#include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
#include <setjmp.h>
-#include <volser_prototypes.h>
+#include "volser_prototypes.h"
struct ubik_client *cstruct;
int verbose = 0;
{ if (verbose) { fprintf(STDOUT, (es), (p1), (p2), (p3)); fflush(STDOUT); } }
#define VDONE \
{ if (verbose) { fprintf(STDOUT, " done\n"); fflush(STDOUT); } }
+#define VEPRINT(es) \
+ { if (verbose) { fprintf(STDERR, (es)); fflush(STDERR); } }
+#define VEPRINT1(es, p) \
+ { if (verbose) { fprintf(STDERR, (es), (p)); fflush(STDERR); } }
+#define VEPRINT2(es, p1, p2) \
+ { if (verbose) { fprintf(STDERR, (es), (p1), (p2)); fflush(STDERR); } }
+#define VEPRINT3(es, p1, p2, p3) \
+ { if (verbose) { fprintf(STDERR, (es), (p1), (p2), (p3)); fflush(STDERR); } }
+#define VEDONE \
+ { if (verbose) { fprintf(STDERR, " done\n"); fflush(STDERR); } }
/* like df. Return usage of <pname> on <server> in <partition> */
int
-UV_PartitionInfo(afs_int32 server, char *pname,
- struct diskPartition *partition)
+UV_PartitionInfo64(afs_int32 server, char *pname,
+ struct diskPartition64 *partition)
{
register struct rx_connection *aconn;
- afs_int32 code;
+ afs_int32 code = 0;
- code = 0;
aconn = (struct rx_connection *)0;
aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
- code = AFSVolPartitionInfo(aconn, pname, partition);
+ code = AFSVolPartitionInfo64(aconn, pname, partition);
+ if (code == RXGEN_OPCODE) {
+ struct diskPartition *dpp =
+ (struct diskPartition *)malloc(sizeof(struct diskPartition));
+ code = AFSVolPartitionInfo(aconn, pname, dpp);
+ if (!code) {
+ strncpy(partition->name, dpp->name, 32);
+ strncpy(partition->devName, dpp->devName, 32);
+ partition->lock_fd = dpp->lock_fd;
+ partition->free = dpp->free;
+ partition->minFree = dpp->minFree;
+ }
+ free(dpp);
+ }
if (code) {
fprintf(STDERR, "Could not get information on partition %s\n", pname);
PrintError("", code);
code = AFSVolSetInfo(aconn, tid, &tstatus);
if (code)
- EPRINT(code, "Could not change quota (error %d), continuing...\n");
+ EPRINT(code, "Could not change quota, continuing...\n");
code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */
EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
(void)signal(SIGINT, dump_sig_handler);
if (!fromdate) {
- VPRINT("Full Dump ...\n");
+ VEPRINT("Full Dump ...\n");
} else {
- VPRINT1("Incremental Dump (as of %.24s)...\n",
+ VEPRINT1("Incremental Dump (as of %.24s)...\n",
ctime(&tmv));
}
/* get connections to the servers */
fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
- VPRINT1("Starting transaction on volume %u...", afromvol);
+ VEPRINT1("Starting transaction on volume %u...", afromvol);
code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
EGOTO1(error_exit, code,
"Could not start transaction on the volume %u to be dumped\n",
afromvol);
- VDONE;
+ VEDONE;
fromcall = rx_NewCall(fromconn);
- VPRINT1("Starting volume dump on volume %u...", afromvol);
+ VEPRINT1("Starting volume dump on volume %u...", afromvol);
if (flags & VOLDUMPV2_OMITDIRS)
code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
else
retryold:
code = StartAFSVolDump(fromcall, fromtid, fromdate);
EGOTO(error_exit, code, "Could not start the dump process \n");
- VDONE;
+ VEDONE;
- VPRINT1("Dumping volume %u...", afromvol);
+ VEPRINT1("Dumping volume %u...", afromvol);
code = DumpFunction(fromcall, rock);
if (code == RXGEN_OPCODE)
goto error_exit;
EGOTO(error_exit, code, "Error while dumping volume \n");
- VDONE;
+ VEDONE;
error_exit:
if (fromcall) {
error = code;
}
if (fromtid) {
- VPRINT1("Ending transaction on volume %u...", afromvol);
+ VEPRINT1("Ending transaction on volume %u...", afromvol);
code = AFSVolEndTrans(fromconn, fromtid, &rcode);
if (code || rcode) {
fprintf(STDERR, "Could not end transaction on the volume %lu\n",
if (!error)
error = (code ? code : rcode);
}
- VDONE;
+ VEDONE;
}
if (fromconn)
rx_DestroyConnection(fromconn);
(void)signal(SIGINT, dump_sig_handler);
if (!fromdate) {
- VPRINT("Full Dump ...\n");
+ VEPRINT("Full Dump ...\n");
} else {
- VPRINT1("Incremental Dump (as of %.24s)...\n",
+ VEPRINT1("Incremental Dump (as of %.24s)...\n",
ctime(&tmv));
}
/* get connections to the servers */
fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
- VPRINT1("Starting transaction on volume %u...", afromvol);
+ VEPRINT1("Starting transaction on volume %u...", afromvol);
code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
EGOTO1(error_exit, code,
"Could not start transaction on the volume %u to be dumped\n",
afromvol);
- VDONE;
+ VEDONE;
/* Get a clone id */
- VPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
+ VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
EGOTO1(error_exit, code,
"Could not get an ID for the clone of volume %u from the VLDB\n",
afromvol);
- VDONE;
+ VEDONE;
/* Do the clone. Default flags on clone are set to delete on salvage and out of service */
- VPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
+ VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
clonevol);
strcpy(vname, "dump-clone-temp");
code =
AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
afromvol);
- VDONE;
+ VEDONE;
- VPRINT1("Ending the transaction on the volume %u ...", afromvol);
+ VEPRINT1("Ending the transaction on the volume %u ...", afromvol);
rcode = 0;
code = AFSVolEndTrans(fromconn, fromtid, &rcode);
fromtid = 0;
code = rcode;
EGOTO1(error_exit, code,
"Failed to end the transaction on the volume %u\n", afromvol);
- VDONE;
+ VEDONE;
- VPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
+ VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
code =
AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
&clonetid);
EGOTO1(error_exit, code,
"Failed to start a transaction on the cloned volume%u\n",
clonevol);
- VDONE;
+ VEDONE;
- VPRINT1("Setting flags on cloned volume %u ...", clonevol);
+ VEPRINT1("Setting flags on cloned volume %u ...", clonevol);
code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage | VTOutOfService); /*redundant */
EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",
clonevol);
- VDONE;
+ VEDONE;
fromcall = rx_NewCall(fromconn);
- VPRINT1("Starting volume dump from cloned volume %u...", clonevol);
+ VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
if (flags & VOLDUMPV2_OMITDIRS)
code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
else
code = StartAFSVolDump(fromcall, clonetid, fromdate);
EGOTO(error_exit, code, "Could not start the dump process \n");
- VDONE;
+ VEDONE;
- VPRINT1("Dumping volume %u...", afromvol);
+ VEPRINT1("Dumping volume %u...", afromvol);
code = DumpFunction(fromcall, rock);
EGOTO(error_exit, code, "Error while dumping volume \n");
- VDONE;
+ VEDONE;
error_exit:
/* now delete the clone */
- VPRINT1("Deleting the cloned volume %u ...", clonevol);
+ VEPRINT1("Deleting the cloned volume %u ...", clonevol);
code = AFSVolDeleteVolume(fromconn, clonetid);
if (code) {
fprintf(STDERR, "Failed to delete the cloned volume %lu\n",
(unsigned long)clonevol);
} else {
- VDONE;
+ VEDONE;
}
if (fromcall) {
}
}
if (clonetid) {
- VPRINT1("Ending transaction on cloned volume %u...", clonevol);
+ VEPRINT1("Ending transaction on cloned volume %u...", clonevol);
code = AFSVolEndTrans(fromconn, clonetid, &rcode);
if (code || rcode) {
fprintf(STDERR,
if (!error)
error = (code ? code : rcode);
}
- VDONE;
+ VEDONE;
}
if (fromconn)
rx_DestroyConnection(fromconn);
struct volser_status tstatus;
struct volintInfo vinfo;
char partName[10];
+ char tovolreal[VOLSER_OLDMAXVOLNAME];
afs_int32 pvolid, pparentid;
afs_int32 temptid;
int success;
}
if (!pparentid) pparentid = pvolid;
/* at this point we have a volume id to use/reuse for the volume to be restored */
+ strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
+
if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
EGOTO1(refail, VOLSERBADOP,
"The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
tovolname);
+ } else {
+ if ((pparentid != pvolid) && (flags & RV_RDONLY)) {
+ if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 10)) {
+ EGOTO1(refail, VOLSERBADOP,
+ "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname);
+ }
+ snprintf(tovolreal, VOLSER_OLDMAXVOLNAME, "%s.readonly", tovolname);
+ }
}
MapPartIdIntoName(topart, partName);
fprintf(STDOUT, "Restoring volume %s Id %lu on server %s partition %s ..",
- tovolname, (unsigned long)pvolid,
+ tovolreal, (unsigned long)pvolid,
hostutil_GetNameByINet(toserver), partName);
fflush(STDOUT);
code =
- AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid, &pvolid,
+ AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid,
&totid);
if (code) {
if (flags & RV_FULLRST) { /* full restore: delete then create anew */
VDONE;
code =
- AFSVolCreateVolume(toconn, topart, tovolname, volsertype, pparentid,
+ AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid,
&pvolid, &totid);
EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
} else {
cookie.parent = pparentid;
cookie.type = voltype;
cookie.clone = 0;
- strncpy(cookie.name, tovolname, VOLSER_OLDMAXVOLNAME);
+ strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME);
tocall = rx_NewCall(toconn);
terror = StartAFSVolRestore(tocall, totid, 1, &cookie);
error = code;
goto refail;
}
- code = AFSVolSetIdsTypes(toconn, totid, tovolname, voltype, pparentid, 0, 0);
+ code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0);
if (code) {
fprintf(STDERR, "Could not set the right type and ID on %lu\n",
(unsigned long)pvolid);
toserver, errcode);
if ((!errcode && !same)
|| (entry.serverPartition[index] != topart)) {
- tempconn =
- UV_Bind(entry.serverNumber[index],
- AFSCONF_VOLUMEPORT);
-
- MapPartIdIntoName(entry.serverPartition[index],
- apartName);
- VPRINT3
- ("Deleting the previous volume %u on server %s, partition %s ...",
- pvolid,
- hostutil_GetNameByINet(entry.serverNumber[index]),
- apartName);
- code =
- AFSVolTransCreate(tempconn, pvolid,
- entry.serverPartition[index],
- ITOffline, &temptid);
- if (!code) {
+ if (flags & RV_NODEL) {
+ VPRINT2
+ ("Not deleting the previous volume %u on server %s, ...",
+ pvolid,
+ hostutil_GetNameByINet(entry.serverNumber[index]));
+ } else {
+ tempconn =
+ UV_Bind(entry.serverNumber[index],
+ AFSCONF_VOLUMEPORT);
+
+ MapPartIdIntoName(entry.serverPartition[index],
+ apartName);
+ VPRINT3
+ ("Deleting the previous volume %u on server %s, partition %s ...",
+ pvolid,
+ hostutil_GetNameByINet(entry.serverNumber[index]),
+ apartName);
code =
- AFSVolSetFlags(tempconn, temptid,
- VTDeleteOnSalvage |
- VTOutOfService);
- if (code) {
- fprintf(STDERR,
- "Could not set flags on volume %lu on the older site\n",
- (unsigned long)pvolid);
- error = code;
- goto refail;
- }
- code = AFSVolDeleteVolume(tempconn, temptid);
- if (code) {
- fprintf(STDERR,
- "Could not delete volume %lu on the older site\n",
- (unsigned long)pvolid);
- error = code;
- goto refail;
- }
- code = AFSVolEndTrans(tempconn, temptid, &rcode);
- temptid = 0;
- if (!code)
- code = rcode;
- if (code) {
- fprintf(STDERR,
- "Could not end transaction on volume %lu on the older site\n",
- (unsigned long)pvolid);
- error = code;
- goto refail;
+ AFSVolTransCreate(tempconn, pvolid,
+ entry.serverPartition[index],
+ ITOffline, &temptid);
+ if (!code) {
+ code =
+ AFSVolSetFlags(tempconn, temptid,
+ VTDeleteOnSalvage |
+ VTOutOfService);
+ if (code) {
+ fprintf(STDERR,
+ "Could not set flags on volume %lu on the older site\n",
+ (unsigned long)pvolid);
+ error = code;
+ goto refail;
+ }
+ code = AFSVolDeleteVolume(tempconn, temptid);
+ if (code) {
+ fprintf(STDERR,
+ "Could not delete volume %lu on the older site\n",
+ (unsigned long)pvolid);
+ error = code;
+ goto refail;
+ }
+ code = AFSVolEndTrans(tempconn, temptid, &rcode);
+ temptid = 0;
+ if (!code)
+ code = rcode;
+ if (code) {
+ fprintf(STDERR,
+ "Could not end transaction on volume %lu on the older site\n",
+ (unsigned long)pvolid);
+ error = code;
+ goto refail;
+ }
+ VDONE;
+ MapPartIdIntoName(entry.serverPartition[index],
+ partName);
}
- VDONE;
- MapPartIdIntoName(entry.serverPartition[index],
- partName);
}
}
entry.serverNumber[index] = toserver;
/*adds <server> and <part> as a readonly replication site for <volid>
*in vldb */
int
-UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid)
+UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
{
int j, nro = 0, islocked = 0;
struct nvldbentry entry, storeEntry;
VPRINT("Adding a new site ...");
entry.serverNumber[entry.nServers] = server;
entry.serverPartition[entry.nServers] = part;
- entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
+ if (!valid) {
+ entry.serverFlags[entry.nServers] = (ITSROVOL | RO_DONTUSE);
+ } else {
+ entry.serverFlags[entry.nServers] = (ITSROVOL);
+ }
entry.nServers++;
MapNetworkToHost(&entry, &storeEntry);
afs_int32 code, error = 0;
struct nvldbentry entry, storeEntry;
char pname[10];
- int pass = 0, islocked = 0, createentry, addvolume, modified, mod;
+ int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
afs_int32 rwvolid;
- if (modentry)
+ if (modentry) {
+ if (*modentry == 1)
+ doit = 0;
*modentry = 0;
+ }
rwvolid =
((volumeinfo->type ==
RWVOL) ? volumeinfo->volid : volumeinfo->parentID);
(unsigned long)volumeinfo->volid);
}
- Lp_SetRWValue(entry, entry.serverNumber[idx],
+ Lp_SetRWValue(&entry, entry.serverNumber[idx],
entry.serverPartition[idx], 0L, 0L);
entry.nServers--;
modified++;
if (entry.volumeId[RWVOL] > *maxvolid)
*maxvolid = entry.volumeId[RWVOL];
- if (modified) {
+ if (modified && doit) {
MapNetworkToHost(&entry, &storeEntry);
if (createentry) {
}
}
- if (verbose) {
+ if (verbose && doit) {
fprintf(STDOUT, "-- status after --\n");
if (modified)
EnumerateEntry(&entry);
volumeInfo.volEntries_val = (volintInfo *) 0;
volumeInfo.volEntries_len = 0;
- if (!aserver && flags) {
+ if (!aserver && (flags & 1)) {
/* fprintf(STDERR,"Partition option requires a server option\n"); */
ERROR_EXIT(EINVAL);
}
/* Turn verbose logging off and do our own verbose logging */
tverbose = verbose;
+ if (flags & 2)
+ tverbose = 1;
verbose = 0;
/* Read the VLDB entry */
* Equivalent to a syncserv.
*/
if (!vcode) {
+ /* Tell CheckVldb not to update if appropriate */
+ if (flags & 2)
+ mod = 1;
+ else
+ mod = 0;
code = CheckVldb(&vldbentry, &mod);
if (code) {
fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
/* If aserver is given, we will search for the desired volume on it */
if (aserver) {
/* Generate array of partitions on the server that we will check */
- if (!flags) {
+ if (!(flags & 1)) {
code = UV_ListPartitions(aserver, &PartList, &pcnt);
if (code) {
fprintf(STDERR,
ERROR_EXIT(code);
}
} else {
+ if (flags & 2)
+ mod = 1;
+ else
+ mod = 0;
/* Found one, sync it with VLDB entry */
code =
CheckVolume(volumeInfo.volEntries_val, aserver,
ERROR_EXIT(code);
}
} else {
+ if (flags & 2)
+ mod = 1;
+ else
+ mod = 0;
/* Found one, sync it with VLDB entry */
code =
CheckVolume(volumeInfo.volEntries_val, aserver,
/* if (aserver) */
/* If verbose output, print a summary of what changed */
- if (tverbose) {
+ if (tverbose && !(flags & 2)) {
fprintf(STDOUT, "-- status after --\n");
code = VLDB_GetEntryByName(avolname, &vldbentry);
if (code && (code != VL_NOENT)) {
aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
/* Generate array of partitions to check */
- if (!flags) {
+ if (!(flags & 1)) {
code = UV_ListPartitions(aserver, &PartList, &pcnt);
if (code) {
fprintf(STDERR,
fflush(STDOUT);
}
+ if (flags & 2)
+ modified = 1;
+ else
+ modified = 0;
code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
if (code) {
PrintError("", code);
} /* thru all partitions */
- VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
- failures, modifications);
+ if (flags & 2) {
+ VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
+ tentries, failures, modifications);
+ } else {
+ VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
+ tentries, failures, modifications);
+ }
error_exit:
/* Now check if the maxvolid is larger than that stored in the VLDB */
afs_int32 code, error = 0;
struct nvldbentry storeEntry;
int islocked = 0, mod, modentry, delentry = 0;
- int pass = 0;
+ int pass = 0, doit=1;
- if (modified)
+ if (modified) {
+ if (*modified == 1)
+ doit = 0;
*modified = 0;
+ }
if (verbose) {
fprintf(STDOUT, "_______________________________\n");
fprintf(STDOUT, "\n-- status before -- \n");
code = CheckVldbRWBK(entry, &mod);
if (code)
ERROR_EXIT(code);
- if (mod && (pass == 1))
+ if (mod && (pass == 1) && doit)
goto retry;
if (mod)
modentry++;
code = CheckVldbRO(entry, &mod);
if (code)
ERROR_EXIT(code);
- if (mod && (pass == 1))
+ if (mod && (pass == 1) && doit)
goto retry;
if (mod)
modentry++;
/* The VLDB entry has been updated. If it as been modified, then
* write the entry back out the the VLDB.
*/
- if (modentry) {
+ if (modentry && doit) {
if (pass == 1)
goto retry;
if (!(entry->flags & RW_EXISTS) && !(entry->flags & BACK_EXISTS)
- && !(entry->flags & RO_EXISTS)) {
+ && !(entry->flags & RO_EXISTS) && doit) {
/* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */
code =
ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL],
islocked = 0;
}
- if (verbose) {
+ if (verbose && doit) {
fprintf(STDOUT, "-- status after --\n");
if (delentry)
fprintf(STDOUT, "\n**entry deleted**\n");
struct nvldbentry *vlentry;
afs_int32 si, nsi, j;
+ if (flags & 2)
+ verbose = 1;
+
aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
/* Set up attributes to search VLDB */
attributes.server = ntohl(aserver);
attributes.Mask = VLLIST_SERVER;
- if (flags) {
+ if ((flags & 1)) {
attributes.partition = apart;
attributes.Mask |= VLLIST_PARTITION;
}
VPRINT1("Processing VLDB entry %d ...\n", j + 1);
+ /* Tell CheckVldb not to update if appropriate */
+ if (flags & 2)
+ modified = 1;
+ else
+ modified = 0;
code = CheckVldb(vlentry, &modified);
if (code) {
PrintError("", code);
}
}
- VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", tentries,
- failures, modifications);
+ if (flags & 2) {
+ VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
+ tentries, failures, modifications);
+ } else {
+ VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
+ tentries, failures, modifications);
+ }
error_exit:
if (aconn)