OSDN Git Service

afs: Overhaul volume and server record caching and fileserver rotation
[tomoyo/tomoyo-test1.git] / fs / afs / vlclient.c
index 1d1e7df..173c652 100644 (file)
 #include "internal.h"
 
 /*
- * deliver reply data to a VL.GetEntryByXXX call
+ * Deliver reply data to a VL.GetEntryByNameU call.
  */
-static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call)
+static int afs_deliver_vl_get_entry_by_name_u(struct afs_call *call)
 {
-       struct afs_cache_vlocation *entry;
-       __be32 *bp;
+       struct afs_uvldbentry__xdr *uvldb;
+       struct afs_vldb_entry *entry;
+       bool new_only = false;
        u32 tmp;
-       int loop, ret;
+       int i, ret;
 
        _enter("");
 
@@ -32,152 +33,270 @@ static int afs_deliver_vl_get_entry_by_xxx(struct afs_call *call)
                return ret;
 
        /* unmarshall the reply once we've received all of it */
+       uvldb = call->buffer;
        entry = call->reply[0];
-       bp = call->buffer;
-
-       for (loop = 0; loop < 64; loop++)
-               entry->name[loop] = ntohl(*bp++);
-       entry->name[loop] = 0;
-       bp++; /* final NUL */
-
-       bp++; /* type */
-       entry->nservers = ntohl(*bp++);
-
-       for (loop = 0; loop < 8; loop++) {
-               entry->servers[loop].srx_family = AF_RXRPC;
-               entry->servers[loop].srx_service = FS_SERVICE;
-               entry->servers[loop].transport_type = SOCK_DGRAM;
-               entry->servers[loop].transport_len = sizeof(entry->servers[loop].transport.sin6);
-               entry->servers[loop].transport.sin6.sin6_family = AF_INET6;
-               entry->servers[loop].transport.sin6.sin6_port = htons(AFS_FS_PORT);
-               entry->servers[loop].transport.sin6.sin6_flowinfo = 0;
-               entry->servers[loop].transport.sin6.sin6_scope_id = 0;
-               entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[0] = 0;
-               entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[1] = 0;
-               entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[2] = htonl(0xffff);
-               entry->servers[loop].transport.sin6.sin6_addr.s6_addr32[3] = *bp++;
+
+       for (i = 0; i < ARRAY_SIZE(uvldb->name) - 1; i++)
+               entry->name[i] = (u8)ntohl(uvldb->name[i]);
+       entry->name[i] = 0;
+       entry->name_len = strlen(entry->name);
+
+       /* If there is a new replication site that we can use, ignore all the
+        * sites that aren't marked as new.
+        */
+       for (i = 0; i < AFS_NMAXNSERVERS; i++) {
+               tmp = ntohl(uvldb->serverFlags[i]);
+               if (!(tmp & AFS_VLSF_DONTUSE) &&
+                   (tmp & AFS_VLSF_NEWREPSITE))
+                       new_only = true;
        }
 
-       bp += 8; /* partition IDs */
+       for (i = 0; i < AFS_NMAXNSERVERS; i++) {
+               struct afs_uuid__xdr *xdr;
+               struct afs_uuid *uuid;
+               int j;
 
-       for (loop = 0; loop < 8; loop++) {
-               tmp = ntohl(*bp++);
-               entry->srvtmask[loop] = 0;
+               tmp = ntohl(uvldb->serverFlags[i]);
+               if (tmp & AFS_VLSF_DONTUSE ||
+                   (new_only && !(tmp & AFS_VLSF_NEWREPSITE)))
+                       continue;
                if (tmp & AFS_VLSF_RWVOL)
-                       entry->srvtmask[loop] |= AFS_VOL_VTM_RW;
+                       entry->fs_mask[i] |= AFS_VOL_VTM_RW;
                if (tmp & AFS_VLSF_ROVOL)
-                       entry->srvtmask[loop] |= AFS_VOL_VTM_RO;
+                       entry->fs_mask[i] |= AFS_VOL_VTM_RO;
                if (tmp & AFS_VLSF_BACKVOL)
-                       entry->srvtmask[loop] |= AFS_VOL_VTM_BAK;
-       }
+                       entry->fs_mask[i] |= AFS_VOL_VTM_BAK;
+               if (!entry->fs_mask[i])
+                       continue;
+
+               xdr = &uvldb->serverNumber[i];
+               uuid = (struct afs_uuid *)&entry->fs_server[i];
+               uuid->time_low                  = xdr->time_low;
+               uuid->time_mid                  = htons(ntohl(xdr->time_mid));
+               uuid->time_hi_and_version       = htons(ntohl(xdr->time_hi_and_version));
+               uuid->clock_seq_hi_and_reserved = (u8)ntohl(xdr->clock_seq_hi_and_reserved);
+               uuid->clock_seq_low             = (u8)ntohl(xdr->clock_seq_low);
+               for (j = 0; j < 6; j++)
+                       uuid->node[j] = (u8)ntohl(xdr->node[j]);
 
-       entry->vid[0] = ntohl(*bp++);
-       entry->vid[1] = ntohl(*bp++);
-       entry->vid[2] = ntohl(*bp++);
+               entry->nr_servers++;
+       }
 
-       bp++; /* clone ID */
+       for (i = 0; i < AFS_MAXTYPES; i++)
+               entry->vid[i] = ntohl(uvldb->volumeId[i]);
 
-       tmp = ntohl(*bp++); /* flags */
-       entry->vidmask = 0;
+       tmp = ntohl(uvldb->flags);
        if (tmp & AFS_VLF_RWEXISTS)
-               entry->vidmask |= AFS_VOL_VTM_RW;
+               __set_bit(AFS_VLDB_HAS_RW, &entry->flags);
        if (tmp & AFS_VLF_ROEXISTS)
-               entry->vidmask |= AFS_VOL_VTM_RO;
+               __set_bit(AFS_VLDB_HAS_RO, &entry->flags);
        if (tmp & AFS_VLF_BACKEXISTS)
-               entry->vidmask |= AFS_VOL_VTM_BAK;
-       if (!entry->vidmask)
-               return -EBADMSG;
+               __set_bit(AFS_VLDB_HAS_BAK, &entry->flags);
 
+       if (!(tmp & (AFS_VLF_RWEXISTS | AFS_VLF_ROEXISTS | AFS_VLF_BACKEXISTS))) {
+               entry->error = -ENOMEDIUM;
+               __set_bit(AFS_VLDB_QUERY_ERROR, &entry->flags);
+       }
+
+       __set_bit(AFS_VLDB_QUERY_VALID, &entry->flags);
        _leave(" = 0 [done]");
        return 0;
 }
 
-/*
- * VL.GetEntryByName operation type
- */
-static const struct afs_call_type afs_RXVLGetEntryByName = {
-       .name           = "VL.GetEntryByName",
-       .deliver        = afs_deliver_vl_get_entry_by_xxx,
-       .destructor     = afs_flat_call_destructor,
-};
+static void afs_destroy_vl_get_entry_by_name_u(struct afs_call *call)
+{
+       kfree(call->reply[0]);
+       afs_flat_call_destructor(call);
+}
 
 /*
- * VL.GetEntryById operation type
+ * VL.GetEntryByNameU operation type.
  */
-static const struct afs_call_type afs_RXVLGetEntryById = {
-       .name           = "VL.GetEntryById",
-       .deliver        = afs_deliver_vl_get_entry_by_xxx,
-       .destructor     = afs_flat_call_destructor,
+static const struct afs_call_type afs_RXVLGetEntryByNameU = {
+       .name           = "VL.GetEntryByNameU",
+       .deliver        = afs_deliver_vl_get_entry_by_name_u,
+       .destructor     = afs_destroy_vl_get_entry_by_name_u,
 };
 
 /*
- * dispatch a get volume entry by name operation
+ * Dispatch a get volume entry by name or ID operation (uuid variant).  If the
+ * volname is a decimal number then it's a volume ID not a volume name.
  */
-int afs_vl_get_entry_by_name(struct afs_net *net,
-                            struct afs_addr_cursor *ac,
-                            struct key *key,
-                            const char *volname,
-                            struct afs_cache_vlocation *entry,
-                            bool async)
+struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *net,
+                                                 struct afs_addr_cursor *ac,
+                                                 struct key *key,
+                                                 const char *volname,
+                                                 int volnamesz)
 {
+       struct afs_vldb_entry *entry;
        struct afs_call *call;
-       size_t volnamesz, reqsz, padsz;
+       size_t reqsz, padsz;
        __be32 *bp;
 
        _enter("");
 
-       volnamesz = strlen(volname);
        padsz = (4 - (volnamesz & 3)) & 3;
        reqsz = 8 + volnamesz + padsz;
 
-       call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByName, reqsz, 384);
-       if (!call)
-               return -ENOMEM;
+       entry = kzalloc(sizeof(struct afs_vldb_entry), GFP_KERNEL);
+       if (!entry)
+               return ERR_PTR(-ENOMEM);
+
+       call = afs_alloc_flat_call(net, &afs_RXVLGetEntryByNameU, reqsz,
+                                  sizeof(struct afs_uvldbentry__xdr));
+       if (!call) {
+               kfree(entry);
+               return ERR_PTR(-ENOMEM);
+       }
 
        call->key = key;
        call->reply[0] = entry;
+       call->ret_reply0 = true;
 
-       /* marshall the parameters */
+       /* Marshall the parameters */
        bp = call->request;
-       *bp++ = htonl(VLGETENTRYBYNAME);
+       *bp++ = htonl(VLGETENTRYBYNAMEU);
        *bp++ = htonl(volnamesz);
        memcpy(bp, volname, volnamesz);
        if (padsz > 0)
-               memset((void *) bp + volnamesz, 0, padsz);
+               memset((void *)bp + volnamesz, 0, padsz);
 
-       /* initiate the call */
-       return afs_make_call(ac, call, GFP_KERNEL, async);
+       return (struct afs_vldb_entry *)afs_make_call(ac, call, GFP_KERNEL, false);
 }
 
 /*
- * dispatch a get volume entry by ID operation
+ * Deliver reply data to a VL.GetAddrsU call.
+ *
+ *     GetAddrsU(IN ListAddrByAttributes *inaddr,
+ *               OUT afsUUID *uuidp1,
+ *               OUT uint32_t *uniquifier,
+ *               OUT uint32_t *nentries,
+ *               OUT bulkaddrs *blkaddrs);
  */
-int afs_vl_get_entry_by_id(struct afs_net *net,
-                          struct afs_addr_cursor *ac,
-                          struct key *key,
-                          afs_volid_t volid,
-                          afs_voltype_t voltype,
-                          struct afs_cache_vlocation *entry,
-                          bool async)
+static int afs_deliver_vl_get_addrs_u(struct afs_call *call)
 {
+       struct afs_addr_list *alist;
+       __be32 *bp;
+       u32 uniquifier, nentries, count;
+       int i, ret;
+
+       _enter("{%u,%zu/%u}", call->unmarshall, call->offset, call->count);
+
+again:
+       switch (call->unmarshall) {
+       case 0:
+               call->offset = 0;
+               call->unmarshall++;
+
+               /* Extract the returned uuid, uniquifier, nentries and blkaddrs size */
+       case 1:
+               ret = afs_extract_data(call, call->buffer,
+                                      sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32),
+                                      true);
+               if (ret < 0)
+                       return ret;
+
+               bp = call->buffer + sizeof(struct afs_uuid__xdr);
+               uniquifier      = ntohl(*bp++);
+               nentries        = ntohl(*bp++);
+               count           = ntohl(*bp);
+
+               nentries = min(nentries, count);
+               alist = afs_alloc_addrlist(nentries, FS_SERVICE, AFS_FS_PORT);
+               if (!alist)
+                       return -ENOMEM;
+               alist->version = uniquifier;
+               call->reply[0] = alist;
+               call->count = count;
+               call->count2 = nentries;
+               call->offset = 0;
+               call->unmarshall++;
+
+               /* Extract entries */
+       case 2:
+               count = min(call->count, 4U);
+               ret = afs_extract_data(call, call->buffer,
+                                      count * sizeof(__be32),
+                                      call->count > 4);
+               if (ret < 0)
+                       return ret;
+
+               alist = call->reply[0];
+               bp = call->buffer;
+               for (i = 0; i < count; i++)
+                       if (alist->nr_addrs < call->count2)
+                               afs_merge_fs_addr4(alist, *bp++);
+
+               call->count -= count;
+               if (call->count > 0)
+                       goto again;
+               call->offset = 0;
+               call->unmarshall++;
+               break;
+       }
+
+       _leave(" = 0 [done]");
+       return 0;
+}
+
+static void afs_vl_get_addrs_u_destructor(struct afs_call *call)
+{
+       afs_put_server(call->net, (struct afs_server *)call->reply[0]);
+       kfree(call->reply[1]);
+       return afs_flat_call_destructor(call);
+}
+
+/*
+ * VL.GetAddrsU operation type.
+ */
+static const struct afs_call_type afs_RXVLGetAddrsU = {
+       .name           = "VL.GetAddrsU",
+       .deliver        = afs_deliver_vl_get_addrs_u,
+       .destructor     = afs_vl_get_addrs_u_destructor,
+};
+
+/*
+ * Dispatch an operation to get the addresses for a server, where the server is
+ * nominated by UUID.
+ */
+struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *net,
+                                        struct afs_addr_cursor *ac,
+                                        struct key *key,
+                                        const uuid_t *uuid)
+{
+       struct afs_ListAddrByAttributes__xdr *r;
+       const struct afs_uuid *u = (const struct afs_uuid *)uuid;
        struct afs_call *call;
        __be32 *bp;
+       int i;
 
        _enter("");
 
-       call = afs_alloc_flat_call(net, &afs_RXVLGetEntryById, 12, 384);
+       call = afs_alloc_flat_call(net, &afs_RXVLGetAddrsU,
+                                  sizeof(__be32) + sizeof(struct afs_ListAddrByAttributes__xdr),
+                                  sizeof(struct afs_uuid__xdr) + 3 * sizeof(__be32));
        if (!call)
-               return -ENOMEM;
+               return ERR_PTR(-ENOMEM);
 
        call->key = key;
-       call->reply[0] = entry;
+       call->reply[0] = NULL;
+       call->ret_reply0 = true;
 
-       /* marshall the parameters */
+       /* Marshall the parameters */
        bp = call->request;
-       *bp++ = htonl(VLGETENTRYBYID);
-       *bp++ = htonl(volid);
-       *bp   = htonl(voltype);
+       *bp++ = htonl(VLGETADDRSU);
+       r = (struct afs_ListAddrByAttributes__xdr *)bp;
+       r->Mask         = htonl(AFS_VLADDR_UUID);
+       r->ipaddr       = 0;
+       r->index        = 0;
+       r->spare        = 0;
+       r->uuid.time_low                        = u->time_low;
+       r->uuid.time_mid                        = htonl(ntohs(u->time_mid));
+       r->uuid.time_hi_and_version             = htonl(ntohs(u->time_hi_and_version));
+       r->uuid.clock_seq_hi_and_reserved       = htonl(u->clock_seq_hi_and_reserved);
+       r->uuid.clock_seq_low                   = htonl(u->clock_seq_low);
+       for (i = 0; i < 6; i++)
+               r->uuid.node[i] = ntohl(u->node[i]);
 
-       /* initiate the call */
-       return afs_make_call(ac, call, GFP_KERNEL, async);
+       return (struct afs_addr_list *)afs_make_call(ac, call, GFP_KERNEL, false);
 }