Skip to content

Commit

Permalink
[AFS]: Add support for the CB.GetCapabilities operation.
Browse files Browse the repository at this point in the history
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: David Howells <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
dhowells authored and davem330 committed Apr 26, 2007
1 parent 0795e7c commit b908fe6
Show file tree
Hide file tree
Showing 7 changed files with 705 additions and 0 deletions.
1 change: 1 addition & 0 deletions fs/afs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ kafs-objs := \
security.o \
server.o \
super.o \
use-rtnetlink.o \
vlclient.o \
vlocation.o \
vnode.o \
Expand Down
3 changes: 3 additions & 0 deletions fs/afs/afs_cm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ enum AFS_CM_Operations {
CBGetCE = 208, /* get cache file description */
CBGetXStatsVersion = 209, /* get version of extended statistics */
CBGetXStats = 210, /* get contents of extended statistics data */
CBGetCapabilities = 65538, /* get client capabilities */
};

#define AFS_CAP_ERROR_TRANSLATION 0x1

#endif /* AFS_FS_H */
98 changes: 98 additions & 0 deletions fs/afs/cmservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static int afs_deliver_cb_init_call_back_state(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_get_capabilities(struct afs_call *, struct sk_buff *,
bool);
static void afs_cm_destructor(struct afs_call *);

/*
Expand Down Expand Up @@ -54,6 +56,16 @@ static const struct afs_call_type afs_SRXCBProbe = {
.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
* - return T if supported, F if not
Expand All @@ -74,6 +86,9 @@ bool afs_cm_incoming_call(struct afs_call *call)
case CBProbe:
call->type = &afs_SRXCBProbe;
return true;
case CBGetCapabilities:
call->type = &afs_SRXCBGetCapabilites;
return true;
default:
return false;
}
Expand Down Expand Up @@ -328,3 +343,86 @@ static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
schedule_work(&call->work);
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;
}
42 changes: 42 additions & 0 deletions fs/afs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,40 @@ struct afs_permits {
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
Expand Down Expand Up @@ -430,6 +464,7 @@ extern void afs_clear_inode(struct inode *);
/*
* main.c
*/
extern struct afs_uuid afs_uuid;
#ifdef AFS_CACHING_SUPPORT
extern struct cachefs_netfs afs_cache_netfs;
#endif
Expand Down Expand Up @@ -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_transfer_reply(struct afs_call *, struct sk_buff *);
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 *,
size_t);

Expand Down Expand Up @@ -500,6 +536,12 @@ extern void __exit afs_purge_servers(void);
extern int afs_fs_init(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
*/
Expand Down
49 changes: 49 additions & 0 deletions fs/afs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,51 @@ struct cachefs_netfs afs_cache_netfs = {
};
#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
*/
Expand All @@ -49,6 +94,10 @@ static int __init afs_init(void)

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 */
ret = afs_proc_init();
if (ret < 0)
Expand Down
39 changes: 39 additions & 0 deletions fs/afs/rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit b908fe6

Please sign in to comment.