Commit b908fe6b authored by David Howells's avatar David Howells Committed by David S. Miller

[AFS]: Add support for the CB.GetCapabilities operation.

Add support for the CB.GetCapabilities operation with which the fileserver can
ask the client for the following information:

 (1) The list of network interfaces it has available as IPv4 address + netmask
     plus the MTUs.

 (2) The client's UUID.

 (3) The extended capabilities of the client, for which the only current one
     is unified error mapping (abort code interpretation).

To support this, the patch adds the following routines to AFS:

 (1) A function to iterate through all the network interfaces using RTNETLINK
     to extract IPv4 addresses and MTUs.

 (2) A function to iterate through all the network interfaces using RTNETLINK
     to pull out the MAC address of the lowest index interface to use in UUID
     construction.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0795e7c0
...@@ -18,6 +18,7 @@ kafs-objs := \ ...@@ -18,6 +18,7 @@ kafs-objs := \
security.o \ security.o \
server.o \ server.o \
super.o \ super.o \
use-rtnetlink.o \
vlclient.o \ vlclient.o \
vlocation.o \ vlocation.o \
vnode.o \ vnode.o \
......
...@@ -23,6 +23,9 @@ enum AFS_CM_Operations { ...@@ -23,6 +23,9 @@ enum AFS_CM_Operations {
CBGetCE = 208, /* get cache file description */ CBGetCE = 208, /* get cache file description */
CBGetXStatsVersion = 209, /* get version of extended statistics */ CBGetXStatsVersion = 209, /* get version of extended statistics */
CBGetXStats = 210, /* get contents of extended statistics data */ CBGetXStats = 210, /* get contents of extended statistics data */
CBGetCapabilities = 65538, /* get client capabilities */
}; };
#define AFS_CAP_ERROR_TRANSLATION 0x1
#endif /* AFS_FS_H */ #endif /* AFS_FS_H */
...@@ -22,6 +22,8 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *, ...@@ -22,6 +22,8 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *,
struct sk_buff *, bool); struct sk_buff *, bool);
static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool); static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool);
static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool); static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool);
static int afs_deliver_cb_get_capabilities(struct afs_call *, struct sk_buff *,
bool);
static void afs_cm_destructor(struct afs_call *); static void afs_cm_destructor(struct afs_call *);
/* /*
...@@ -54,6 +56,16 @@ static const struct afs_call_type afs_SRXCBProbe = { ...@@ -54,6 +56,16 @@ static const struct afs_call_type afs_SRXCBProbe = {
.destructor = afs_cm_destructor, .destructor = afs_cm_destructor,
}; };
/*
* CB.GetCapabilities operation type
*/
static const struct afs_call_type afs_SRXCBGetCapabilites = {
.name = "CB.GetCapabilities",
.deliver = afs_deliver_cb_get_capabilities,
.abort_to_error = afs_abort_to_error,
.destructor = afs_cm_destructor,
};
/* /*
* route an incoming cache manager call * route an incoming cache manager call
* - return T if supported, F if not * - return T if supported, F if not
...@@ -74,6 +86,9 @@ bool afs_cm_incoming_call(struct afs_call *call) ...@@ -74,6 +86,9 @@ bool afs_cm_incoming_call(struct afs_call *call)
case CBProbe: case CBProbe:
call->type = &afs_SRXCBProbe; call->type = &afs_SRXCBProbe;
return true; return true;
case CBGetCapabilities:
call->type = &afs_SRXCBGetCapabilites;
return true;
default: default:
return false; return false;
} }
...@@ -328,3 +343,86 @@ static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb, ...@@ -328,3 +343,86 @@ static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
schedule_work(&call->work); schedule_work(&call->work);
return 0; return 0;
} }
/*
* allow the fileserver to ask about the cache manager's capabilities
*/
static void SRXAFSCB_GetCapabilities(struct work_struct *work)
{
struct afs_interface *ifs;
struct afs_call *call = container_of(work, struct afs_call, work);
int loop, nifs;
struct {
struct /* InterfaceAddr */ {
__be32 nifs;
__be32 uuid[11];
__be32 ifaddr[32];
__be32 netmask[32];
__be32 mtu[32];
} ia;
struct /* Capabilities */ {
__be32 capcount;
__be32 caps[1];
} cap;
} reply;
_enter("");
nifs = 0;
ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
if (ifs) {
nifs = afs_get_ipv4_interfaces(ifs, 32, false);
if (nifs < 0) {
kfree(ifs);
ifs = NULL;
nifs = 0;
}
}
memset(&reply, 0, sizeof(reply));
reply.ia.nifs = htonl(nifs);
reply.ia.uuid[0] = htonl(afs_uuid.time_low);
reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
for (loop = 0; loop < 6; loop++)
reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
if (ifs) {
for (loop = 0; loop < nifs; loop++) {
reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
}
}
reply.cap.capcount = htonl(1);
reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
afs_send_simple_reply(call, &reply, sizeof(reply));
_leave("");
}
/*
* deliver request data to a CB.GetCapabilities call
*/
static int afs_deliver_cb_get_capabilities(struct afs_call *call,
struct sk_buff *skb, bool last)
{
_enter(",{%u},%d", skb->len, last);
if (skb->len > 0)
return -EBADMSG;
if (!last)
return 0;
/* no unmarshalling required */
call->state = AFS_CALL_REPLYING;
INIT_WORK(&call->work, SRXAFSCB_GetCapabilities);
schedule_work(&call->work);
return 0;
}
...@@ -346,6 +346,40 @@ struct afs_permits { ...@@ -346,6 +346,40 @@ struct afs_permits {
struct afs_permit permits[0]; /* the permits so far examined */ struct afs_permit permits[0]; /* the permits so far examined */
}; };
/*
* record of one of a system's set of network interfaces
*/
struct afs_interface {
unsigned index; /* interface index */
struct in_addr address; /* IPv4 address bound to interface */
struct in_addr netmask; /* netmask applied to address */
unsigned mtu; /* MTU of interface */
};
/*
* UUID definition [internet draft]
* - the timestamp is a 60-bit value, split 32/16/12, and goes in 100ns
* increments since midnight 15th October 1582
* - add AFS_UUID_TO_UNIX_TIME to convert unix time in 100ns units to UUID
* time
* - the clock sequence is a 14-bit counter to avoid duplicate times
*/
struct afs_uuid {
u32 time_low; /* low part of timestamp */
u16 time_mid; /* mid part of timestamp */
u16 time_hi_and_version; /* high part of timestamp and version */
#define AFS_UUID_TO_UNIX_TIME 0x01b21dd213814000
#define AFS_UUID_TIMEHI_MASK 0x0fff
#define AFS_UUID_VERSION_TIME 0x1000 /* time-based UUID */
#define AFS_UUID_VERSION_NAME 0x3000 /* name-based UUID */
#define AFS_UUID_VERSION_RANDOM 0x4000 /* (pseudo-)random generated UUID */
u8 clock_seq_hi_and_reserved; /* clock seq hi and variant */
#define AFS_UUID_CLOCKHI_MASK 0x3f
#define AFS_UUID_VARIANT_STD 0x80
u8 clock_seq_low; /* clock seq low */
u8 node[6]; /* spatially unique node ID (MAC addr) */
};
/*****************************************************************************/ /*****************************************************************************/
/* /*
* callback.c * callback.c
...@@ -430,6 +464,7 @@ extern void afs_clear_inode(struct inode *); ...@@ -430,6 +464,7 @@ extern void afs_clear_inode(struct inode *);
/* /*
* main.c * main.c
*/ */
extern struct afs_uuid afs_uuid;
#ifdef AFS_CACHING_SUPPORT #ifdef AFS_CACHING_SUPPORT
extern struct cachefs_netfs afs_cache_netfs; extern struct cachefs_netfs afs_cache_netfs;
#endif #endif
...@@ -470,6 +505,7 @@ extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *, ...@@ -470,6 +505,7 @@ extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *,
extern void afs_flat_call_destructor(struct afs_call *); extern void afs_flat_call_destructor(struct afs_call *);
extern void afs_transfer_reply(struct afs_call *, struct sk_buff *); extern void afs_transfer_reply(struct afs_call *, struct sk_buff *);
extern void afs_send_empty_reply(struct afs_call *); extern void afs_send_empty_reply(struct afs_call *);
extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *, extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *,
size_t); size_t);
...@@ -500,6 +536,12 @@ extern void __exit afs_purge_servers(void); ...@@ -500,6 +536,12 @@ extern void __exit afs_purge_servers(void);
extern int afs_fs_init(void); extern int afs_fs_init(void);
extern void afs_fs_exit(void); extern void afs_fs_exit(void);
/*
* use-rtnetlink.c
*/
extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
extern int afs_get_MAC_address(u8 [6]);
/* /*
* vlclient.c * vlclient.c
*/ */
......
...@@ -40,6 +40,51 @@ struct cachefs_netfs afs_cache_netfs = { ...@@ -40,6 +40,51 @@ struct cachefs_netfs afs_cache_netfs = {
}; };
#endif #endif
struct afs_uuid afs_uuid;
/*
* get a client UUID
*/
static int __init afs_get_client_UUID(void)
{
struct timespec ts;
u64 uuidtime;
u16 clockseq;
int ret;
/* read the MAC address of one of the external interfaces and construct
* a UUID from it */
ret = afs_get_MAC_address(afs_uuid.node);
if (ret < 0)
return ret;
getnstimeofday(&ts);
uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
uuidtime += ts.tv_nsec / 100;
uuidtime += AFS_UUID_TO_UNIX_TIME;
afs_uuid.time_low = uuidtime;
afs_uuid.time_mid = uuidtime >> 32;
afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
afs_uuid.time_hi_and_version = AFS_UUID_VERSION_TIME;
get_random_bytes(&clockseq, 2);
afs_uuid.clock_seq_low = clockseq;
afs_uuid.clock_seq_hi_and_reserved =
(clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
afs_uuid.clock_seq_hi_and_reserved = AFS_UUID_VARIANT_STD;
_debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
afs_uuid.time_low,
afs_uuid.time_mid,
afs_uuid.time_hi_and_version,
afs_uuid.clock_seq_hi_and_reserved,
afs_uuid.clock_seq_low,
afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
return 0;
}
/* /*
* initialise the AFS client FS module * initialise the AFS client FS module
*/ */
...@@ -49,6 +94,10 @@ static int __init afs_init(void) ...@@ -49,6 +94,10 @@ static int __init afs_init(void)
printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
ret = afs_get_client_UUID();
if (ret < 0)
return ret;
/* register the /proc stuff */ /* register the /proc stuff */
ret = afs_proc_init(); ret = afs_proc_init();
if (ret < 0) if (ret < 0)
......
...@@ -713,6 +713,45 @@ void afs_send_empty_reply(struct afs_call *call) ...@@ -713,6 +713,45 @@ void afs_send_empty_reply(struct afs_call *call)
} }
} }
/*
* send a simple reply
*/
void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
{
struct msghdr msg;
struct iovec iov[1];
_enter("");
iov[0].iov_base = (void *) buf;
iov[0].iov_len = len;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
call->state = AFS_CALL_AWAIT_ACK;
switch (rxrpc_kernel_send_data(call->rxcall, &msg, len)) {
case 0:
_leave(" [replied]");
return;
case -ENOMEM:
_debug("oom");
rxrpc_kernel_abort_call(call->rxcall, RX_USER_ABORT);
default:
rxrpc_kernel_end_call(call->rxcall);
call->rxcall = NULL;
call->type->destructor(call);
afs_free_call(call);
_leave(" [error]");
return;
}
}
/* /*
* extract a piece of data from the received data socket buffers * extract a piece of data from the received data socket buffers
*/ */
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment