if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
END(VL_PERM);
- if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT)
+ if (Maxvolidbump > MAXBUMPCOUNT)
END(VL_BADVOLIDBUMP);
if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
return code;
allocCount = VLDBALLOCCOUNT;
Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
- (vldbentry *) malloc(allocCount * sizeof(vldbentry));
+ malloc(allocCount * sizeof(vldbentry));
if (Vldbentry == NULL) {
code = VL_NOMEM;
goto abort;
&& (allocCount > vldbentries->bulkentries_len)) {
vldbentries->bulkentries_val =
- (vldbentry *) realloc(vldbentries->bulkentries_val,
- vldbentries->bulkentries_len *
- sizeof(vldbentry));
+ realloc(vldbentries->bulkentries_val,
+ vldbentries->bulkentries_len * sizeof(vldbentry));
if (vldbentries->bulkentries_val == NULL) {
code = VL_NOMEM;
goto abort;
return code;
allocCount = VLDBALLOCCOUNT;
Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
- (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
+ malloc(allocCount * sizeof(nvldbentry));
if (Vldbentry == NULL) {
code = VL_NOMEM;
goto abort;
&& (allocCount > vldbentries->nbulkentries_len)) {
vldbentries->nbulkentries_val =
- (nvldbentry *) realloc(vldbentries->nbulkentries_val,
- vldbentries->nbulkentries_len *
- sizeof(nvldbentry));
+ realloc(vldbentries->nbulkentries_val,
+ vldbentries->nbulkentries_len * sizeof(nvldbentry));
if (vldbentries->nbulkentries_val == NULL) {
code = VL_NOMEM;
goto abort;
return code;
Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
- (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
+ malloc(maxCount * sizeof(nvldbentry));
if (Vldbentry == NULL) {
countAbort(this_op);
ubik_AbortTrans(ctx.trans);
countAbort(this_op);
ubik_AbortTrans(ctx.trans);
if (vldbentries->nbulkentries_val)
- free((char *)vldbentries->nbulkentries_val);
+ free(vldbentries->nbulkentries_val);
vldbentries->nbulkentries_val = 0;
vldbentries->nbulkentries_len = 0;
*nextstartindex = -1;
goto abort;
}
- vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
+ vllist = malloc(sizeof(single_vldbentry));
if (vllist == NULL) {
code = VL_NOMEM;
goto abort;
continue;
}
- vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
+ vllist = malloc(sizeof(single_vldbentry));
if (vllist == NULL) {
code = VL_NOMEM;
goto abort;
goto abort;
}
- vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
+ vllist = malloc(sizeof(single_nvldbentry));
if (vllist == NULL) {
code = VL_NOMEM;
goto abort;
continue;
}
- vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
+ vllist = malloc(sizeof(single_nvldbentry));
if (vllist == NULL) {
code = VL_NOMEM;
goto abort;
VLog(5, ("GetAddrs\n"));
addrsp->bulkaddrs_val = taddrp =
- (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
+ malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
nservers = *nentries = addrsp->bulkaddrs_len = 0;
if (!taddrp) {
return code;
}
-#define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
+static_inline void
+append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
+{
+ int n = strlen(buffer);
+ if (buffer_size > n) {
+ snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
+ (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
+ addr & 0xff);
+ }
+}
afs_int32
SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
struct vl_ctx ctx;
int cnt, h, i, j, k, m;
struct extentaddr *exp = 0, *tex;
+ char addrbuf[256];
afsUUID tuuid;
afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
int base;
|| (!foundUuidEntry && (count > 1))) {
VLog(0,
("The following fileserver is being registered in the VLDB:\n"));
- VLog(0, (" ["));
- for (k = 0; k < cnt; k++) {
+ for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
if (k > 0)
- VLog(0,(" "));
- PADDR(addrs[k]);
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, addrs[k], sizeof(addrbuf));
}
- VLog(0,("]\n"));
+ VLog(0, (" [%s]\n", addrbuf));
if (foundUuidEntry) {
code = multiHomedExtent(&ctx, FoundUuid, &exp);
if (code == 0) {
VLog(0, (" It would have replaced the existing VLDB server "
"entry:\n"));
- VLog(0, (" entry %d: [", FoundUuid));
- for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
+ for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
if (!exp->ex_addrs[mhidx])
continue;
if (mhidx > 0)
- VLog(0,(" "));
- PADDR(ntohl(exp->ex_addrs[mhidx]));
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
}
- VLog(0, ("]\n"));
+ VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
}
}
if (code)
goto abort;
+ addrbuf[0] = '\0';
if (exp) {
- VLog(0, ("["));
for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
if (!exp->ex_addrs[mhidx])
continue;
if (mhidx > 0)
- VLog(0, (" "));
- PADDR(ntohl(exp->ex_addrs[mhidx]));
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
}
- VLog(0, ("]"));
} else {
- PADDR(ctx.hostaddress[srvidx]);
+ append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
}
- VLog(0, ("\n"));
+ VLog(0, (" entry %d: [%s]\n", srvidx, addrbuf));
}
if (count == 1)
}
VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
- VLog(0, (" ["));
- for (k = 0; k < cnt; k++) {
+ for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
if (k > 0)
- VLog(0, (" "));
- PADDR(addrs[k]);
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, addrs[k], sizeof(addrbuf));
}
- VLog(0, ("]\n"));
+ VLog(0, (" [%s]\n", addrbuf));
if (foundUuidEntry) {
VLog(0,
(" It will replace the following existing entry in the VLDB (same uuid):\n"));
- VLog(0, (" entry %d: [", FoundUuid));
- for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
+ for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
if (exp->ex_addrs[k] == 0)
continue;
if (k > 0)
- VLog(0, (" "));
- PADDR(ntohl(exp->ex_addrs[k]));
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
}
- VLog(0, ("]\n"));
+ VLog(0, (" entry %d: [%s]\n", FoundUuid, addrbuf));
} else if (willReplaceCnt || (count == 1)) {
/* If we are not replacing an entry and there is only one entry to change,
* then we will replace that entry.
if (exp) {
VLog(0,
(" It will replace the following existing entry in the VLDB (new uuid):\n"));
- VLog(0, (" entry %d: [", ReplaceEntry));
- for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
+ for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
if (exp->ex_addrs[k] == 0)
continue;
if (k > 0)
- VLog(0, (" "));
- PADDR(ntohl(exp->ex_addrs[k]));
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
}
- VLog(0, ("]\n"));
+ VLog(0, (" entry %d: [%s]\n", ReplaceEntry, addrbuf));
} else {
/* Not a mh entry. So we have to create a new mh entry and
* put it on the ReplaceEntry slot of the ctx.hostaddress array.
*/
- VLog(0, (" It will replace existing entry %d, ", ReplaceEntry));
- PADDR(ctx.hostaddress[ReplaceEntry]);
- VLog(0,(", in the VLDB (new uuid):\n"));
-
+ addrbuf[0] = '\0';
+ append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
+ VLog(0, (" It will replace existing entry %d, %s,"
+ " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
code =
FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
if (code || !exp) {
VLog(0,
(" The following existing entries in the VLDB will be updated:\n"));
- VLog(0, (" entry %d: [", WillChange[i]));
- for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
+ for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
if (tex->ex_addrs[j]) {
if (j > 0)
- printf(" ");
- PADDR(ntohl(tex->ex_addrs[j]));
+ strlcat(addrbuf, " ", sizeof(addrbuf));
+ append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
}
for (k = 0; k < cnt; k++) {
for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
tex->ex_addrs[j] = 0; /* zero rest of mh entry */
}
- VLog(0, ("]\n"));
+ VLog(0, (" entry %d: [%s]\n", WillChange[i], addrbuf));
/* Write out the modified mh entry */
tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
bulkaddrs *addrsp)
{
int this_op = VLGETADDRSU;
- afs_int32 code, index = -1, offset;
+ afs_int32 code, index;
struct vl_ctx ctx;
int nservers, i, j, base = 0;
struct extentaddr *exp = 0;
code = VL_BADMASK;
goto abort;
}
- for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
- if (!ctx.ex_addr[base])
- break;
- for (i = 1; i < VL_MHSRV_PERBLK; i++) {
- exp = &ctx.ex_addr[base][i];
- tuuid = exp->ex_hostuuid;
- afs_ntohuuid(&tuuid);
- if (afs_uuid_is_nil(&tuuid))
- continue;
+ /* Search for a server registered with the VLDB with this ip address. */
+ for (index = 0; index <= MAXSERVERID; index++) {
+ code = multiHomedExtent(&ctx, index, &exp);
+ if (code)
+ continue;
+
+ if (exp) {
for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
if (exp->ex_addrs[j]
&& (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
if (j < VL_MAXIPADDRS_PERMH)
break;
}
- if (i < VL_MHSRV_PERBLK)
- break;
}
- if (base >= VL_MAX_ADDREXTBLKS) {
+ if (index > MAXSERVERID) {
code = VL_NOENT;
goto abort;
}
code = VL_BADMASK;
goto abort;
}
- index = attributes->index;
- if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
+ /* VLADDR_INDEX index is one based */
+ if (attributes->index < 1 || attributes->index > MAXSERVERID) {
code = VL_INDEXERANGE;
goto abort;
}
- base = index / VL_MHSRV_PERBLK;
- offset = index % VL_MHSRV_PERBLK;
- if (offset == 0) {
+ index = attributes->index - 1;
+ code = multiHomedExtent(&ctx, index, &exp);
+ if (code) {
code = VL_NOENT;
goto abort;
}
- if (!ctx.ex_addr[base]) {
- code = VL_INDEXERANGE;
- goto abort;
- }
- exp = &ctx.ex_addr[base][offset];
} else if (attributes->Mask & VLADDR_UUID) {
if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
code = VL_BADMASK;
goto abort;
}
addrsp->bulkaddrs_val = taddrp =
- (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
+ malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
nservers = *nentries = addrsp->bulkaddrs_len = 0;
if (!taddrp) {
code = VL_NOMEM;
* then grow in increments of VLDBALLOCINCR.
*/
allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
- reall =
- (vldbentry *) realloc(*VldbentryFirst,
- (*alloccnt + allo) * sizeof(vldbentry));
+ reall = realloc(*VldbentryFirst,
+ (*alloccnt + allo) * sizeof(vldbentry));
if (reall == NULL)
return VL_NOMEM;
* then grow in increments of VLDBALLOCINCR.
*/
allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
- reall =
- (nvldbentry *) realloc(*VldbentryFirst,
- (*alloccnt + allo) * sizeof(nvldbentry));
+ reall = realloc(*VldbentryFirst,
+ (*alloccnt + allo) * sizeof(nvldbentry));
if (reall == NULL)
return VL_NOMEM;
tuuid = exp->ex_hostuuid;
afs_ntohuuid(&tuuid);
- VldbEntry->serverFlags[i] |= VLSERVER_FLAG_UUID;
+ VldbEntry->serverFlags[i] |= VLSF_UUID;
VldbEntry->serverNumber[i] = tuuid;
VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
} else {
int pollcount = 0;
struct nvlentry tentry;
int ipaddr1_id = -1, ipaddr2_id = -1;
+ char addrbuf1[256];
+ char addrbuf2[256];
/* Don't let addr change to 256.*.*.* : Causes internal error below */
if ((ipaddr2 & 0xff000000) == 0xff000000)
VLog(0,
("The following IP address is being %s:\n",
(ipaddr2 ? "changed" : "removed")));
- VLog(0, (" entry %d: ", i));
+ addrbuf1[0] = addrbuf2[0] = '\0';
if (exp) {
- VLog(0, ("["));
for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
if (!exp->ex_addrs[mhidx])
continue;
if (mhidx > 0)
- VLog(0, (" "));
- PADDR(ntohl(exp->ex_addrs[mhidx]));
+ strlcat(addrbuf1, " ", sizeof(addrbuf1));
+ append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
}
- VLog(0, ("]"));
} else {
- PADDR(ipaddr1);
+ append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
}
if (ipaddr2) {
- VLog(0, (" -> "));
- PADDR(ipaddr2);
+ append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
}
- VLog(0, ("\n"));
+ VLog(0, (" entry %d: [%s] -> [%s]\n", i, addrbuf1, addrbuf2));
/* Change the registered uuuid addresses */
if (exp) {