| File: | volser/vsprocs.c |
| Location: | line 4341, column 5 |
| Description: | Assigned value is always the same as the existing value |
| 1 | /* | ||
| 2 | * Copyright 2000, International Business Machines Corporation and others. | ||
| 3 | * All Rights Reserved. | ||
| 4 | * | ||
| 5 | * This software has been released under the terms of the IBM Public | ||
| 6 | * License. For details, see the LICENSE file in the top-level source | ||
| 7 | * directory or online at http://www.openafs.org/dl/license10.html | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <afsconfig.h> | ||
| 11 | #include <afs/param.h> | ||
| 12 | |||
| 13 | #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */ | ||
| 14 | #include <roken.h> | ||
| 15 | |||
| 16 | #ifdef AFS_AIX_ENV | ||
| 17 | #include <sys/statfs.h> | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #include <lock.h> | ||
| 21 | #include <afs/voldefs.h> | ||
| 22 | #include <rx/xdr.h> | ||
| 23 | #include <rx/rx.h> | ||
| 24 | #include <afs/vlserver.h> | ||
| 25 | #include <afs/nfs.h> | ||
| 26 | #include <afs/cellconfig.h> | ||
| 27 | #include <afs/keys.h> | ||
| 28 | #include <ubik.h> | ||
| 29 | #include <afs/afsint.h> | ||
| 30 | #include "volser.h" | ||
| 31 | #include "volint.h" | ||
| 32 | #include "lockdata.h" | ||
| 33 | #include <afs/com_err.h> | ||
| 34 | #include <rx/rxkad.h> | ||
| 35 | #include <afs/kautils.h> | ||
| 36 | #include <afs/cmd.h> | ||
| 37 | #include <afs/ihandle.h> | ||
| 38 | #ifdef AFS_NT40_ENV | ||
| 39 | #include <afs/ntops.h> | ||
| 40 | #endif | ||
| 41 | #include <afs/vnode.h> | ||
| 42 | #include <afs/volume.h> | ||
| 43 | #define ERRCODE_RANGE8 8 /* from error_table.h */ | ||
| 44 | #define CLOCKSKEW2 2 /* not really skew, but resolution */ | ||
| 45 | #define CLOCKADJ(x)(((x) < 2) ? 0 : (x) - 2) (((x) < CLOCKSKEW2) ? 0 : (x) - CLOCKSKEW2) | ||
| 46 | |||
| 47 | /* for UV_MoveVolume() recovery */ | ||
| 48 | |||
| 49 | #include <setjmp.h> | ||
| 50 | |||
| 51 | #include "volser_internal.h" | ||
| 52 | #include "volser_prototypes.h" | ||
| 53 | #include "vsutils_prototypes.h" | ||
| 54 | #include "lockprocs_prototypes.h" | ||
| 55 | |||
| 56 | struct ubik_client *cstruct; | ||
| 57 | int verbose = 0, noresolve = 0; | ||
| 58 | |||
| 59 | struct release { | ||
| 60 | afs_uint32 crtime; | ||
| 61 | afs_uint32 uptime; | ||
| 62 | afs_int32 vldbEntryIndex; | ||
| 63 | }; | ||
| 64 | |||
| 65 | /* Utility macros used by rest of this source file */ | ||
| 66 | #define EPRINT(ec, es)do { fprintf(__stderrp, "\n"); fprintf(__stderrp, (es)); PrintError (" ",ec); } while (0) \ | ||
| 67 | do { \ | ||
| 68 | fprintf(STDERR__stderrp, "\n"); \ | ||
| 69 | fprintf(STDERR__stderrp, (es)); \ | ||
| 70 | PrintError(" ",ec); \ | ||
| 71 | } while (0) | ||
| 72 | |||
| 73 | #define EPRINT1(ec, es, ep1)do { fprintf(__stderrp, "\n"); fprintf(__stderrp, (es), (ep1) ); PrintError(" ",ec); } while (0) \ | ||
| 74 | do { \ | ||
| 75 | fprintf(STDERR__stderrp, "\n"); \ | ||
| 76 | fprintf(STDERR__stderrp, (es), (ep1)); \ | ||
| 77 | PrintError(" ",ec); \ | ||
| 78 | } while (0) | ||
| 79 | |||
| 80 | #define EPRINT2(ec, es, ep1, ep2)do { fprintf(__stderrp, "\n"); fprintf(__stderrp, (es), (ep1) , (ep2)); PrintError(" ",ec); } while (0) \ | ||
| 81 | do { \ | ||
| 82 | fprintf(STDERR__stderrp, "\n"); \ | ||
| 83 | fprintf(STDERR__stderrp, (es), (ep1), (ep2)); \ | ||
| 84 | PrintError(" ",ec); \ | ||
| 85 | } while (0) | ||
| 86 | |||
| 87 | #define EPRINT3(ec, es, ep1, ep2, ep3)do { fprintf(__stderrp, "\n"); fprintf(__stderrp, (es), (ep1) , (ep2), (ep3)); PrintError(" ",ec); } while (0) \ | ||
| 88 | do { \ | ||
| 89 | fprintf(STDERR__stderrp, "\n"); \ | ||
| 90 | fprintf(STDERR__stderrp, (es), (ep1), (ep2), (ep3)); \ | ||
| 91 | PrintError(" ",ec); \ | ||
| 92 | } while (0) | ||
| 93 | |||
| 94 | #define EGOTO(where, ec, es)do { if (ec) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((es))); PrintError(" ",(ec)); } while (0); error = (ec); goto where; } } while (0) \ | ||
| 95 | do { \ | ||
| 96 | if (ec) { \ | ||
| 97 | EPRINT((ec),(es))do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ((es))); PrintError (" ",(ec)); } while (0); \ | ||
| 98 | error = (ec); \ | ||
| 99 | goto where; \ | ||
| 100 | } \ | ||
| 101 | } while (0) | ||
| 102 | |||
| 103 | #define EGOTO1(where, ec, es, ep1)do { if (ec) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((es)), ((ep1))); PrintError(" ",(ec)); } while (0); error = (ec); goto where; } } while (0) \ | ||
| 104 | do { \ | ||
| 105 | if (ec) { \ | ||
| 106 | EPRINT1((ec),(es),(ep1))do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ((es)), ((ep1 ))); PrintError(" ",(ec)); } while (0); \ | ||
| 107 | error = (ec); \ | ||
| 108 | goto where; \ | ||
| 109 | } \ | ||
| 110 | } while (0) | ||
| 111 | |||
| 112 | #define EGOTO2(where, ec, es, ep1, ep2)do { if (ec) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((es)), ((ep1)), ((ep2))); PrintError(" ",(ec)); } while ( 0); error = (ec); goto where; } } while (0) \ | ||
| 113 | do { \ | ||
| 114 | if (ec) { \ | ||
| 115 | EPRINT2((ec),(es),(ep1),(ep2))do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ((es)), ((ep1 )), ((ep2))); PrintError(" ",(ec)); } while (0); \ | ||
| 116 | error = (ec); \ | ||
| 117 | goto where; \ | ||
| 118 | } \ | ||
| 119 | } while (0) | ||
| 120 | |||
| 121 | #define EGOTO3(where, ec, es, ep1, ep2, ep3)do { if (ec) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((es)), ((ep1)), ((ep2)), ((ep3))); PrintError(" ",(ec)); } while (0); error = (ec); goto where; } } while (0) \ | ||
| 122 | do { \ | ||
| 123 | if (ec) { \ | ||
| 124 | EPRINT3((ec),(es),(ep1),(ep2),(ep3))do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ((es)), ((ep1 )), ((ep2)), ((ep3))); PrintError(" ",(ec)); } while (0); \ | ||
| 125 | error = (ec); \ | ||
| 126 | goto where; \ | ||
| 127 | } \ | ||
| 128 | } while (0) | ||
| 129 | |||
| 130 | #define VPRINT(es){ if (verbose) { fprintf(__stdoutp, (es)); fflush(__stdoutp); } } \ | ||
| 131 | { if (verbose) { fprintf(STDOUT__stdoutp, (es)); fflush(STDOUT__stdoutp); } } | ||
| 132 | #define VPRINT1(es, p){ if (verbose) { fprintf(__stdoutp, (es), (p)); fflush(__stdoutp ); } } \ | ||
| 133 | { if (verbose) { fprintf(STDOUT__stdoutp, (es), (p)); fflush(STDOUT__stdoutp); } } | ||
| 134 | #define VPRINT2(es, p1, p2){ if (verbose) { fprintf(__stdoutp, (es), (p1), (p2)); fflush (__stdoutp); } } \ | ||
| 135 | { if (verbose) { fprintf(STDOUT__stdoutp, (es), (p1), (p2)); fflush(STDOUT__stdoutp); } } | ||
| 136 | #define VPRINT3(es, p1, p2, p3){ if (verbose) { fprintf(__stdoutp, (es), (p1), (p2), (p3)); fflush (__stdoutp); } } \ | ||
| 137 | { if (verbose) { fprintf(STDOUT__stdoutp, (es), (p1), (p2), (p3)); fflush(STDOUT__stdoutp); } } | ||
| 138 | #define VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } } \ | ||
| 139 | { if (verbose) { fprintf(STDOUT__stdoutp, " done\n"); fflush(STDOUT__stdoutp); } } | ||
| 140 | #define VEPRINT(es){ if (verbose) { fprintf(__stderrp, (es)); fflush(__stderrp); } } \ | ||
| 141 | { if (verbose) { fprintf(STDERR__stderrp, (es)); fflush(STDERR__stderrp); } } | ||
| 142 | #define VEPRINT1(es, p){ if (verbose) { fprintf(__stderrp, (es), (p)); fflush(__stderrp ); } } \ | ||
| 143 | { if (verbose) { fprintf(STDERR__stderrp, (es), (p)); fflush(STDERR__stderrp); } } | ||
| 144 | #define VEPRINT2(es, p1, p2){ if (verbose) { fprintf(__stderrp, (es), (p1), (p2)); fflush (__stderrp); } } \ | ||
| 145 | { if (verbose) { fprintf(STDERR__stderrp, (es), (p1), (p2)); fflush(STDERR__stderrp); } } | ||
| 146 | #define VEPRINT3(es, p1, p2, p3){ if (verbose) { fprintf(__stderrp, (es), (p1), (p2), (p3)); fflush (__stderrp); } } \ | ||
| 147 | { if (verbose) { fprintf(STDERR__stderrp, (es), (p1), (p2), (p3)); fflush(STDERR__stderrp); } } | ||
| 148 | #define VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } } \ | ||
| 149 | { if (verbose) { fprintf(STDERR__stderrp, " done\n"); fflush(STDERR__stderrp); } } | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | /* getting rid of this */ | ||
| 154 | #define ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0) do { \ | ||
| 155 | error = (code); \ | ||
| 156 | goto error_exit; \ | ||
| 157 | } while (0) | ||
| 158 | |||
| 159 | |||
| 160 | /* Protos for static routines */ | ||
| 161 | #if 0 | ||
| 162 | static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn, | ||
| 163 | afs_int32 apart, afs_uint32 okvol, | ||
| 164 | afs_uint32 delvol); | ||
| 165 | #endif | ||
| 166 | static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part, | ||
| 167 | afs_int32 flags); | ||
| 168 | static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index, | ||
| 169 | struct rx_connection **connPtr, afs_int32 * transPtr, | ||
| 170 | afs_uint32 * crtimePtr, afs_uint32 * uptimePtr, | ||
| 171 | afs_int32 *origflags); | ||
| 172 | static int SimulateForwardMultiple(struct rx_connection *fromconn, | ||
| 173 | afs_int32 fromtid, afs_int32 fromdate, | ||
| 174 | manyDests * tr, afs_int32 flags, | ||
| 175 | void *cookie, manyResults * results); | ||
| 176 | static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, | ||
| 177 | afs_int32 apart, afs_int32 * modentry, | ||
| 178 | afs_uint32 * maxvolid, struct nvldbentry *aentry); | ||
| 179 | static afs_int32 VolumeExists(afs_uint32 server, afs_int32 partition, | ||
| 180 | afs_uint32 volumeid); | ||
| 181 | static afs_int32 CheckVldbRWBK(struct nvldbentry * entry, | ||
| 182 | afs_int32 * modified); | ||
| 183 | static afs_int32 CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified); | ||
| 184 | static afs_int32 CheckVldb(struct nvldbentry *entry, afs_int32 * modified, | ||
| 185 | afs_int32 *deleted); | ||
| 186 | static void dump_sig_handler(int x); | ||
| 187 | static int sortVolumes(const void *a, const void *b); | ||
| 188 | |||
| 189 | |||
| 190 | /*map the partition <partId> into partition name <partName>*/ | ||
| 191 | void | ||
| 192 | MapPartIdIntoName(afs_int32 partId, char *partName) | ||
| 193 | { | ||
| 194 | if (partId < 26) { /* what if partId > = 26 ? */ | ||
| 195 | strcpy(partName, "/vicep"); | ||
| 196 | partName[6] = partId + 'a'; | ||
| 197 | partName[7] = '\0'; | ||
| 198 | return; | ||
| 199 | } else if (partId < VOLMAXPARTS255) { | ||
| 200 | strcpy(partName, "/vicep"); | ||
| 201 | partId -= 26; | ||
| 202 | partName[6] = 'a' + (partId / 26); | ||
| 203 | partName[7] = 'a' + (partId % 26); | ||
| 204 | partName[8] = '\0'; | ||
| 205 | return; | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | int | ||
| 210 | PrintError(char *msg, afs_int32 errcode) | ||
| 211 | { | ||
| 212 | fprintf(STDERR__stderrp, "%s", msg); | ||
| 213 | /*replace by a big switch statement */ | ||
| 214 | switch (errcode) { | ||
| 215 | case 0: | ||
| 216 | break; | ||
| 217 | case -1: | ||
| 218 | fprintf(STDERR__stderrp, "Possible communication failure\n"); | ||
| 219 | break; | ||
| 220 | case VSALVAGE101: | ||
| 221 | fprintf(STDERR__stderrp, "Volume needs to be salvaged\n"); | ||
| 222 | break; | ||
| 223 | case VNOVNODE102: | ||
| 224 | fprintf(STDERR__stderrp, "Bad vnode number quoted\n"); | ||
| 225 | break; | ||
| 226 | case VNOVOL103: | ||
| 227 | fprintf(STDERR__stderrp, | ||
| 228 | "Volume not attached, does not exist, or not on line\n"); | ||
| 229 | break; | ||
| 230 | case VVOLEXISTS104: | ||
| 231 | fprintf(STDERR__stderrp, "Volume already exists\n"); | ||
| 232 | break; | ||
| 233 | case VNOSERVICE105: | ||
| 234 | fprintf(STDERR__stderrp, "Volume is not in service\n"); | ||
| 235 | break; | ||
| 236 | case VOFFLINE106: | ||
| 237 | fprintf(STDERR__stderrp, "Volume is off line\n"); | ||
| 238 | break; | ||
| 239 | case VONLINE107: | ||
| 240 | fprintf(STDERR__stderrp, "Volume is already on line\n"); | ||
| 241 | break; | ||
| 242 | case VDISKFULL108: | ||
| 243 | fprintf(STDERR__stderrp, "Partition is full\n"); | ||
| 244 | break; | ||
| 245 | case VOVERQUOTA109: | ||
| 246 | fprintf(STDERR__stderrp, "Volume max quota exceeded\n"); | ||
| 247 | break; | ||
| 248 | case VBUSY110: | ||
| 249 | fprintf(STDERR__stderrp, "Volume temporarily unavailable\n"); | ||
| 250 | break; | ||
| 251 | case VMOVED111: | ||
| 252 | fprintf(STDERR__stderrp, "Volume has moved to another server\n"); | ||
| 253 | break; | ||
| 254 | case VL_IDEXIST(363520L): | ||
| 255 | fprintf(STDERR__stderrp, "VLDB: volume Id exists in the vldb\n"); | ||
| 256 | break; | ||
| 257 | case VL_IO(363521L): | ||
| 258 | fprintf(STDERR__stderrp, "VLDB: a read terminated too early\n"); | ||
| 259 | break; | ||
| 260 | case VL_NAMEEXIST(363522L): | ||
| 261 | fprintf(STDERR__stderrp, "VLDB: volume entry exists in the vldb\n"); | ||
| 262 | break; | ||
| 263 | case VL_CREATEFAIL(363523L): | ||
| 264 | fprintf(STDERR__stderrp, "VLDB: internal creation failure\n"); | ||
| 265 | break; | ||
| 266 | case VL_NOENT(363524L): | ||
| 267 | fprintf(STDERR__stderrp, "VLDB: no such entry\n"); | ||
| 268 | break; | ||
| 269 | case VL_EMPTY(363525L): | ||
| 270 | fprintf(STDERR__stderrp, "VLDB: vldb database is empty\n"); | ||
| 271 | break; | ||
| 272 | case VL_ENTDELETED(363526L): | ||
| 273 | fprintf(STDERR__stderrp, "VLDB: entry is deleted (soft delete)\n"); | ||
| 274 | break; | ||
| 275 | case VL_BADNAME(363527L): | ||
| 276 | fprintf(STDERR__stderrp, "VLDB: volume name is illegal\n"); | ||
| 277 | break; | ||
| 278 | case VL_BADINDEX(363528L): | ||
| 279 | fprintf(STDERR__stderrp, "VLDB: index was out of range\n"); | ||
| 280 | break; | ||
| 281 | case VL_BADVOLTYPE(363529L): | ||
| 282 | fprintf(STDERR__stderrp, "VLDB: bad volume type\n"); | ||
| 283 | break; | ||
| 284 | case VL_BADSERVER(363530L): | ||
| 285 | fprintf(STDERR__stderrp, "VLDB: illegal server number (not within limits)\n"); | ||
| 286 | break; | ||
| 287 | case VL_BADPARTITION(363531L): | ||
| 288 | fprintf(STDERR__stderrp, "VLDB: bad partition number\n"); | ||
| 289 | break; | ||
| 290 | case VL_REPSFULL(363532L): | ||
| 291 | fprintf(STDERR__stderrp, "VLDB: run out of space for replication sites\n"); | ||
| 292 | break; | ||
| 293 | case VL_NOREPSERVER(363533L): | ||
| 294 | fprintf(STDERR__stderrp, "VLDB: no such repsite server exists\n"); | ||
| 295 | break; | ||
| 296 | case VL_DUPREPSERVER(363534L): | ||
| 297 | fprintf(STDERR__stderrp, "VLDB: replication site server already exists\n"); | ||
| 298 | break; | ||
| 299 | case VL_RWNOTFOUND(363535L): | ||
| 300 | fprintf(STDERR__stderrp, "VLDB: parent r/w entry not found\n"); | ||
| 301 | break; | ||
| 302 | case VL_BADREFCOUNT(363536L): | ||
| 303 | fprintf(STDERR__stderrp, "VLDB: illegal reference count number\n"); | ||
| 304 | break; | ||
| 305 | case VL_SIZEEXCEEDED(363537L): | ||
| 306 | fprintf(STDERR__stderrp, "VLDB: vldb size for attributes exceeded\n"); | ||
| 307 | break; | ||
| 308 | case VL_BADENTRY(363538L): | ||
| 309 | fprintf(STDERR__stderrp, "VLDB: bad incoming vldb entry\n"); | ||
| 310 | break; | ||
| 311 | case VL_BADVOLIDBUMP(363539L): | ||
| 312 | fprintf(STDERR__stderrp, "VLDB: illegal max volid increment\n"); | ||
| 313 | break; | ||
| 314 | case VL_IDALREADYHASHED(363540L): | ||
| 315 | fprintf(STDERR__stderrp, "VLDB: (RO/BACK) Id already hashed\n"); | ||
| 316 | break; | ||
| 317 | case VL_ENTRYLOCKED(363541L): | ||
| 318 | fprintf(STDERR__stderrp, "VLDB: vldb entry is already locked\n"); | ||
| 319 | break; | ||
| 320 | case VL_BADVOLOPER(363542L): | ||
| 321 | fprintf(STDERR__stderrp, "VLDB: bad volume operation code\n"); | ||
| 322 | break; | ||
| 323 | case VL_BADRELLOCKTYPE(363543L): | ||
| 324 | fprintf(STDERR__stderrp, "VLDB: bad release lock type\n"); | ||
| 325 | break; | ||
| 326 | case VL_RERELEASE(363544L): | ||
| 327 | fprintf(STDERR__stderrp, "VLDB: status report: last release was aborted\n"); | ||
| 328 | break; | ||
| 329 | case VL_BADSERVERFLAG(363545L): | ||
| 330 | fprintf(STDERR__stderrp, "VLDB: invalid replication site server flag\n"); | ||
| 331 | break; | ||
| 332 | case VL_PERM(363546L): | ||
| 333 | fprintf(STDERR__stderrp, "VLDB: no permission access for call\n"); | ||
| 334 | break; | ||
| 335 | case VOLSERREAD_DUMPERROR(1492325122L): | ||
| 336 | fprintf(STDERR__stderrp, | ||
| 337 | "VOLSER: Problems encountered in reading the dump file !\n"); | ||
| 338 | break; | ||
| 339 | case VOLSERDUMPERROR(1492325123L): | ||
| 340 | fprintf(STDERR__stderrp, "VOLSER: Problems encountered in doing the dump !\n"); | ||
| 341 | break; | ||
| 342 | case VOLSERATTACH_ERROR(1492325124L): | ||
| 343 | fprintf(STDERR__stderrp, "VOLSER: Could not attach the volume\n"); | ||
| 344 | break; | ||
| 345 | case VOLSERDETACH_ERROR(1492325126L): | ||
| 346 | fprintf(STDERR__stderrp, "VOLSER: Could not detach the volume\n"); | ||
| 347 | break; | ||
| 348 | case VOLSERILLEGAL_PARTITION(1492325125L): | ||
| 349 | fprintf(STDERR__stderrp, "VOLSER: encountered illegal partition number\n"); | ||
| 350 | break; | ||
| 351 | case VOLSERBAD_ACCESS(1492325127L): | ||
| 352 | fprintf(STDERR__stderrp, "VOLSER: permission denied, not a super user\n"); | ||
| 353 | break; | ||
| 354 | case VOLSERVLDB_ERROR(1492325128L): | ||
| 355 | fprintf(STDERR__stderrp, "VOLSER: error detected in the VLDB\n"); | ||
| 356 | break; | ||
| 357 | case VOLSERBADNAME(1492325129L): | ||
| 358 | fprintf(STDERR__stderrp, "VOLSER: error in volume name\n"); | ||
| 359 | break; | ||
| 360 | case VOLSERVOLMOVED(1492325130L): | ||
| 361 | fprintf(STDERR__stderrp, "VOLSER: volume has moved\n"); | ||
| 362 | break; | ||
| 363 | case VOLSERBADOP(1492325131L): | ||
| 364 | fprintf(STDERR__stderrp, "VOLSER: illegal operation\n"); | ||
| 365 | break; | ||
| 366 | case VOLSERBADRELEASE(1492325132L): | ||
| 367 | fprintf(STDERR__stderrp, "VOLSER: release could not be completed\n"); | ||
| 368 | break; | ||
| 369 | case VOLSERVOLBUSY(1492325133L): | ||
| 370 | fprintf(STDERR__stderrp, "VOLSER: volume is busy\n"); | ||
| 371 | break; | ||
| 372 | case VOLSERNO_MEMORY(1492325134L): | ||
| 373 | fprintf(STDERR__stderrp, "VOLSER: volume server is out of memory\n"); | ||
| 374 | break; | ||
| 375 | case VOLSERNOVOL(1492325135L): | ||
| 376 | fprintf(STDERR__stderrp, | ||
| 377 | "VOLSER: no such volume - location specified incorrectly or volume does not exist\n"); | ||
| 378 | break; | ||
| 379 | case VOLSERMULTIRWVOL(1492325136L): | ||
| 380 | fprintf(STDERR__stderrp, | ||
| 381 | "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n"); | ||
| 382 | break; | ||
| 383 | case VOLSERFAILEDOP(1492325137L): | ||
| 384 | fprintf(STDERR__stderrp, | ||
| 385 | "VOLSER: not all entries were successfully processed\n"); | ||
| 386 | break; | ||
| 387 | default: | ||
| 388 | { | ||
| 389 | initialize_KA_error_table(); | ||
| 390 | initialize_RXK_error_table(); | ||
| 391 | initialize_KTC_error_table(); | ||
| 392 | initialize_ACFG_error_table(); | ||
| 393 | initialize_CMD_error_table(); | ||
| 394 | initialize_VL_error_table(); | ||
| 395 | |||
| 396 | fprintf(STDERR__stderrp, "%s: %s\n", afs_error_table_name(errcode), | ||
| 397 | afs_error_message(errcode)); | ||
| 398 | break; | ||
| 399 | } | ||
| 400 | } | ||
| 401 | return 0; | ||
| 402 | } | ||
| 403 | |||
| 404 | void init_volintInfo(struct volintInfo *vinfo) { | ||
| 405 | memset(vinfo, 0, sizeof(struct volintInfo)); | ||
| 406 | |||
| 407 | vinfo->maxquota = -1; | ||
| 408 | vinfo->dayUse = -1; | ||
| 409 | vinfo->creationDate = -1; | ||
| 410 | vinfo->updateDate = -1; | ||
| 411 | vinfo->flags = -1; | ||
| 412 | vinfo->spare0 = -1; | ||
| 413 | vinfo->spare1 = -1; | ||
| 414 | vinfo->spare2 = -1; | ||
| 415 | vinfo->spare3 = -1; | ||
| 416 | } | ||
| 417 | |||
| 418 | static struct rx_securityClass *uvclass = 0; | ||
| 419 | static int uvindex = -1; | ||
| 420 | /* called by VLDBClient_Init to set the security module to be used in the RPC */ | ||
| 421 | int | ||
| 422 | UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex) | ||
| 423 | { | ||
| 424 | uvindex = aindex; | ||
| 425 | uvclass = as; | ||
| 426 | return 0; | ||
| 427 | } | ||
| 428 | |||
| 429 | /* bind to volser on <port> <aserver> */ | ||
| 430 | /* takes server address in network order, port in host order. dumb */ | ||
| 431 | struct rx_connection * | ||
| 432 | UV_Bind(afs_uint32 aserver, afs_int32 port) | ||
| 433 | { | ||
| 434 | struct rx_connection *tc; | ||
| 435 | |||
| 436 | tc = rx_NewConnection(aserver, htons(port)(__builtin_constant_p(port) ? (__uint16_t)(((__uint16_t)(port )) << 8 | ((__uint16_t)(port)) >> 8) : __bswap16_var (port)), VOLSERVICE_ID4, uvclass, | ||
| 437 | uvindex); | ||
| 438 | return tc; | ||
| 439 | } | ||
| 440 | |||
| 441 | static int | ||
| 442 | AFSVolCreateVolume_retry(struct rx_connection *z_conn, | ||
| 443 | afs_int32 partition, char *name, afs_int32 type, | ||
| 444 | afs_int32 parent, afs_uint32 *volid, afs_int32 *trans) | ||
| 445 | { | ||
| 446 | afs_int32 code; | ||
| 447 | int retries = 3; | ||
| 448 | while (retries) { | ||
| 449 | code = AFSVolCreateVolume(z_conn, partition, name, type, parent, | ||
| 450 | volid, trans); | ||
| 451 | if (code != VOLSERVOLBUSY(1492325133L)) | ||
| 452 | break; | ||
| 453 | retries--; | ||
| 454 | #ifdef AFS_PTHREAD_ENV | ||
| 455 | sleep(3-retries); | ||
| 456 | #else | ||
| 457 | IOMGR_Sleep(3-retries); | ||
| 458 | #endif | ||
| 459 | } | ||
| 460 | return code; | ||
| 461 | } | ||
| 462 | |||
| 463 | static int | ||
| 464 | AFSVolTransCreate_retry(struct rx_connection *z_conn, | ||
| 465 | afs_int32 volume, afs_int32 partition, | ||
| 466 | afs_int32 flags, afs_int32 * trans) | ||
| 467 | { | ||
| 468 | afs_int32 code; | ||
| 469 | int retries = 3; | ||
| 470 | while (retries) { | ||
| 471 | code = AFSVolTransCreate(z_conn, volume, partition, flags, trans); | ||
| 472 | if (code != VOLSERVOLBUSY(1492325133L)) | ||
| 473 | break; | ||
| 474 | retries--; | ||
| 475 | #ifdef AFS_PTHREAD_ENV | ||
| 476 | sleep(3-retries); | ||
| 477 | #else | ||
| 478 | IOMGR_Sleep(3-retries); | ||
| 479 | #endif | ||
| 480 | } | ||
| 481 | return code; | ||
| 482 | } | ||
| 483 | |||
| 484 | #if 0 | ||
| 485 | /* if <okvol> is allright(indicated by beibg able to | ||
| 486 | * start a transaction, delete the <delvol> */ | ||
| 487 | static afs_int32 | ||
| 488 | CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart, | ||
| 489 | afs_uint32 okvol, afs_uint32 delvol) | ||
| 490 | { | ||
| 491 | afs_int32 error, code, tid, rcode; | ||
| 492 | error = 0; | ||
| 493 | code = 0; | ||
| 494 | |||
| 495 | if (okvol == 0) { | ||
| 496 | code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline1, &tid); | ||
| 497 | if (!error && code) | ||
| 498 | error = code; | ||
| 499 | code = AFSVolDeleteVolume(aconn, tid); | ||
| 500 | if (!error && code) | ||
| 501 | error = code; | ||
| 502 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 503 | if (!code) | ||
| 504 | code = rcode; | ||
| 505 | if (!error && code) | ||
| 506 | error = code; | ||
| 507 | return error; | ||
| 508 | } else { | ||
| 509 | code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline1, &tid); | ||
| 510 | if (!code) { | ||
| 511 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 512 | if (!code) | ||
| 513 | code = rcode; | ||
| 514 | if (!error && code) | ||
| 515 | error = code; | ||
| 516 | code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline1, &tid); | ||
| 517 | if (!error && code) | ||
| 518 | error = code; | ||
| 519 | code = AFSVolDeleteVolume(aconn, tid); | ||
| 520 | if (!error && code) | ||
| 521 | error = code; | ||
| 522 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 523 | if (!code) | ||
| 524 | code = rcode; | ||
| 525 | if (!error && code) | ||
| 526 | error = code; | ||
| 527 | } else | ||
| 528 | error = code; | ||
| 529 | return error; | ||
| 530 | } | ||
| 531 | } | ||
| 532 | |||
| 533 | #endif | ||
| 534 | |||
| 535 | /* called by EmuerateEntry, show vldb entry in a reasonable format */ | ||
| 536 | void | ||
| 537 | SubEnumerateEntry(struct nvldbentry *entry) | ||
| 538 | { | ||
| 539 | int i; | ||
| 540 | char pname[10]; | ||
| 541 | int isMixed = 0; | ||
| 542 | char hoststr[16]; | ||
| 543 | |||
| 544 | #ifdef notdef | ||
| 545 | fprintf(STDOUT__stdoutp, " readWriteID %-10u ", entry->volumeId[RWVOL0]); | ||
| 546 | if (entry->flags & RW_EXISTS0x1000) | ||
| 547 | fprintf(STDOUT__stdoutp, " valid \n"); | ||
| 548 | else | ||
| 549 | fprintf(STDOUT__stdoutp, " invalid \n"); | ||
| 550 | fprintf(STDOUT__stdoutp, " readOnlyID %-10u ", entry->volumeId[ROVOL1]); | ||
| 551 | if (entry->flags & RO_EXISTS0x2000) | ||
| 552 | fprintf(STDOUT__stdoutp, " valid \n"); | ||
| 553 | else | ||
| 554 | fprintf(STDOUT__stdoutp, " invalid \n"); | ||
| 555 | fprintf(STDOUT__stdoutp, " backUpID %-10u ", entry->volumeId[BACKVOL2]); | ||
| 556 | if (entry->flags & BACK_EXISTS0x4000) | ||
| 557 | fprintf(STDOUT__stdoutp, " valid \n"); | ||
| 558 | else | ||
| 559 | fprintf(STDOUT__stdoutp, " invalid \n"); | ||
| 560 | if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS0x2000)) | ||
| 561 | fprintf(STDOUT__stdoutp, " releaseClone %-10u \n", entry->cloneId); | ||
| 562 | #else | ||
| 563 | if (entry->flags & RW_EXISTS0x1000) | ||
| 564 | fprintf(STDOUT__stdoutp, " RWrite: %-10u", entry->volumeId[RWVOL0]); | ||
| 565 | if (entry->flags & RO_EXISTS0x2000) | ||
| 566 | fprintf(STDOUT__stdoutp, " ROnly: %-10u", entry->volumeId[ROVOL1]); | ||
| 567 | if (entry->flags & BACK_EXISTS0x4000) | ||
| 568 | fprintf(STDOUT__stdoutp, " Backup: %-10u", entry->volumeId[BACKVOL2]); | ||
| 569 | if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS0x2000)) | ||
| 570 | fprintf(STDOUT__stdoutp, " RClone: %-10lu", (unsigned long)entry->cloneId); | ||
| 571 | fprintf(STDOUT__stdoutp, "\n"); | ||
| 572 | #endif | ||
| 573 | fprintf(STDOUT__stdoutp, " number of sites -> %lu\n", | ||
| 574 | (unsigned long)entry->nServers); | ||
| 575 | for (i = 0; i < entry->nServers; i++) { | ||
| 576 | if (entry->serverFlags[i] & NEW_REPSITE0x01) | ||
| 577 | isMixed = 1; | ||
| 578 | } | ||
| 579 | for (i = 0; i < entry->nServers; i++) { | ||
| 580 | MapPartIdIntoName(entry->serverPartition[i], pname); | ||
| 581 | fprintf(STDOUT__stdoutp, " server %s partition %s ", | ||
| 582 | noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) : | ||
| 583 | hostutil_GetNameByINet(entry->serverNumber[i]), pname); | ||
| 584 | if (entry->serverFlags[i] & ITSRWVOL0x04) | ||
| 585 | fprintf(STDOUT__stdoutp, "RW Site "); | ||
| 586 | else | ||
| 587 | fprintf(STDOUT__stdoutp, "RO Site "); | ||
| 588 | if (isMixed) { | ||
| 589 | if (entry->serverFlags[i] & NEW_REPSITE0x01) | ||
| 590 | fprintf(STDOUT__stdoutp," -- New release"); | ||
| 591 | else | ||
| 592 | if (!(entry->serverFlags[i] & ITSRWVOL0x04)) | ||
| 593 | fprintf(STDOUT__stdoutp," -- Old release"); | ||
| 594 | } else { | ||
| 595 | if (entry->serverFlags[i] & RO_DONTUSE0x20) | ||
| 596 | fprintf(STDOUT__stdoutp, " -- Not released"); | ||
| 597 | } | ||
| 598 | fprintf(STDOUT__stdoutp, "\n"); | ||
| 599 | } | ||
| 600 | |||
| 601 | return; | ||
| 602 | |||
| 603 | } | ||
| 604 | |||
| 605 | /*enumerate the vldb entry corresponding to <entry> */ | ||
| 606 | void | ||
| 607 | EnumerateEntry(struct nvldbentry *entry) | ||
| 608 | { | ||
| 609 | |||
| 610 | fprintf(STDOUT__stdoutp, "\n"); | ||
| 611 | fprintf(STDOUT__stdoutp, "%s \n", entry->name); | ||
| 612 | SubEnumerateEntry(entry); | ||
| 613 | return; | ||
| 614 | } | ||
| 615 | |||
| 616 | /* forcibly remove a volume. Very dangerous call */ | ||
| 617 | int | ||
| 618 | UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid) | ||
| 619 | { | ||
| 620 | struct rx_connection *tconn; | ||
| 621 | afs_int32 code; | ||
| 622 | |||
| 623 | tconn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 624 | if (tconn) { | ||
| 625 | code = AFSVolNukeVolume(tconn, partid, volid); | ||
| 626 | rx_DestroyConnection(tconn); | ||
| 627 | } else | ||
| 628 | code = 0; | ||
| 629 | return code; | ||
| 630 | } | ||
| 631 | |||
| 632 | /* like df. Return usage of <pname> on <server> in <partition> */ | ||
| 633 | int | ||
| 634 | UV_PartitionInfo64(afs_uint32 server, char *pname, | ||
| 635 | struct diskPartition64 *partition) | ||
| 636 | { | ||
| 637 | struct rx_connection *aconn; | ||
| 638 | afs_int32 code = 0; | ||
| 639 | |||
| 640 | aconn = (struct rx_connection *)0; | ||
| 641 | aconn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 642 | code = AFSVolPartitionInfo64(aconn, pname, partition); | ||
| 643 | if (code == RXGEN_OPCODE-455) { | ||
| 644 | struct diskPartition *dpp = | ||
| 645 | (struct diskPartition *)malloc(sizeof(struct diskPartition)); | ||
| 646 | code = AFSVolPartitionInfo(aconn, pname, dpp); | ||
| 647 | if (!code) { | ||
| 648 | strncpy(partition->name, dpp->name, 32); | ||
| 649 | strncpy(partition->devName, dpp->devName, 32); | ||
| 650 | partition->lock_fd = dpp->lock_fd; | ||
| 651 | partition->free = dpp->free; | ||
| 652 | partition->minFree = dpp->minFree; | ||
| 653 | } | ||
| 654 | free(dpp); | ||
| 655 | } | ||
| 656 | if (code) { | ||
| 657 | fprintf(STDERR__stderrp, "Could not get information on partition %s\n", pname); | ||
| 658 | PrintError("", code); | ||
| 659 | } | ||
| 660 | if (aconn) | ||
| 661 | rx_DestroyConnection(aconn); | ||
| 662 | return code; | ||
| 663 | } | ||
| 664 | |||
| 665 | /* old interface to create volumes */ | ||
| 666 | int | ||
| 667 | UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname, | ||
| 668 | afs_uint32 * anewid) | ||
| 669 | { | ||
| 670 | afs_int32 code; | ||
| 671 | *anewid = 0; | ||
| 672 | code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid); | ||
| 673 | return code; | ||
| 674 | } | ||
| 675 | |||
| 676 | /* less old interface to create volumes */ | ||
| 677 | int | ||
| 678 | UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname, | ||
| 679 | afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2, | ||
| 680 | afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid) | ||
| 681 | { | ||
| 682 | afs_uint32 roid = 0, bkid = 0; | ||
| 683 | return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2, | ||
| 684 | aspare3, aspare4, anewid, &roid, &bkid); | ||
| 685 | } | ||
| 686 | |||
| 687 | /** | ||
| 688 | * Create a volume on the given server and partition | ||
| 689 | * | ||
| 690 | * @param aserver server to create volume on | ||
| 691 | * @param spart partition to create volume on | ||
| 692 | * @param aname name of new volume | ||
| 693 | * @param aquota quota for new volume | ||
| 694 | * @param anewid contains the desired volume id for the new volume. If | ||
| 695 | * *anewid == 0, a new id will be chosen, and will be placed | ||
| 696 | * in *anewid when UV_CreateVolume3 returns. | ||
| 697 | * @param aroid contains the desired RO volume id. If NULL, the RO id entry | ||
| 698 | * will be unset. If *aroid == 0, an id will be chosen, and | ||
| 699 | * will be placed in *anewid when UV_CreateVolume3 returns. | ||
| 700 | * @param abkid same as aroid, except for the BK volume id instead of the | ||
| 701 | * RO volume id. | ||
| 702 | * @return 0 on success, error code otherwise. | ||
| 703 | */ | ||
| 704 | int | ||
| 705 | UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname, | ||
| 706 | afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2, | ||
| 707 | afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid, | ||
| 708 | afs_uint32 * aroid, afs_uint32 * abkid) | ||
| 709 | { | ||
| 710 | struct rx_connection *aconn; | ||
| 711 | afs_int32 tid; | ||
| 712 | afs_int32 code; | ||
| 713 | afs_int32 error; | ||
| 714 | afs_int32 rcode, vcode; | ||
| 715 | afs_int32 lastid; | ||
| 716 | struct nvldbentry entry, storeEntry; /*the new vldb entry */ | ||
| 717 | struct volintInfo tstatus; | ||
| 718 | |||
| 719 | tid = 0; | ||
| 720 | aconn = (struct rx_connection *)0; | ||
| 721 | error = 0; | ||
| 722 | |||
| 723 | init_volintInfo(&tstatus); | ||
| 724 | tstatus.maxquota = aquota; | ||
| 725 | |||
| 726 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 727 | |||
| 728 | if (aroid && *aroid) { | ||
| 729 | VPRINT1("Using RO volume ID %d.\n", *aroid){ if (verbose) { fprintf(__stdoutp, ("Using RO volume ID %d.\n" ), (*aroid)); fflush(__stdoutp); } }; | ||
| 730 | } | ||
| 731 | if (abkid && *abkid) { | ||
| 732 | VPRINT1("Using BK volume ID %d.\n", *abkid){ if (verbose) { fprintf(__stdoutp, ("Using BK volume ID %d.\n" ), (*abkid)); fflush(__stdoutp); } }; | ||
| 733 | } | ||
| 734 | |||
| 735 | if (*anewid) { | ||
| 736 | vcode = VLDB_GetEntryByID(*anewid, -1, &entry); | ||
| 737 | if (!vcode) { | ||
| 738 | fprintf(STDERR__stderrp, "Volume ID %d already exists\n", *anewid); | ||
| 739 | return VVOLEXISTS104; | ||
| 740 | } | ||
| 741 | VPRINT1("Using volume ID %d.\n", *anewid){ if (verbose) { fprintf(__stdoutp, ("Using volume ID %d.\n") , (*anewid)); fflush(__stdoutp); } }; | ||
| 742 | } else { | ||
| 743 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid); | ||
| 744 | EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an Id for volume %s\n")), ((aname))); PrintError (" ",(vcode)); } while (0); error = (vcode); goto cfail; } } while (0); | ||
| 745 | |||
| 746 | if (aroid && *aroid == 0) { | ||
| 747 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid); | ||
| 748 | EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an RO Id for volume %s\n")), ((aname))); PrintError (" ",(vcode)); } while (0); error = (vcode); goto cfail; } } while (0); | ||
| 749 | } | ||
| 750 | |||
| 751 | if (abkid && *abkid == 0) { | ||
| 752 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid); | ||
| 753 | EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get a BK Id for volume %s\n")), ((aname))); PrintError (" ",(vcode)); } while (0); error = (vcode); goto cfail; } } while (0); | ||
| 754 | } | ||
| 755 | } | ||
| 756 | |||
| 757 | /* rw,ro, bk id are related in the default case */ | ||
| 758 | /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */ | ||
| 759 | lastid = *anewid; | ||
| 760 | if (aroid && *aroid == 0) { | ||
| 761 | *aroid = ++lastid; | ||
| 762 | } | ||
| 763 | if (abkid && *abkid == 0) { | ||
| 764 | *abkid = ++lastid; | ||
| 765 | } | ||
| 766 | |||
| 767 | code = | ||
| 768 | AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW0, 0, anewid, &tid); | ||
| 769 | EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create the volume %s %u \n")), ((aname)), ((*anewid ))); PrintError(" ",(code)); } while (0); error = (code); goto cfail; } } while (0) | ||
| 770 | *anewid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create the volume %s %u \n")), ((aname)), ((*anewid ))); PrintError(" ",(code)); } while (0); error = (code); goto cfail; } } while (0); | ||
| 771 | |||
| 772 | code = AFSVolSetInfo(aconn, tid, &tstatus); | ||
| 773 | if (code) | ||
| 774 | EPRINT(code, "Could not change quota, continuing...\n")do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Could not change quota, continuing...\n" )); PrintError(" ",code); } while (0); | ||
| 775 | |||
| 776 | code = AFSVolSetFlags(aconn, tid, 0); /* bring it online (mark it InService */ | ||
| 777 | EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not bring the volume %s %u online \n")), ((aname)) , ((*anewid))); PrintError(" ",(code)); } while (0); error = (code); goto cfail; } } while (0) | ||
| 778 | *anewid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not bring the volume %s %u online \n")), ((aname)) , ((*anewid))); PrintError(" ",(code)); } while (0); error = (code); goto cfail; } } while (0); | ||
| 779 | |||
| 780 | VPRINT2("Volume %s %u created and brought online\n", aname, *anewid){ if (verbose) { fprintf(__stdoutp, ("Volume %s %u created and brought online\n" ), (aname), (*anewid)); fflush(__stdoutp); } }; | ||
| 781 | |||
| 782 | /* set up the vldb entry for this volume */ | ||
| 783 | strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME32); | ||
| 784 | entry.nServers = 1; | ||
| 785 | entry.serverNumber[0] = aserver; /* this should have another | ||
| 786 | * level of indirection later */ | ||
| 787 | entry.serverPartition[0] = apart; /* this should also have | ||
| 788 | * another indirection level */ | ||
| 789 | entry.flags = RW_EXISTS0x1000; /* this records that rw volume exists */ | ||
| 790 | entry.serverFlags[0] = ITSRWVOL0x04; /*this rep site has rw vol */ | ||
| 791 | entry.volumeId[RWVOL0] = *anewid; | ||
| 792 | entry.volumeId[ROVOL1] = aroid ? *aroid : 0; | ||
| 793 | entry.volumeId[BACKVOL2] = abkid ? *abkid : 0; | ||
| 794 | entry.cloneId = 0; | ||
| 795 | /*map into right byte order, before passing to xdr, the stuff has to be in host | ||
| 796 | * byte order. Xdr converts it into network order */ | ||
| 797 | MapNetworkToHost(&entry, &storeEntry); | ||
| 798 | /* create the vldb entry */ | ||
| 799 | vcode = VLDB_CreateEntry(&storeEntry); | ||
| 800 | if (vcode) { | ||
| 801 | fprintf(STDERR__stderrp, | ||
| 802 | "Could not create a VLDB entry for the volume %s %lu\n", | ||
| 803 | aname, (unsigned long)*anewid); | ||
| 804 | /*destroy the created volume */ | ||
| 805 | VPRINT1("Deleting the newly created volume %u\n", *anewid){ if (verbose) { fprintf(__stdoutp, ("Deleting the newly created volume %u\n" ), (*anewid)); fflush(__stdoutp); } }; | ||
| 806 | AFSVolDeleteVolume(aconn, tid); | ||
| 807 | error = vcode; | ||
| 808 | goto cfail; | ||
| 809 | } | ||
| 810 | VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, *anewid){ if (verbose) { fprintf(__stdoutp, ("Created the VLDB entry for the volume %s %u\n" ), (aname), (*anewid)); fflush(__stdoutp); } }; | ||
| 811 | /* volume created, now terminate the transaction and release the connection */ | ||
| 812 | code = AFSVolEndTrans(aconn, tid, &rcode); /*if it crashes before this | ||
| 813 | * the volume will come online anyway when transaction timesout , so if | ||
| 814 | * vldb entry exists then the volume is guaranteed to exist too wrt create */ | ||
| 815 | tid = 0; | ||
| 816 | if (code) { | ||
| 817 | fprintf(STDERR__stderrp, | ||
| 818 | "Failed to end the transaction on the volume %s %lu\n", aname, | ||
| 819 | (unsigned long)*anewid); | ||
| 820 | error = code; | ||
| 821 | goto cfail; | ||
| 822 | } | ||
| 823 | |||
| 824 | cfail: | ||
| 825 | if (tid) { | ||
| 826 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 827 | if (code) | ||
| 828 | fprintf(STDERR__stderrp, "WARNING: could not end transaction\n"); | ||
| 829 | } | ||
| 830 | if (aconn) | ||
| 831 | rx_DestroyConnection(aconn); | ||
| 832 | PrintError("", error); | ||
| 833 | return error; | ||
| 834 | } | ||
| 835 | |||
| 836 | /* create a volume, given a server, partition number, volume name --> sends | ||
| 837 | * back new vol id in <anewid>*/ | ||
| 838 | int | ||
| 839 | UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname, | ||
| 840 | afs_uint32 aid) | ||
| 841 | { | ||
| 842 | struct rx_connection *aconn; | ||
| 843 | afs_int32 error; | ||
| 844 | afs_int32 vcode; | ||
| 845 | struct nvldbentry entry, storeEntry; /*the new vldb entry */ | ||
| 846 | |||
| 847 | aconn = (struct rx_connection *)0; | ||
| 848 | error = 0; | ||
| 849 | |||
| 850 | /* set up the vldb entry for this volume */ | ||
| 851 | strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME32); | ||
| 852 | entry.nServers = 1; | ||
| 853 | entry.serverNumber[0] = aserver; /* this should have another | ||
| 854 | * level of indirection later */ | ||
| 855 | entry.serverPartition[0] = apart; /* this should also have | ||
| 856 | * another indirection level */ | ||
| 857 | entry.flags = RW_EXISTS0x1000; /* this records that rw volume exists */ | ||
| 858 | entry.serverFlags[0] = ITSRWVOL0x04; /*this rep site has rw vol */ | ||
| 859 | entry.volumeId[RWVOL0] = aid; | ||
| 860 | #ifdef notdef | ||
| 861 | entry.volumeId[ROVOL1] = anewid + 1; /* rw,ro, bk id are related in the default case */ | ||
| 862 | entry.volumeId[BACKVOL2] = *anewid + 2; | ||
| 863 | #else | ||
| 864 | entry.volumeId[ROVOL1] = 0; | ||
| 865 | entry.volumeId[BACKVOL2] = 0; | ||
| 866 | #endif | ||
| 867 | entry.cloneId = 0; | ||
| 868 | /*map into right byte order, before passing to xdr, the stuff has to be in host | ||
| 869 | * byte order. Xdr converts it into network order */ | ||
| 870 | MapNetworkToHost(&entry, &storeEntry); | ||
| 871 | /* create the vldb entry */ | ||
| 872 | vcode = VLDB_CreateEntry(&storeEntry); | ||
| 873 | if (vcode) { | ||
| 874 | fprintf(STDERR__stderrp, | ||
| 875 | "Could not create a VLDB entry for the volume %s %lu\n", | ||
| 876 | aname, (unsigned long)aid); | ||
| 877 | error = vcode; | ||
| 878 | goto cfail; | ||
| 879 | } | ||
| 880 | VPRINT2("Created the VLDB entry for the volume %s %u\n", aname, aid){ if (verbose) { fprintf(__stdoutp, ("Created the VLDB entry for the volume %s %u\n" ), (aname), (aid)); fflush(__stdoutp); } }; | ||
| 881 | |||
| 882 | cfail: | ||
| 883 | if (aconn) | ||
| 884 | rx_DestroyConnection(aconn); | ||
| 885 | PrintError("", error); | ||
| 886 | return error; | ||
| 887 | } | ||
| 888 | |||
| 889 | /* Delete the volume <volid>on <aserver> <apart> | ||
| 890 | * the physical entry gets removed from the vldb only if the ref count | ||
| 891 | * becomes zero | ||
| 892 | */ | ||
| 893 | int | ||
| 894 | UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid) | ||
| 895 | { | ||
| 896 | struct rx_connection *aconn = (struct rx_connection *)0; | ||
| 897 | afs_int32 ttid = 0; | ||
| 898 | afs_int32 code, rcode; | ||
| 899 | afs_int32 error = 0; | ||
| 900 | struct nvldbentry entry, storeEntry; | ||
| 901 | int islocked = 0; | ||
| 902 | afs_int32 avoltype = -1, vtype; | ||
| 903 | int notondisk = 0, notinvldb = 0; | ||
| 904 | |||
| 905 | /* Find and read bhe VLDB entry for this volume */ | ||
| 906 | code = ubik_VL_SetLock(cstruct, 0, avolid, avoltype, VLOP_DELETE0x80); | ||
| 907 | if (code) { | ||
| 908 | if (code != VL_NOENT(363524L)) { | ||
| 909 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not lock VLDB entry for the volume %u\n")), ((avolid ))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 910 | "Could not lock VLDB entry for the volume %u\n", avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not lock VLDB entry for the volume %u\n")), ((avolid ))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 911 | } | ||
| 912 | notinvldb = 1; | ||
| 913 | } else { | ||
| 914 | islocked = 1; | ||
| 915 | |||
| 916 | code = VLDB_GetEntryByID(avolid, avoltype, &entry); | ||
| 917 | EGOTO1(error_exit, code, "Could not fetch VLDB entry for volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch VLDB entry for volume %u\n")), ((avolid) )); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 918 | avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch VLDB entry for volume %u\n")), ((avolid) )); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 919 | MapHostToNetwork(&entry); | ||
| 920 | |||
| 921 | if (verbose) | ||
| 922 | EnumerateEntry(&entry); | ||
| 923 | } | ||
| 924 | |||
| 925 | /* Whether volume is in the VLDB or not. Delete the volume on disk */ | ||
| 926 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 927 | code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline1, &ttid); | ||
| 928 | if (code) { | ||
| 929 | if (code == VNOVOL103) { | ||
| 930 | notondisk = 1; | ||
| 931 | } else { | ||
| 932 | EGOTO1(error_exit, code, "Transaction on volume %u failed\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Transaction on volume %u failed\n")), ((avolid))); PrintError (" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 933 | avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Transaction on volume %u failed\n")), ((avolid))); PrintError (" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 934 | } | ||
| 935 | } else { | ||
| 936 | VPRINT1("Trying to delete the volume %u ...", avolid){ if (verbose) { fprintf(__stdoutp, ("Trying to delete the volume %u ..." ), (avolid)); fflush(__stdoutp); } }; | ||
| 937 | |||
| 938 | code = AFSVolDeleteVolume(aconn, ttid); | ||
| 939 | EGOTO1(error_exit, code, "Could not delete the volume %u \n", avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the volume %u \n")), ((avolid))); PrintError (" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 940 | |||
| 941 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 942 | code = (code ? code : rcode); | ||
| 943 | ttid = 0; | ||
| 944 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the volume %u \n")), ( (avolid))); PrintError(" ",(code)); } while (0); error = (code ); goto error_exit; } } while (0) | ||
| 945 | "Could not end the transaction for the volume %u \n", avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the volume %u \n")), ( (avolid))); PrintError(" ",(code)); } while (0); error = (code ); goto error_exit; } } while (0); | ||
| 946 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 947 | } | ||
| 948 | |||
| 949 | /* Now update the VLDB entry. | ||
| 950 | * But first, verify we have a VLDB entry. | ||
| 951 | * Whether volume is on disk or not. Delete the volume in VLDB. | ||
| 952 | */ | ||
| 953 | if (notinvldb) | ||
| 954 | ERROR_EXIT(0)do { error = (0); goto error_exit; } while (0); | ||
| 955 | |||
| 956 | if (avolid == entry.volumeId[BACKVOL2]) { | ||
| 957 | /* Its a backup volume, modify the VLDB entry. Check that the | ||
| 958 | * backup volume is on the server/partition we asked to delete. | ||
| 959 | */ | ||
| 960 | if (!(entry.flags & BACK_EXISTS0x4000) || !Lp_Match(aserver, apart, &entry)) { | ||
| 961 | notinvldb = 2; /* Not on this server and partition */ | ||
| 962 | ERROR_EXIT(0)do { error = (0); goto error_exit; } while (0); | ||
| 963 | } | ||
| 964 | |||
| 965 | VPRINT1("Marking the backup volume %u deleted in the VLDB\n", avolid){ if (verbose) { fprintf(__stdoutp, ("Marking the backup volume %u deleted in the VLDB\n" ), (avolid)); fflush(__stdoutp); } }; | ||
| 966 | |||
| 967 | entry.flags &= ~BACK_EXISTS0x4000; | ||
| 968 | vtype = BACKVOL2; | ||
| 969 | } | ||
| 970 | |||
| 971 | else if (avolid == entry.volumeId[ROVOL1]) { | ||
| 972 | /* Its a read-only volume, modify the VLDB entry. Check that the | ||
| 973 | * readonly volume is on the server/partition we asked to delete. | ||
| 974 | * If flags does not have RO_EIXSTS set, then this may mean the RO | ||
| 975 | * hasn't been released (and could exist in VLDB). | ||
| 976 | */ | ||
| 977 | if (!Lp_ROMatch(aserver, apart, &entry)) { | ||
| 978 | notinvldb = 2; /* Not found on this server and partition */ | ||
| 979 | ERROR_EXIT(0)do { error = (0); goto error_exit; } while (0); | ||
| 980 | } | ||
| 981 | |||
| 982 | if (verbose) | ||
| 983 | fprintf(STDOUT__stdoutp, | ||
| 984 | "Marking the readonly volume %lu deleted in the VLDB\n", | ||
| 985 | (unsigned long)avolid); | ||
| 986 | |||
| 987 | Lp_SetROValue(&entry, aserver, apart, 0, 0); /* delete the site */ | ||
| 988 | entry.nServers--; | ||
| 989 | if (!Lp_ROMatch(0, 0, &entry)) | ||
| 990 | entry.flags &= ~RO_EXISTS0x2000; /* This was the last ro volume */ | ||
| 991 | vtype = ROVOL1; | ||
| 992 | } | ||
| 993 | |||
| 994 | else if (avolid == entry.volumeId[RWVOL0]) { | ||
| 995 | /* It's a rw volume, delete the backup volume, modify the VLDB entry. | ||
| 996 | * Check that the readwrite volumes is on the server/partition we | ||
| 997 | * asked to delete. | ||
| 998 | */ | ||
| 999 | if (!(entry.flags & RW_EXISTS0x1000) || !Lp_Match(aserver, apart, &entry)) { | ||
| 1000 | notinvldb = 2; /* Not found on this server and partition */ | ||
| 1001 | ERROR_EXIT(0)do { error = (0); goto error_exit; } while (0); | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | /* Delete backup if it exists */ | ||
| 1005 | code = | ||
| 1006 | AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL2], apart, | ||
| 1007 | ITOffline1, &ttid); | ||
| 1008 | |||
| 1009 | if (!code) { | ||
| 1010 | if (verbose) { | ||
| 1011 | fprintf(STDOUT__stdoutp, "Trying to delete the backup volume %u ...", | ||
| 1012 | entry.volumeId[BACKVOL2]); | ||
| 1013 | fflush(STDOUT__stdoutp); | ||
| 1014 | } | ||
| 1015 | code = AFSVolDeleteVolume(aconn, ttid); | ||
| 1016 | EGOTO1(error_exit, code, "Could not delete the volume %u \n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the volume %u \n")), ((entry.volumeId[2 ]))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 1017 | entry.volumeId[BACKVOL])do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the volume %u \n")), ((entry.volumeId[2 ]))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 1018 | |||
| 1019 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 1020 | ttid = 0; | ||
| 1021 | code = (code ? code : rcode); | ||
| 1022 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the volume %u \n")), ( (entry.volumeId[2]))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 1023 | "Could not end the transaction for the volume %u \n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the volume %u \n")), ( (entry.volumeId[2]))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 1024 | entry.volumeId[BACKVOL])do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the volume %u \n")), ( (entry.volumeId[2]))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 1025 | if (verbose) | ||
| 1026 | fprintf(STDOUT__stdoutp, " done\n"); | ||
| 1027 | } | ||
| 1028 | |||
| 1029 | if (verbose) | ||
| 1030 | fprintf(STDOUT__stdoutp, | ||
| 1031 | "Marking the readwrite volume %lu%s deleted in the VLDB\n", | ||
| 1032 | (unsigned long)avolid, | ||
| 1033 | ((entry. | ||
| 1034 | flags & BACK_EXISTS0x4000) ? ", and its backup volume," : | ||
| 1035 | "")); | ||
| 1036 | |||
| 1037 | Lp_SetRWValue(&entry, aserver, apart, 0L, 0L); | ||
| 1038 | entry.nServers--; | ||
| 1039 | entry.flags &= ~(BACK_EXISTS0x4000 | RW_EXISTS0x1000); | ||
| 1040 | vtype = RWVOL0; | ||
| 1041 | |||
| 1042 | if (entry.flags & RO_EXISTS0x2000) | ||
| 1043 | fprintf(STDERR__stderrp, "WARNING: ReadOnly copy(s) may still exist\n"); | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | else { | ||
| 1047 | notinvldb = 2; /* Not found on this server and partition */ | ||
| 1048 | ERROR_EXIT(0)do { error = (0); goto error_exit; } while (0); | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | /* Either delete or replace the VLDB entry */ | ||
| 1052 | if ((entry.nServers <= 0) || !(entry.flags & (RO_EXISTS0x2000 | RW_EXISTS0x1000))) { | ||
| 1053 | if (verbose) | ||
| 1054 | fprintf(STDOUT__stdoutp, | ||
| 1055 | "Last reference to the VLDB entry for %lu - deleting entry\n", | ||
| 1056 | (unsigned long)avolid); | ||
| 1057 | code = ubik_VL_DeleteEntry(cstruct, 0, avolid, vtype); | ||
| 1058 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the VLDB entry for the volume %u \n")), ((avolid))); PrintError(" ",(code)); } while (0); error = ( code); goto error_exit; } } while (0) | ||
| 1059 | "Could not delete the VLDB entry for the volume %u \n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the VLDB entry for the volume %u \n")), ((avolid))); PrintError(" ",(code)); } while (0); error = ( code); goto error_exit; } } while (0) | ||
| 1060 | avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the VLDB entry for the volume %u \n")), ((avolid))); PrintError(" ",(code)); } while (0); error = ( code); goto error_exit; } } while (0); | ||
| 1061 | } else { | ||
| 1062 | MapNetworkToHost(&entry, &storeEntry); | ||
| 1063 | code = | ||
| 1064 | VLDB_ReplaceEntry(avolid, vtype, &storeEntry, | ||
| 1065 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 1066 | LOCKREL_TIMESTAMP1)); | ||
| 1067 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not update the VLDB entry for the volume %u \n")), ((avolid))); PrintError(" ",(code)); } while (0); error = ( code); goto error_exit; } } while (0) | ||
| 1068 | "Could not update the VLDB entry for the volume %u \n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not update the VLDB entry for the volume %u \n")), ((avolid))); PrintError(" ",(code)); } while (0); error = ( code); goto error_exit; } } while (0) | ||
| 1069 | avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not update the VLDB entry for the volume %u \n")), ((avolid))); PrintError(" ",(code)); } while (0); error = ( code); goto error_exit; } } while (0); | ||
| 1070 | } | ||
| 1071 | islocked = 0; | ||
| 1072 | |||
| 1073 | error_exit: | ||
| 1074 | if (error) | ||
| 1075 | EPRINT(error, "\n")do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("\n")); PrintError (" ",error); } while (0); | ||
| 1076 | |||
| 1077 | if (notondisk && notinvldb) { | ||
| 1078 | EPRINT2(VOLSERNOVOL, "Volume %u does not exist %s\n", avolid,do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Volume %u does not exist %s\n" ), (avolid), (((notinvldb == 2) ? "on server and partition" : ""))); PrintError(" ",(1492325135L)); } while (0) | ||
| 1079 | ((notinvldb == 2) ? "on server and partition" : ""))do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Volume %u does not exist %s\n" ), (avolid), (((notinvldb == 2) ? "on server and partition" : ""))); PrintError(" ",(1492325135L)); } while (0); | ||
| 1080 | if (!error) | ||
| 1081 | error = VOLSERNOVOL(1492325135L); | ||
| 1082 | } else if (notondisk) { | ||
| 1083 | fprintf(STDERR__stderrp, | ||
| 1084 | "WARNING: Volume %lu did not exist on the partition\n", | ||
| 1085 | (unsigned long)avolid); | ||
| 1086 | } else if (notinvldb) { | ||
| 1087 | fprintf(STDERR__stderrp, "WARNING: Volume %lu does not exist in VLDB %s\n", | ||
| 1088 | (unsigned long)avolid, | ||
| 1089 | ((notinvldb == 2) ? "on server and partition" : "")); | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | if (ttid) { | ||
| 1093 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 1094 | code = (code ? code : rcode); | ||
| 1095 | if (code) { | ||
| 1096 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %lu\n", | ||
| 1097 | (unsigned long)avolid); | ||
| 1098 | PrintError("", code); | ||
| 1099 | if (!error) | ||
| 1100 | error = code; | ||
| 1101 | } | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | if (islocked) { | ||
| 1105 | code = | ||
| 1106 | ubik_VL_ReleaseLock(cstruct, 0, avolid, -1, | ||
| 1107 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 1108 | LOCKREL_TIMESTAMP1)); | ||
| 1109 | if (code) { | ||
| 1110 | EPRINT1(code,do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Could not release the lock on the VLDB entry for the volume %u \n" ), (avolid)); PrintError(" ",code); } while (0) | ||
| 1111 | "Could not release the lock on the VLDB entry for the volume %u \n",do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Could not release the lock on the VLDB entry for the volume %u \n" ), (avolid)); PrintError(" ",code); } while (0) | ||
| 1112 | avolid)do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Could not release the lock on the VLDB entry for the volume %u \n" ), (avolid)); PrintError(" ",code); } while (0); | ||
| 1113 | if (!error) | ||
| 1114 | error = code; | ||
| 1115 | } | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | if (aconn) | ||
| 1119 | rx_DestroyConnection(aconn); | ||
| 1120 | return error; | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | /* add recovery to UV_MoveVolume */ | ||
| 1124 | |||
| 1125 | #define TESTC0 0 /* set to test recovery code, clear for production */ | ||
| 1126 | |||
| 1127 | jmp_buf env; | ||
| 1128 | int interrupt = 0; | ||
| 1129 | |||
| 1130 | static void * | ||
| 1131 | do_interrupt(void * unused) | ||
| 1132 | { | ||
| 1133 | if (interrupt) { | ||
| 1134 | #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV) | ||
| 1135 | /* Avoid UNIX LWP from getting confused that our stack has suddenly | ||
| 1136 | * changed. This will avoid some sanity checks, but until a better way | ||
| 1137 | * is found, the only alternative is always crashing and burning on at | ||
| 1138 | * least the stack-overflow check. */ | ||
| 1139 | lwp_cpptr->stack = NULL((void *)0); | ||
| 1140 | #endif | ||
| 1141 | longjmp(env, 0); | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | fprintf(STDOUT__stdoutp, "\nSIGINT handler: vos move operation in progress\n"); | ||
| 1145 | fprintf(STDOUT__stdoutp, | ||
| 1146 | "WARNING: may leave AFS storage and metadata in indeterminate state\n"); | ||
| 1147 | fprintf(STDOUT__stdoutp, "enter second control-c to exit\n"); | ||
| 1148 | fflush(STDOUT__stdoutp); | ||
| 1149 | |||
| 1150 | interrupt = 1; | ||
| 1151 | return NULL((void *)0); | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | static void | ||
| 1155 | sigint_handler(int x) | ||
| 1156 | { | ||
| 1157 | #ifdef AFS_PTHREAD_ENV | ||
| 1158 | do_interrupt(NULL((void *)0)); | ||
| 1159 | #else | ||
| 1160 | IOMGR_SoftSig(do_interrupt, 0); | ||
| 1161 | #endif | ||
| 1162 | (void)signal(SIGINT2, sigint_handler); | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver> | ||
| 1166 | * <atopart>. The operation is almost idempotent. The following | ||
| 1167 | * flags are recognized: | ||
| 1168 | * | ||
| 1169 | * RV_NOCLONE - don't use a copy clone | ||
| 1170 | */ | ||
| 1171 | |||
| 1172 | int | ||
| 1173 | UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart, | ||
| 1174 | afs_uint32 atoserver, afs_int32 atopart, int flags) | ||
| 1175 | { | ||
| 1176 | /* declare stuff 'volatile' that may be used from setjmp/longjmp and may | ||
| 1177 | * be changing during the move */ | ||
| 1178 | struct rx_connection * volatile toconn; | ||
| 1179 | struct rx_connection * volatile fromconn; | ||
| 1180 | afs_int32 volatile fromtid; | ||
| 1181 | afs_int32 volatile totid; | ||
| 1182 | afs_int32 volatile clonetid; | ||
| 1183 | afs_uint32 volatile newVol; | ||
| 1184 | afs_uint32 volatile volid; | ||
| 1185 | afs_uint32 volatile backupId; | ||
| 1186 | int volatile islocked; | ||
| 1187 | int volatile pntg; | ||
| 1188 | |||
| 1189 | char vname[64]; | ||
| 1190 | char *volName = 0; | ||
| 1191 | char tmpName[VOLSER_MAXVOLNAME65 + 1]; | ||
| 1192 | afs_int32 rcode; | ||
| 1193 | afs_int32 fromDate; | ||
| 1194 | afs_int32 tmp; | ||
| 1195 | afs_uint32 tmpVol; | ||
| 1196 | struct restoreCookie cookie; | ||
| 1197 | afs_int32 vcode, code; | ||
| 1198 | struct volser_status tstatus; | ||
| 1199 | struct destServer destination; | ||
| 1200 | |||
| 1201 | struct nvldbentry entry, storeEntry; | ||
| 1202 | int i; | ||
| 1203 | afs_int32 error; | ||
| 1204 | char in, lf; /* for test code */ | ||
| 1205 | int same; | ||
| 1206 | char hoststr[16]; | ||
| 1207 | |||
| 1208 | #ifdef ENABLE_BUGFIX_1165 | ||
| 1209 | volEntries volumeInfo; | ||
| 1210 | struct volintInfo *infop = 0; | ||
| 1211 | #endif | ||
| 1212 | |||
| 1213 | islocked = 0; | ||
| 1214 | fromconn = (struct rx_connection *)0; | ||
| 1215 | toconn = (struct rx_connection *)0; | ||
| 1216 | fromtid = 0; | ||
| 1217 | totid = 0; | ||
| 1218 | clonetid = 0; | ||
| 1219 | error = 0; | ||
| 1220 | volid = 0; | ||
| 1221 | pntg = 0; | ||
| 1222 | backupId = 0; | ||
| 1223 | newVol = 0; | ||
| 1224 | |||
| 1225 | /* support control-c processing */ | ||
| 1226 | if (setjmp(env)) | ||
| 1227 | goto mfail; | ||
| 1228 | (void)signal(SIGINT2, sigint_handler); | ||
| 1229 | |||
| 1230 | if (TESTC0) { | ||
| 1231 | fprintf(STDOUT__stdoutp, | ||
| 1232 | "\nThere are three tests points - verifies all code paths through recovery.\n"); | ||
| 1233 | fprintf(STDOUT__stdoutp, "First test point - operation not started.\n"); | ||
| 1234 | fprintf(STDOUT__stdoutp, "...test here (y, n)? "); | ||
| 1235 | fflush(STDOUT__stdoutp); | ||
| 1236 | fscanf(stdin__stdinp, "%c", &in); | ||
| 1237 | fscanf(stdin__stdinp, "%c", &lf); /* toss away */ | ||
| 1238 | if (in == 'y') { | ||
| 1239 | fprintf(STDOUT__stdoutp, "type control-c\n"); | ||
| 1240 | while (1) { | ||
| 1241 | fprintf(stdout__stdoutp, "."); | ||
| 1242 | fflush(stdout__stdoutp); | ||
| 1243 | sleep(1); | ||
| 1244 | } | ||
| 1245 | } | ||
| 1246 | /* or drop through */ | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | vcode = VLDB_GetEntryByID(afromvol, -1, &entry); | ||
| 1250 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1251 | "Could not fetch the entry for the volume %u from the VLDB \n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1252 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 1253 | |||
| 1254 | if (entry.volumeId[RWVOL0] != afromvol) { | ||
| 1255 | fprintf(STDERR__stderrp, "Only RW volume can be moved\n"); | ||
| 1256 | exit(1); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL0, VLOP_MOVE0x10); | ||
| 1260 | EGOTO1(mfail, vcode, "Could not lock entry for volume %u \n", afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not lock entry for volume %u \n")), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 1261 | islocked = 1; | ||
| 1262 | |||
| 1263 | vcode = VLDB_GetEntryByID(afromvol, RWVOL0, &entry); | ||
| 1264 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1265 | "Could not fetch the entry for the volume %u from the VLDB \n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1266 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 1267 | |||
| 1268 | backupId = entry.volumeId[BACKVOL2]; | ||
| 1269 | MapHostToNetwork(&entry); | ||
| 1270 | |||
| 1271 | if (!Lp_Match(afromserver, afrompart, &entry)) { | ||
| 1272 | /* the from server and partition do not exist in the vldb entry corresponding to volid */ | ||
| 1273 | if (!Lp_Match(atoserver, atopart, &entry)) { | ||
| 1274 | /* the to server and partition do not exist in the vldb entry corresponding to volid */ | ||
| 1275 | fprintf(STDERR__stderrp, "The volume %lu is not on the specified site. \n", | ||
| 1276 | (unsigned long)afromvol); | ||
| 1277 | fprintf(STDERR__stderrp, "The current site is :"); | ||
| 1278 | for (i = 0; i < entry.nServers; i++) { | ||
| 1279 | if (entry.serverFlags[i] == ITSRWVOL0x04) { | ||
| 1280 | char pname[10]; | ||
| 1281 | MapPartIdIntoName(entry.serverPartition[i], pname); | ||
| 1282 | fprintf(STDERR__stderrp, " server %s partition %s \n", | ||
| 1283 | noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) : | ||
| 1284 | hostutil_GetNameByINet(entry.serverNumber[i]), | ||
| 1285 | pname); | ||
| 1286 | } | ||
| 1287 | } | ||
| 1288 | vcode = | ||
| 1289 | ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1, | ||
| 1290 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 1291 | LOCKREL_TIMESTAMP1)); | ||
| 1292 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((" Could not release lock on the VLDB entry for the volume %u \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1293 | " Could not release lock on the VLDB entry for the volume %u \n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((" Could not release lock on the VLDB entry for the volume %u \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1294 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , ((" Could not release lock on the VLDB entry for the volume %u \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 1295 | |||
| 1296 | return VOLSERVOLMOVED(1492325130L); | ||
| 1297 | } | ||
| 1298 | |||
| 1299 | /* delete the volume afromvol on src_server */ | ||
| 1300 | /* from-info does not exist but to-info does => | ||
| 1301 | * we have already done the move, but the volume | ||
| 1302 | * may still be existing physically on from fileserver | ||
| 1303 | */ | ||
| 1304 | fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 1305 | fromtid = 0; | ||
| 1306 | pntg = 1; | ||
| 1307 | |||
| 1308 | tmp = fromtid; | ||
| 1309 | code = | ||
| 1310 | AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline1, | ||
| 1311 | &tmp); | ||
| 1312 | fromtid = tmp; | ||
| 1313 | |||
| 1314 | if (!code) { /* volume exists - delete it */ | ||
| 1315 | VPRINT1("Setting flags on leftover source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Setting flags on leftover source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 1316 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Setting flags on leftover source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1317 | code = | ||
| 1318 | AFSVolSetFlags(fromconn, fromtid, | ||
| 1319 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 1320 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set flags on the leftover source volume %u\n") ), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1321 | "Failed to set flags on the leftover source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set flags on the leftover source volume %u\n") ), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1322 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set flags on the leftover source volume %u\n") ), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1323 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1324 | |||
| 1325 | VPRINT1("Deleting leftover source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Deleting leftover source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1326 | code = AFSVolDeleteVolume(fromconn, fromtid); | ||
| 1327 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the leftover source volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1328 | "Failed to delete the leftover source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the leftover source volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1329 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the leftover source volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1330 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1331 | |||
| 1332 | VPRINT1("Ending transaction on leftover source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on leftover source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 1333 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on leftover source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1334 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1335 | fromtid = 0; | ||
| 1336 | if (!code) | ||
| 1337 | code = rcode; | ||
| 1338 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the leftover source volume %u \n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1339 | "Could not end the transaction for the leftover source volume %u \n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the leftover source volume %u \n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1340 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the leftover source volume %u \n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1341 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1342 | } | ||
| 1343 | |||
| 1344 | /*delete the backup volume now */ | ||
| 1345 | fromtid = 0; | ||
| 1346 | code = | ||
| 1347 | AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline1, | ||
| 1348 | &tmp); | ||
| 1349 | fromtid = tmp; | ||
| 1350 | |||
| 1351 | if (!code) { /* backup volume exists - delete it */ | ||
| 1352 | VPRINT1("Setting flags on leftover backup volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Setting flags on leftover backup volume %u ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 1353 | backupId){ if (verbose) { fprintf(__stdoutp, ("Setting flags on leftover backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1354 | code = | ||
| 1355 | AFSVolSetFlags(fromconn, fromtid, | ||
| 1356 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 1357 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set flags on the backup volume %u\n")), ((backupId ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1358 | "Failed to set flags on the backup volume %u\n", backupId)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set flags on the backup volume %u\n")), ((backupId ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1359 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1360 | |||
| 1361 | VPRINT1("Deleting leftover backup volume %u ...", backupId){ if (verbose) { fprintf(__stdoutp, ("Deleting leftover backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1362 | code = AFSVolDeleteVolume(fromconn, fromtid); | ||
| 1363 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the leftover backup volume %u\n")), ((backupId ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1364 | "Could not delete the leftover backup volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the leftover backup volume %u\n")), ((backupId ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1365 | backupId)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the leftover backup volume %u\n")), ((backupId ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1366 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1367 | |||
| 1368 | VPRINT1("Ending transaction on leftover backup volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on leftover backup volume %u ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 1369 | backupId){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on leftover backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1370 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1371 | fromtid = 0; | ||
| 1372 | if (!code) | ||
| 1373 | code = rcode; | ||
| 1374 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the leftover backup volume %u\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1375 | "Could not end the transaction for the leftover backup volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the leftover backup volume %u\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1376 | backupId)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction for the leftover backup volume %u\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1377 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | fromtid = 0; | ||
| 1381 | error = 0; | ||
| 1382 | goto mfail; | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | /* From-info matches the vldb info about volid, | ||
| 1386 | * its ok start the move operation, the backup volume | ||
| 1387 | * on the old site is deleted in the process | ||
| 1388 | */ | ||
| 1389 | if (afrompart == atopart) { | ||
| 1390 | same = VLDB_IsSameAddrs(afromserver, atoserver, &error); | ||
| 1391 | EGOTO2(mfail, error,do { if (error) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n" )), ((afromserver)), ((error))); PrintError(" ",(error)); } while (0); error = (error); goto mfail; } } while (0) | ||
| 1392 | "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",do { if (error) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n" )), ((afromserver)), ((error))); PrintError(" ",(error)); } while (0); error = (error); goto mfail; } } while (0) | ||
| 1393 | afromserver, error)do { if (error) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n" )), ((afromserver)), ((error))); PrintError(" ",(error)); } while (0); error = (error); goto mfail; } } while (0); | ||
| 1394 | |||
| 1395 | if (same) { | ||
| 1396 | EGOTO1(mfail, VOLSERVOLMOVED,do { if ((1492325130L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("Warning: Moving volume %u to its home partition ignored!\n" )), ((afromvol))); PrintError(" ",((1492325130L))); } while (0); error = ((1492325130L)); goto mfail; } } while (0) | ||
| 1397 | "Warning: Moving volume %u to its home partition ignored!\n",do { if ((1492325130L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("Warning: Moving volume %u to its home partition ignored!\n" )), ((afromvol))); PrintError(" ",((1492325130L))); } while (0); error = ((1492325130L)); goto mfail; } } while (0) | ||
| 1398 | afromvol)do { if ((1492325130L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("Warning: Moving volume %u to its home partition ignored!\n" )), ((afromvol))); PrintError(" ",((1492325130L))); } while (0); error = ((1492325130L)); goto mfail; } } while (0); | ||
| 1399 | } | ||
| 1400 | } | ||
| 1401 | |||
| 1402 | pntg = 1; | ||
| 1403 | toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT7005); /* get connections to the servers */ | ||
| 1404 | fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 1405 | fromtid = totid = 0; /* initialize to uncreated */ | ||
| 1406 | |||
| 1407 | /* *** | ||
| 1408 | * clone the read/write volume locally. | ||
| 1409 | * ***/ | ||
| 1410 | |||
| 1411 | VPRINT1("Starting transaction on source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1412 | code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, &tmp); | ||
| 1413 | fromtid = tmp; | ||
| 1414 | EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create transaction on the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1415 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create transaction on the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1416 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1417 | |||
| 1418 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 1419 | /* Get a clone id */ | ||
| 1420 | VPRINT1("Allocating new volume id for clone of volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for clone of volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 1421 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for clone of volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1422 | newVol = tmpVol = 0; | ||
| 1423 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol); | ||
| 1424 | newVol = tmpVol; | ||
| 1425 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1426 | "Could not get an ID for the clone of volume %u from the VLDB\n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 1427 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 1428 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1429 | |||
| 1430 | /* Do the clone. Default flags on clone are set to delete on salvage and out of service */ | ||
| 1431 | VPRINT1("Cloning source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Cloning source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1432 | strcpy(vname, "move-clone-temp"); | ||
| 1433 | code = | ||
| 1434 | AFSVolClone(fromconn, fromtid, 0, readonlyVolume1, vname, &tmpVol); | ||
| 1435 | newVol = tmpVol; | ||
| 1436 | EGOTO1(mfail, code, "Failed to clone the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to clone the source volume %u\n")), ((afromvol))) ; PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1437 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to clone the source volume %u\n")), ((afromvol))) ; PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1438 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1439 | } | ||
| 1440 | |||
| 1441 | /* lookup the name of the volume we just cloned */ | ||
| 1442 | volid = afromvol; | ||
| 1443 | code = AFSVolGetName(fromconn, fromtid, &volName); | ||
| 1444 | EGOTO1(mfail, code, "Failed to get the name of the volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the name of the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1445 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the name of the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1446 | |||
| 1447 | VPRINT1("Ending the transaction on the source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending the transaction on the source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1448 | rcode = 0; | ||
| 1449 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1450 | fromtid = 0; | ||
| 1451 | if (!code) | ||
| 1452 | code = rcode; | ||
| 1453 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1454 | "Failed to end the transaction on the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1455 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1456 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1457 | |||
| 1458 | /* *** | ||
| 1459 | * Create the destination volume | ||
| 1460 | * ***/ | ||
| 1461 | |||
| 1462 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 1463 | /* All of this is to get the fromDate */ | ||
| 1464 | VPRINT1("Starting transaction on the cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on the cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1465 | tmp = clonetid; | ||
| 1466 | code = | ||
| 1467 | AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline1, | ||
| 1468 | &tmp); | ||
| 1469 | clonetid = tmp; | ||
| 1470 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1471 | "Failed to start a transaction on the cloned volume%u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1472 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1473 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1474 | |||
| 1475 | VPRINT1("Setting flags on cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Setting flags on cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1476 | code = | ||
| 1477 | AFSVolSetFlags(fromconn, clonetid, | ||
| 1478 | VTDeleteOnSalvage1 | VTOutOfService2); /*redundant */ | ||
| 1479 | EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set flags on the cloned volume %u\n")), ((newVol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1480 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set flags on the cloned volume %u\n")), ((newVol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1481 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1482 | |||
| 1483 | /* remember time from which we've dumped the volume */ | ||
| 1484 | VPRINT1("Getting status of cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Getting status of cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1485 | code = AFSVolGetStatus(fromconn, clonetid, &tstatus); | ||
| 1486 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the cloned volume %u\n")), ( (newVol))); PrintError(" ",(code)); } while (0); error = (code ); goto mfail; } } while (0) | ||
| 1487 | "Failed to get the status of the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the cloned volume %u\n")), ( (newVol))); PrintError(" ",(code)); } while (0); error = (code ); goto mfail; } } while (0) | ||
| 1488 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the cloned volume %u\n")), ( (newVol))); PrintError(" ",(code)); } while (0); error = (code ); goto mfail; } } while (0); | ||
| 1489 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1490 | |||
| 1491 | fromDate = CLOCKADJ(tstatus.creationDate)(((tstatus.creationDate) < 2) ? 0 : (tstatus.creationDate) - 2); | ||
| 1492 | } else { | ||
| 1493 | /* With RV_NOCLONE, just do a full copy from the source */ | ||
| 1494 | fromDate = 0; | ||
| 1495 | } | ||
| 1496 | |||
| 1497 | |||
| 1498 | #ifdef ENABLE_BUGFIX_1165 | ||
| 1499 | /* | ||
| 1500 | * Get the internal volume state from the source volume. We'll use such info (i.e. dayUse) | ||
| 1501 | * to copy it to the new volume (via AFSSetInfo later on) so that when we move volumes we | ||
| 1502 | * don't use this information... | ||
| 1503 | */ | ||
| 1504 | volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */ | ||
| 1505 | volumeInfo.volEntries_len = 0; | ||
| 1506 | code = AFSVolListOneVolume(fromconn, afrompart, afromvol, &volumeInfo); | ||
| 1507 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the volint Info of the cloned volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1508 | "Failed to get the volint Info of the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the volint Info of the cloned volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1509 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the volint Info of the cloned volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1510 | |||
| 1511 | infop = (volintInfo *) volumeInfo.volEntries_val; | ||
| 1512 | infop->maxquota = -1; /* Else it will replace the default quota */ | ||
| 1513 | infop->creationDate = -1; /* Else it will use the source creation date */ | ||
| 1514 | infop->updateDate = -1; /* Else it will use the source update date */ | ||
| 1515 | #endif | ||
| 1516 | |||
| 1517 | /* create a volume on the target machine */ | ||
| 1518 | volid = afromvol; | ||
| 1519 | tmp = totid; | ||
| 1520 | code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline1, &tmp); | ||
| 1521 | totid = tmp; | ||
| 1522 | if (!code) { | ||
| 1523 | /* Delete the existing volume. | ||
| 1524 | * While we are deleting the volume in these steps, the transaction | ||
| 1525 | * we started against the cloned volume (clonetid above) will be | ||
| 1526 | * sitting idle. It will get cleaned up after 600 seconds | ||
| 1527 | */ | ||
| 1528 | VPRINT1("Deleting pre-existing volume %u on destination ...", volid){ if (verbose) { fprintf(__stdoutp, ("Deleting pre-existing volume %u on destination ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 1529 | code = AFSVolDeleteVolume(toconn, totid); | ||
| 1530 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the pre-existing volume %u on destination\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1531 | "Could not delete the pre-existing volume %u on destination\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the pre-existing volume %u on destination\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1532 | volid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the pre-existing volume %u on destination\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1533 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1534 | |||
| 1535 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on pre-existing volume %u on destination ..." ), (volid)); fflush(__stdoutp); } } | ||
| 1536 | ("Ending transaction on pre-existing volume %u on destination ...",{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on pre-existing volume %u on destination ..." ), (volid)); fflush(__stdoutp); } } | ||
| 1537 | volid){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on pre-existing volume %u on destination ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 1538 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 1539 | totid = 0; | ||
| 1540 | if (!code) | ||
| 1541 | code = rcode; | ||
| 1542 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction on pre-existing volume %u on destination\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1543 | "Could not end the transaction on pre-existing volume %u on destination\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction on pre-existing volume %u on destination\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1544 | volid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction on pre-existing volume %u on destination\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1545 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1546 | } | ||
| 1547 | |||
| 1548 | VPRINT1("Creating the destination volume %u ...", volid){ if (verbose) { fprintf(__stdoutp, ("Creating the destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 1549 | tmp = totid; | ||
| 1550 | tmpVol = volid; | ||
| 1551 | code = | ||
| 1552 | AFSVolCreateVolume(toconn, atopart, volName, volser_RW0, volid, &tmpVol, | ||
| 1553 | &tmp); | ||
| 1554 | totid = tmp; | ||
| 1555 | volid = tmpVol; | ||
| 1556 | EGOTO1(mfail, code, "Failed to create the destination volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create the destination volume %u\n")), ((volid ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1557 | volid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create the destination volume %u\n")), ((volid ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1558 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1559 | |||
| 1560 | strncpy(tmpName, volName, VOLSER_OLDMAXVOLNAME32); | ||
| 1561 | free(volName); | ||
| 1562 | volName = NULL((void *)0); | ||
| 1563 | |||
| 1564 | VPRINT1("Setting volume flags on destination volume %u ...", volid){ if (verbose) { fprintf(__stdoutp, ("Setting volume flags on destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 1565 | code = | ||
| 1566 | AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage1 | VTOutOfService2)); | ||
| 1567 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the destination volume %u\n") ), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1568 | "Failed to set the flags on the destination volume %u\n", volid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the destination volume %u\n") ), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1569 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1570 | |||
| 1571 | /*** | ||
| 1572 | * Now dump the clone to the new volume | ||
| 1573 | ***/ | ||
| 1574 | |||
| 1575 | destination.destHost = ntohl(atoserver)(__builtin_constant_p(atoserver) ? ((((__uint32_t)(atoserver) ) >> 24) | ((((__uint32_t)(atoserver)) & (0xff << 16)) >> 8) | ((((__uint32_t)(atoserver)) & (0xff << 8)) << 8) | (((__uint32_t)(atoserver)) << 24)) : __bswap32_var(atoserver)); | ||
| 1576 | destination.destPort = AFSCONF_VOLUMEPORT7005; | ||
| 1577 | destination.destSSID = 1; | ||
| 1578 | |||
| 1579 | strncpy(cookie.name, tmpName, VOLSER_OLDMAXVOLNAME32); | ||
| 1580 | cookie.type = RWVOL0; | ||
| 1581 | cookie.parent = entry.volumeId[RWVOL0]; | ||
| 1582 | cookie.clone = 0; | ||
| 1583 | |||
| 1584 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 1585 | /* Copy the clone to the new volume */ | ||
| 1586 | VPRINT2("Dumping from clone %u on source to volume %u on destination ...",{ if (verbose) { fprintf(__stdoutp, ("Dumping from clone %u on source to volume %u on destination ..." ), (newVol), (afromvol)); fflush(__stdoutp); } } | ||
| 1587 | newVol, afromvol){ if (verbose) { fprintf(__stdoutp, ("Dumping from clone %u on source to volume %u on destination ..." ), (newVol), (afromvol)); fflush(__stdoutp); } }; | ||
| 1588 | code = | ||
| 1589 | AFSVolForward(fromconn, clonetid, 0, &destination, totid, | ||
| 1590 | &cookie); | ||
| 1591 | EGOTO1(mfail, code, "Failed to move data for the volume %u\n", volid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to move data for the volume %u\n")), ((volid))); PrintError (" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1592 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1593 | |||
| 1594 | VPRINT1("Ending transaction on cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1595 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 1596 | if (!code) | ||
| 1597 | code = rcode; | ||
| 1598 | clonetid = 0; | ||
| 1599 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1600 | "Failed to end the transaction on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1601 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1602 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1603 | } | ||
| 1604 | |||
| 1605 | /* *** | ||
| 1606 | * reattach to the main-line volume, and incrementally dump it. | ||
| 1607 | * ***/ | ||
| 1608 | |||
| 1609 | VPRINT1("Starting transaction on source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1610 | tmp = fromtid; | ||
| 1611 | code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, &tmp); | ||
| 1612 | fromtid = tmp; | ||
| 1613 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create a transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1614 | "Failed to create a transaction on the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create a transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1615 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create a transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1616 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1617 | |||
| 1618 | /* now do the incremental */ | ||
| 1619 | VPRINT2{ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } } | ||
| 1620 | ("Doing the%s dump from source to destination for volume %u ... ",{ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } } | ||
| 1621 | (flags & RV_NOCLONE) ? "" : " incremental",{ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } } | ||
| 1622 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } }; | ||
| 1623 | code = | ||
| 1624 | AFSVolForward(fromconn, fromtid, fromDate, &destination, totid, | ||
| 1625 | &cookie); | ||
| 1626 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to do the%s dump from rw volume on old site to rw volume on newsite\n" )), (((flags & 0x080000) ? "" : " incremental"))); PrintError (" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1627 | "Failed to do the%s dump from rw volume on old site to rw volume on newsite\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to do the%s dump from rw volume on old site to rw volume on newsite\n" )), (((flags & 0x080000) ? "" : " incremental"))); PrintError (" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1628 | (flags & RV_NOCLONE) ? "" : " incremental")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to do the%s dump from rw volume on old site to rw volume on newsite\n" )), (((flags & 0x080000) ? "" : " incremental"))); PrintError (" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1629 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1630 | |||
| 1631 | /* now adjust the flags so that the new volume becomes official */ | ||
| 1632 | VPRINT1("Setting volume flags on old source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Setting volume flags on old source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1633 | code = AFSVolSetFlags(fromconn, fromtid, VTOutOfService2); | ||
| 1634 | EGOTO(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags to make old source volume offline\n" ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1635 | "Failed to set the flags to make old source volume offline\n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags to make old source volume offline\n" ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1636 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1637 | |||
| 1638 | VPRINT1("Setting volume flags on new source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Setting volume flags on new source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1639 | code = AFSVolSetFlags(toconn, totid, 0); | ||
| 1640 | EGOTO(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags to make new source volume online\n" ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1641 | "Failed to set the flags to make new source volume online\n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags to make new source volume online\n" ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1642 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1643 | |||
| 1644 | #ifdef ENABLE_BUGFIX_1165 | ||
| 1645 | VPRINT1("Setting volume status on destination volume %u ...", volid){ if (verbose) { fprintf(__stdoutp, ("Setting volume status on destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 1646 | code = AFSVolSetInfo(toconn, totid, infop); | ||
| 1647 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set volume status on the destination volume %u\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1648 | "Failed to set volume status on the destination volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set volume status on the destination volume %u\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1649 | volid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set volume status on the destination volume %u\n" )), ((volid))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1650 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1651 | #endif | ||
| 1652 | |||
| 1653 | /* put new volume online */ | ||
| 1654 | VPRINT1("Ending transaction on destination volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on destination volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1655 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 1656 | totid = 0; | ||
| 1657 | if (!code) | ||
| 1658 | code = rcode; | ||
| 1659 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the volume %u on the new site\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1660 | "Failed to end the transaction on the volume %u on the new site\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the volume %u on the new site\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1661 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the volume %u on the new site\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1662 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1663 | |||
| 1664 | Lp_SetRWValue(&entry, afromserver, afrompart, atoserver, atopart); | ||
| 1665 | MapNetworkToHost(&entry, &storeEntry); | ||
| 1666 | storeEntry.flags &= ~BACK_EXISTS0x4000; | ||
| 1667 | |||
| 1668 | if (TESTC0) { | ||
| 1669 | fprintf(STDOUT__stdoutp, | ||
| 1670 | "Second test point - operation in progress but not complete.\n"); | ||
| 1671 | fprintf(STDOUT__stdoutp, "...test here (y, n)? "); | ||
| 1672 | fflush(STDOUT__stdoutp); | ||
| 1673 | fscanf(stdin__stdinp, "%c", &in); | ||
| 1674 | fscanf(stdin__stdinp, "%c", &lf); /* toss away */ | ||
| 1675 | if (in == 'y') { | ||
| 1676 | fprintf(STDOUT__stdoutp, "type control-c\n"); | ||
| 1677 | while (1) { | ||
| 1678 | fprintf(stdout__stdoutp, "."); | ||
| 1679 | fflush(stdout__stdoutp); | ||
| 1680 | sleep(1); | ||
| 1681 | } | ||
| 1682 | } | ||
| 1683 | /* or drop through */ | ||
| 1684 | } | ||
| 1685 | |||
| 1686 | VPRINT1("Releasing lock on VLDB entry for volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Releasing lock on VLDB entry for volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1687 | vcode = | ||
| 1688 | VLDB_ReplaceEntry(afromvol, -1, &storeEntry, | ||
| 1689 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 1690 | LOCKREL_TIMESTAMP1)); | ||
| 1691 | if (vcode) { | ||
| 1692 | fprintf(STDERR__stderrp, | ||
| 1693 | " Could not release the lock on the VLDB entry for the volume %s %lu \n", | ||
| 1694 | storeEntry.name, (unsigned long)afromvol); | ||
| 1695 | error = vcode; | ||
| 1696 | goto mfail; | ||
| 1697 | } | ||
| 1698 | islocked = 0; | ||
| 1699 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1700 | |||
| 1701 | if (TESTC0) { | ||
| 1702 | fprintf(STDOUT__stdoutp, | ||
| 1703 | "Third test point - operation complete but no cleanup.\n"); | ||
| 1704 | fprintf(STDOUT__stdoutp, "...test here (y, n)? "); | ||
| 1705 | fflush(STDOUT__stdoutp); | ||
| 1706 | fscanf(stdin__stdinp, "%c", &in); | ||
| 1707 | fscanf(stdin__stdinp, "%c", &lf); /* toss away */ | ||
| 1708 | if (in == 'y') { | ||
| 1709 | fprintf(STDOUT__stdoutp, "type control-c\n"); | ||
| 1710 | while (1) { | ||
| 1711 | fprintf(stdout__stdoutp, "."); | ||
| 1712 | fflush(stdout__stdoutp); | ||
| 1713 | sleep(1); | ||
| 1714 | } | ||
| 1715 | } | ||
| 1716 | /* or drop through */ | ||
| 1717 | } | ||
| 1718 | #ifdef notdef | ||
| 1719 | /* This is tricky. File server is very stupid, and if you mark the volume | ||
| 1720 | * as VTOutOfService, it may mark the *good* instance (if you're moving | ||
| 1721 | * between partitions on the same machine) as out of service. Since | ||
| 1722 | * we're cleaning this code up in DEcorum, we're just going to kludge around | ||
| 1723 | * it for now by removing this call. */ | ||
| 1724 | /* already out of service, just zap it now */ | ||
| 1725 | code = | ||
| 1726 | AFSVolSetFlags(fromconn, fromtid, VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 1727 | if (code) { | ||
| 1728 | fprintf(STDERR__stderrp, | ||
| 1729 | "Failed to set the flags to make the old source volume offline\n"); | ||
| 1730 | goto mfail; | ||
| 1731 | } | ||
| 1732 | #endif | ||
| 1733 | if (atoserver != afromserver) { | ||
| 1734 | /* set forwarding pointer for moved volumes */ | ||
| 1735 | VPRINT1("Setting forwarding pointer for volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Setting forwarding pointer for volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1736 | code = AFSVolSetForwarding(fromconn, fromtid, atoserver); | ||
| 1737 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the forwarding pointer for the volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1738 | "Failed to set the forwarding pointer for the volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the forwarding pointer for the volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1739 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the forwarding pointer for the volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1740 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1741 | } | ||
| 1742 | |||
| 1743 | VPRINT1("Deleting old volume %u on source ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Deleting old volume %u on source ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1744 | code = AFSVolDeleteVolume(fromconn, fromtid); /* zap original volume */ | ||
| 1745 | EGOTO1(mfail, code, "Failed to delete the old volume %u on source\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the old volume %u on source\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1746 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the old volume %u on source\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1747 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1748 | |||
| 1749 | VPRINT1("Ending transaction on old volume %u on the source ...",{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on old volume %u on the source ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 1750 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on old volume %u on the source ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1751 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1752 | fromtid = 0; | ||
| 1753 | if (!code) | ||
| 1754 | code = rcode; | ||
| 1755 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the old volume %u on the source\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1756 | "Failed to end the transaction on the old volume %u on the source\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the old volume %u on the source\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1757 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the old volume %u on the source\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1758 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1759 | |||
| 1760 | /* Delete the backup volume on the original site */ | ||
| 1761 | VPRINT1("Creating transaction for backup volume %u on source ...",{ if (verbose) { fprintf(__stdoutp, ("Creating transaction for backup volume %u on source ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 1762 | backupId){ if (verbose) { fprintf(__stdoutp, ("Creating transaction for backup volume %u on source ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1763 | tmp = fromtid; | ||
| 1764 | code = | ||
| 1765 | AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline1, &tmp); | ||
| 1766 | fromtid = tmp; | ||
| 1767 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1768 | if (!code) { | ||
| 1769 | VPRINT1("Setting flags on backup volume %u on source ...", backupId){ if (verbose) { fprintf(__stdoutp, ("Setting flags on backup volume %u on source ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1770 | code = | ||
| 1771 | AFSVolSetFlags(fromconn, fromtid, | ||
| 1772 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 1773 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the backup volume %u on the source\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1774 | "Failed to set the flags on the backup volume %u on the source\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the backup volume %u on the source\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1775 | backupId)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the backup volume %u on the source\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1776 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1777 | |||
| 1778 | VPRINT1("Deleting the backup volume %u on the source ...", backupId){ if (verbose) { fprintf(__stdoutp, ("Deleting the backup volume %u on the source ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1779 | code = AFSVolDeleteVolume(fromconn, fromtid); | ||
| 1780 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the backup volume %u on the source\n")) , ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1781 | "Failed to delete the backup volume %u on the source\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the backup volume %u on the source\n")) , ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1782 | backupId)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the backup volume %u on the source\n")) , ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1783 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1784 | |||
| 1785 | VPRINT1("Ending transaction on backup volume %u on source ...",{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on backup volume %u on source ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 1786 | backupId){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on backup volume %u on source ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 1787 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1788 | fromtid = 0; | ||
| 1789 | if (!code) | ||
| 1790 | code = rcode; | ||
| 1791 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the backup volume %u on the source\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1792 | "Failed to end the transaction on the backup volume %u on the source\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the backup volume %u on the source\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1793 | backupId)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the backup volume %u on the source\n" )), ((backupId))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1794 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1795 | } else | ||
| 1796 | code = 0; /* no backup volume? that's okay */ | ||
| 1797 | |||
| 1798 | fromtid = 0; | ||
| 1799 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 1800 | VPRINT1("Starting transaction on the cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on the cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1801 | tmp = clonetid; | ||
| 1802 | code = | ||
| 1803 | AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline1, | ||
| 1804 | &tmp); | ||
| 1805 | clonetid = tmp; | ||
| 1806 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1807 | "Failed to start a transaction on the cloned volume%u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1808 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1809 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1810 | |||
| 1811 | /* now delete the clone */ | ||
| 1812 | VPRINT1("Deleting the cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Deleting the cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1813 | code = AFSVolDeleteVolume(fromconn, clonetid); | ||
| 1814 | EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the cloned volume %u\n")), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail ; } } while (0) | ||
| 1815 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the cloned volume %u\n")), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail ; } } while (0); | ||
| 1816 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1817 | |||
| 1818 | VPRINT1("Ending transaction on cloned volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on cloned volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1819 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 1820 | if (!code) | ||
| 1821 | code = rcode; | ||
| 1822 | clonetid = 0; | ||
| 1823 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1824 | "Failed to end the transaction on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 1825 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 1826 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1827 | } | ||
| 1828 | |||
| 1829 | /* fall through */ | ||
| 1830 | /* END OF MOVE */ | ||
| 1831 | |||
| 1832 | if (TESTC0) { | ||
| 1833 | fprintf(STDOUT__stdoutp, "Fourth test point - operation complete.\n"); | ||
| 1834 | fprintf(STDOUT__stdoutp, "...test here (y, n)? "); | ||
| 1835 | fflush(STDOUT__stdoutp); | ||
| 1836 | fscanf(stdin__stdinp, "%c", &in); | ||
| 1837 | fscanf(stdin__stdinp, "%c", &lf); /* toss away */ | ||
| 1838 | if (in == 'y') { | ||
| 1839 | fprintf(STDOUT__stdoutp, "type control-c\n"); | ||
| 1840 | while (1) { | ||
| 1841 | fprintf(stdout__stdoutp, "."); | ||
| 1842 | fflush(stdout__stdoutp); | ||
| 1843 | sleep(1); | ||
| 1844 | } | ||
| 1845 | } | ||
| 1846 | /* or drop through */ | ||
| 1847 | } | ||
| 1848 | |||
| 1849 | /* normal cleanup code */ | ||
| 1850 | |||
| 1851 | if (entry.flags & RO_EXISTS0x2000) | ||
| 1852 | fprintf(STDERR__stderrp, "WARNING : readOnly copies still exist \n"); | ||
| 1853 | |||
| 1854 | if (islocked) { | ||
| 1855 | VPRINT1("Cleanup: Releasing VLDB lock on volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Releasing VLDB lock on volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1856 | vcode = | ||
| 1857 | ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1, | ||
| 1858 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1)); | ||
| 1859 | if (vcode) { | ||
| 1860 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 1861 | fprintf(STDERR__stderrp, | ||
| 1862 | " Could not release the lock on the VLDB entry for the volume %lu \n", | ||
| 1863 | (unsigned long)afromvol); | ||
| 1864 | if (!error) | ||
| 1865 | error = vcode; | ||
| 1866 | } | ||
| 1867 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1868 | } | ||
| 1869 | |||
| 1870 | if (fromtid) { | ||
| 1871 | VPRINT1("Cleanup: Ending transaction on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 1872 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1873 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1874 | if (code || rcode) { | ||
| 1875 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 1876 | fprintf(STDERR__stderrp, | ||
| 1877 | "Could not end transaction on the source volume %lu\n", | ||
| 1878 | (unsigned long)afromvol); | ||
| 1879 | if (!error) | ||
| 1880 | error = (code ? code : rcode); | ||
| 1881 | } | ||
| 1882 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1883 | } | ||
| 1884 | |||
| 1885 | if (clonetid) { | ||
| 1886 | VPRINT1("Cleanup: Ending transaction on clone volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on clone volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 1887 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 1888 | if (code || rcode) { | ||
| 1889 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 1890 | fprintf(STDERR__stderrp, | ||
| 1891 | "Could not end transaction on the source's clone volume %lu\n", | ||
| 1892 | (unsigned long)newVol); | ||
| 1893 | if (!error) | ||
| 1894 | error = (code ? code : rcode); | ||
| 1895 | } | ||
| 1896 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1897 | } | ||
| 1898 | |||
| 1899 | if (totid) { | ||
| 1900 | VPRINT1("Cleanup: Ending transaction on destination volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on destination volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 1901 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on destination volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1902 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 1903 | if (code) { | ||
| 1904 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 1905 | fprintf(STDERR__stderrp, | ||
| 1906 | "Could not end transaction on destination volume %lu\n", | ||
| 1907 | (unsigned long)afromvol); | ||
| 1908 | if (!error) | ||
| 1909 | error = (code ? code : rcode); | ||
| 1910 | } | ||
| 1911 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1912 | } | ||
| 1913 | if (volName) | ||
| 1914 | free(volName); | ||
| 1915 | #ifdef ENABLE_BUGFIX_1165 | ||
| 1916 | if (infop) | ||
| 1917 | free(infop); | ||
| 1918 | #endif | ||
| 1919 | if (fromconn) | ||
| 1920 | rx_DestroyConnection(fromconn); | ||
| 1921 | if (toconn) | ||
| 1922 | rx_DestroyConnection(toconn); | ||
| 1923 | PrintError("", error); | ||
| 1924 | return error; | ||
| 1925 | |||
| 1926 | /* come here only when the sky falls */ | ||
| 1927 | mfail: | ||
| 1928 | |||
| 1929 | if (pntg) { | ||
| 1930 | fprintf(STDOUT__stdoutp, | ||
| 1931 | "vos move: operation interrupted, cleanup in progress...\n"); | ||
| 1932 | fprintf(STDOUT__stdoutp, "clear transaction contexts\n"); | ||
| 1933 | fflush(STDOUT__stdoutp); | ||
| 1934 | } | ||
| 1935 | |||
| 1936 | /* unlock VLDB entry */ | ||
| 1937 | if (islocked) { | ||
| 1938 | VPRINT1("Recovery: Releasing VLDB lock on volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Releasing VLDB lock on volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 1939 | ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1, | ||
| 1940 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1)); | ||
| 1941 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1942 | islocked = 0; | ||
| 1943 | } | ||
| 1944 | |||
| 1945 | if (clonetid) { | ||
| 1946 | VPRINT("Recovery: Ending transaction on clone volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on clone volume ..." )); fflush(__stdoutp); } }; | ||
| 1947 | AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 1948 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1949 | } | ||
| 1950 | if (totid) { | ||
| 1951 | VPRINT("Recovery: Ending transaction on destination volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on destination volume ..." )); fflush(__stdoutp); } }; | ||
| 1952 | AFSVolEndTrans(toconn, totid, &rcode); | ||
| 1953 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1954 | } | ||
| 1955 | if (fromtid) { /* put it on-line */ | ||
| 1956 | VPRINT("Recovery: Setting volume flags on source volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting volume flags on source volume ..." )); fflush(__stdoutp); } }; | ||
| 1957 | AFSVolSetFlags(fromconn, fromtid, 0); | ||
| 1958 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1959 | |||
| 1960 | VPRINT("Recovery: Ending transaction on source volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume ..." )); fflush(__stdoutp); } }; | ||
| 1961 | AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 1962 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1963 | } | ||
| 1964 | |||
| 1965 | VPRINT("Recovery: Accessing VLDB.\n"){ if (verbose) { fprintf(__stdoutp, ("Recovery: Accessing VLDB.\n" )); fflush(__stdoutp); } }; | ||
| 1966 | vcode = VLDB_GetEntryByID(afromvol, -1, &entry); | ||
| 1967 | if (vcode) { | ||
| 1968 | fprintf(STDOUT__stdoutp, "FATAL: VLDB access error: abort cleanup\n"); | ||
| 1969 | fflush(STDOUT__stdoutp); | ||
| 1970 | goto done; | ||
| 1971 | } | ||
| 1972 | MapHostToNetwork(&entry); | ||
| 1973 | |||
| 1974 | /* Delete either the volume on the source location or the target location. | ||
| 1975 | * If the vldb entry still points to the source location, then we know the | ||
| 1976 | * volume move didn't finish so we remove the volume from the target | ||
| 1977 | * location. Otherwise, we remove the volume from the source location. | ||
| 1978 | */ | ||
| 1979 | if (Lp_Match(afromserver, afrompart, &entry)) { /* didn't move - delete target volume */ | ||
| 1980 | if (pntg) { | ||
| 1981 | fprintf(STDOUT__stdoutp, | ||
| 1982 | "move incomplete - attempt cleanup of target partition - no guarantee\n"); | ||
| 1983 | fflush(STDOUT__stdoutp); | ||
| 1984 | } | ||
| 1985 | |||
| 1986 | if (volid && toconn) { | ||
| 1987 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction for destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 1988 | ("Recovery: Creating transaction for destination volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction for destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 1989 | volid){ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction for destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 1990 | tmp = totid; | ||
| 1991 | code = | ||
| 1992 | AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline1, &tmp); | ||
| 1993 | totid = tmp; | ||
| 1994 | |||
| 1995 | if (!code) { | ||
| 1996 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 1997 | |||
| 1998 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 1999 | ("Recovery: Setting flags on destination volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 2000 | volid){ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 2001 | AFSVolSetFlags(toconn, totid, | ||
| 2002 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 2003 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2004 | |||
| 2005 | VPRINT1("Recovery: Deleting destination volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Deleting destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 2006 | volid){ if (verbose) { fprintf(__stdoutp, ("Recovery: Deleting destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 2007 | AFSVolDeleteVolume(toconn, totid); | ||
| 2008 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2009 | |||
| 2010 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 2011 | ("Recovery: Ending transaction on destination volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on destination volume %u ..." ), (volid)); fflush(__stdoutp); } } | ||
| 2012 | volid){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on destination volume %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 2013 | AFSVolEndTrans(toconn, totid, &rcode); | ||
| 2014 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2015 | } else { | ||
| 2016 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on destination volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2017 | ("\nRecovery: Unable to start transaction on destination volume %u.\n",{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on destination volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2018 | afromvol){ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on destination volume %u.\n" ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2019 | } | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | /* put source volume on-line */ | ||
| 2023 | if (fromconn) { | ||
| 2024 | VPRINT1("Recovery: Creating transaction on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2025 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2026 | tmp = fromtid; | ||
| 2027 | code = | ||
| 2028 | AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, | ||
| 2029 | &tmp); | ||
| 2030 | fromtid = tmp; | ||
| 2031 | if (!code) { | ||
| 2032 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2033 | |||
| 2034 | VPRINT1("Recovery: Setting flags on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2035 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2036 | AFSVolSetFlags(fromconn, fromtid, 0); | ||
| 2037 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2038 | |||
| 2039 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2040 | ("Recovery: Ending transaction on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2041 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2042 | AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2043 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2044 | } else { | ||
| 2045 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2046 | ("\nRecovery: Unable to start transaction on source volume %u.\n",{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2047 | afromvol){ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2048 | } | ||
| 2049 | } | ||
| 2050 | } else { /* yep, move complete */ | ||
| 2051 | if (pntg) { | ||
| 2052 | fprintf(STDOUT__stdoutp, | ||
| 2053 | "move complete - attempt cleanup of source partition - no guarantee\n"); | ||
| 2054 | fflush(STDOUT__stdoutp); | ||
| 2055 | } | ||
| 2056 | |||
| 2057 | /* delete backup volume */ | ||
| 2058 | if (fromconn) { | ||
| 2059 | VPRINT1("Recovery: Creating transaction on backup volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 2060 | backupId){ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 2061 | tmp = fromtid; | ||
| 2062 | code = | ||
| 2063 | AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline1, | ||
| 2064 | &tmp); | ||
| 2065 | fromtid = tmp; | ||
| 2066 | if (!code) { | ||
| 2067 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2068 | |||
| 2069 | VPRINT1("Recovery: Setting flags on backup volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 2070 | backupId){ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 2071 | AFSVolSetFlags(fromconn, fromtid, | ||
| 2072 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 2073 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2074 | |||
| 2075 | VPRINT1("Recovery: Deleting backup volume %u ...", backupId){ if (verbose) { fprintf(__stdoutp, ("Recovery: Deleting backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 2076 | AFSVolDeleteVolume(fromconn, fromtid); | ||
| 2077 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2078 | |||
| 2079 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 2080 | ("Recovery: Ending transaction on backup volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } } | ||
| 2081 | backupId){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on backup volume %u ..." ), (backupId)); fflush(__stdoutp); } }; | ||
| 2082 | AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2083 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2084 | } else { | ||
| 2085 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on backup volume %u.\n" ), (backupId)); fflush(__stdoutp); } } | ||
| 2086 | ("\nRecovery: Unable to start transaction on backup volume %u.\n",{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on backup volume %u.\n" ), (backupId)); fflush(__stdoutp); } } | ||
| 2087 | backupId){ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on backup volume %u.\n" ), (backupId)); fflush(__stdoutp); } }; | ||
| 2088 | } | ||
| 2089 | |||
| 2090 | /* delete source volume */ | ||
| 2091 | VPRINT1("Recovery: Creating transaction on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2092 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2093 | tmp = fromtid; | ||
| 2094 | code = | ||
| 2095 | AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, | ||
| 2096 | &tmp); | ||
| 2097 | fromtid = tmp; | ||
| 2098 | if (!code) { | ||
| 2099 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2100 | |||
| 2101 | VPRINT1("Recovery: Setting flags on backup volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on backup volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2102 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting flags on backup volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2103 | AFSVolSetFlags(fromconn, fromtid, | ||
| 2104 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 2105 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2106 | |||
| 2107 | if (atoserver != afromserver) { | ||
| 2108 | VPRINT("Recovery: Setting volume forwarding pointer ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Setting volume forwarding pointer ..." )); fflush(__stdoutp); } }; | ||
| 2109 | AFSVolSetForwarding(fromconn, fromtid, atoserver); | ||
| 2110 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2111 | } | ||
| 2112 | |||
| 2113 | VPRINT1("Recovery: Deleting source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Deleting source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2114 | AFSVolDeleteVolume(fromconn, fromtid); | ||
| 2115 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2116 | |||
| 2117 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2118 | ("Recovery: Ending transaction on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2119 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2120 | AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2121 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2122 | } else { | ||
| 2123 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2124 | ("\nRecovery: Unable to start transaction on source volume %u.\n",{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2125 | afromvol){ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2126 | } | ||
| 2127 | } | ||
| 2128 | } | ||
| 2129 | |||
| 2130 | /* common cleanup - delete local clone */ | ||
| 2131 | if (newVol) { | ||
| 2132 | VPRINT1("Recovery: Creating transaction on clone volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on clone volume %u ..." ), (newVol)); fflush(__stdoutp); } } | ||
| 2133 | newVol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on clone volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2134 | tmp = clonetid; | ||
| 2135 | code = | ||
| 2136 | AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline1, | ||
| 2137 | &tmp); | ||
| 2138 | clonetid = tmp; | ||
| 2139 | if (!code) { | ||
| 2140 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2141 | |||
| 2142 | VPRINT1("Recovery: Deleting clone volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Deleting clone volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2143 | AFSVolDeleteVolume(fromconn, clonetid); | ||
| 2144 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2145 | |||
| 2146 | VPRINT1("Recovery: Ending transaction on clone volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on clone volume %u ..." ), (newVol)); fflush(__stdoutp); } } | ||
| 2147 | newVol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on clone volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2148 | AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 2149 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2150 | } else { | ||
| 2151 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2152 | ("\nRecovery: Unable to start transaction on source volume %u.\n",{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } } | ||
| 2153 | afromvol){ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on source volume %u.\n" ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2154 | } | ||
| 2155 | } | ||
| 2156 | |||
| 2157 | /* unlock VLDB entry */ | ||
| 2158 | if (islocked) { | ||
| 2159 | VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Releasing lock on VLDB entry for volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2160 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Releasing lock on VLDB entry for volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2161 | ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1, | ||
| 2162 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1)); | ||
| 2163 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2164 | islocked = 0; | ||
| 2165 | } | ||
| 2166 | done: /* routine cleanup */ | ||
| 2167 | if (volName) | ||
| 2168 | free(volName); | ||
| 2169 | #ifdef ENABLE_BUGFIX_1165 | ||
| 2170 | if (infop) | ||
| 2171 | free(infop); | ||
| 2172 | #endif | ||
| 2173 | if (fromconn) | ||
| 2174 | rx_DestroyConnection(fromconn); | ||
| 2175 | if (toconn) | ||
| 2176 | rx_DestroyConnection(toconn); | ||
| 2177 | |||
| 2178 | if (pntg) { | ||
| 2179 | fprintf(STDOUT__stdoutp, "cleanup complete - user verify desired result\n"); | ||
| 2180 | fflush(STDOUT__stdoutp); | ||
| 2181 | } | ||
| 2182 | exit(1); | ||
| 2183 | } | ||
| 2184 | |||
| 2185 | |||
| 2186 | int | ||
| 2187 | UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart, | ||
| 2188 | afs_uint32 atoserver, afs_int32 atopart) | ||
| 2189 | { | ||
| 2190 | return UV_MoveVolume2(afromvol, afromserver, afrompart, | ||
| 2191 | atoserver, atopart, 0); | ||
| 2192 | } | ||
| 2193 | |||
| 2194 | |||
| 2195 | /* Copy volume <afromvol> from <afromserver> <afrompart> to <atoserver> | ||
| 2196 | * <atopart>. The new volume is named by <atovolname>. The new volume | ||
| 2197 | * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated | ||
| 2198 | * from the VLDB. the following flags are supported: | ||
| 2199 | * | ||
| 2200 | * RV_RDONLY - target volume is RO | ||
| 2201 | * RV_OFFLINE - leave target volume offline | ||
| 2202 | * RV_CPINCR - do incremental dump if target exists | ||
| 2203 | * RV_NOVLDB - don't create/update VLDB entry | ||
| 2204 | * RV_NOCLONE - don't use a copy clone | ||
| 2205 | */ | ||
| 2206 | int | ||
| 2207 | UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart, | ||
| 2208 | char *atovolname, afs_uint32 atoserver, afs_int32 atopart, | ||
| 2209 | afs_uint32 atovolid, int flags) | ||
| 2210 | { | ||
| 2211 | /* declare stuff 'volatile' that may be used from setjmp/longjmp and may | ||
| 2212 | * be changing during the copy */ | ||
| 2213 | int volatile pntg; | ||
| 2214 | afs_int32 volatile clonetid; | ||
| 2215 | afs_int32 volatile totid; | ||
| 2216 | afs_int32 volatile fromtid; | ||
| 2217 | struct rx_connection * volatile fromconn; | ||
| 2218 | struct rx_connection * volatile toconn; | ||
| 2219 | afs_uint32 volatile cloneVol; | ||
| 2220 | |||
| 2221 | char vname[64]; | ||
| 2222 | afs_int32 rcode; | ||
| 2223 | afs_int32 fromDate, cloneFromDate; | ||
| 2224 | struct restoreCookie cookie; | ||
| 2225 | afs_int32 vcode, code; | ||
| 2226 | afs_uint32 newVol; | ||
| 2227 | afs_int32 volflag; | ||
| 2228 | struct volser_status tstatus; | ||
| 2229 | struct destServer destination; | ||
| 2230 | struct nvldbentry entry, newentry, storeEntry; | ||
| 2231 | afs_int32 error; | ||
| 2232 | afs_int32 tmp; | ||
| 2233 | afs_uint32 tmpVol; | ||
| 2234 | |||
| 2235 | fromconn = (struct rx_connection *)0; | ||
| 2236 | toconn = (struct rx_connection *)0; | ||
| 2237 | fromtid = 0; | ||
| 2238 | totid = 0; | ||
| 2239 | clonetid = 0; | ||
| 2240 | error = 0; | ||
| 2241 | pntg = 0; | ||
| 2242 | newVol = 0; | ||
| 2243 | |||
| 2244 | /* support control-c processing */ | ||
| 2245 | if (setjmp(env)) | ||
| 2246 | goto mfail; | ||
| 2247 | (void)signal(SIGINT2, sigint_handler); | ||
| 2248 | |||
| 2249 | vcode = VLDB_GetEntryByID(afromvol, -1, &entry); | ||
| 2250 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 2251 | "Could not fetch the entry for the volume %u from the VLDB \n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 2252 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not fetch the entry for the volume %u from the VLDB \n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 2253 | MapHostToNetwork(&entry); | ||
| 2254 | |||
| 2255 | pntg = 1; | ||
| 2256 | toconn = UV_Bind(atoserver, AFSCONF_VOLUMEPORT7005); /* get connections to the servers */ | ||
| 2257 | fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 2258 | fromtid = totid = 0; /* initialize to uncreated */ | ||
| 2259 | |||
| 2260 | /* *** | ||
| 2261 | * clone the read/write volume locally. | ||
| 2262 | * ***/ | ||
| 2263 | |||
| 2264 | cloneVol = 0; | ||
| 2265 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 2266 | VPRINT1("Starting transaction on source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2267 | tmp = fromtid; | ||
| 2268 | code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, | ||
| 2269 | &tmp); | ||
| 2270 | fromtid = tmp; | ||
| 2271 | EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create transaction on the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2272 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create transaction on the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2273 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2274 | |||
| 2275 | /* Get a clone id */ | ||
| 2276 | VPRINT1("Allocating new volume id for clone of volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for clone of volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2277 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for clone of volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2278 | cloneVol = 0; | ||
| 2279 | tmpVol = cloneVol; | ||
| 2280 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol); | ||
| 2281 | cloneVol = tmpVol; | ||
| 2282 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 2283 | "Could not get an ID for the clone of volume %u from the VLDB\n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 2284 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 2285 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2286 | } | ||
| 2287 | |||
| 2288 | if (atovolid) { | ||
| 2289 | newVol = atovolid; | ||
| 2290 | } else { | ||
| 2291 | /* Get a new volume id */ | ||
| 2292 | VPRINT1("Allocating new volume id for copy of volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for copy of volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2293 | newVol = 0; | ||
| 2294 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol); | ||
| 2295 | EGOTO1(mfail, vcode,do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the copy of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 2296 | "Could not get an ID for the copy of volume %u from the VLDB\n",do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the copy of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0) | ||
| 2297 | afromvol)do { if (vcode) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the copy of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(vcode)); } while (0); error = (vcode); goto mfail; } } while (0); | ||
| 2298 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 2302 | /* Do the clone. Default flags on clone are set to delete on salvage and out of service */ | ||
| 2303 | VPRINT1("Cloning source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Cloning source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2304 | strcpy(vname, "copy-clone-temp"); | ||
| 2305 | tmpVol = cloneVol; | ||
| 2306 | code = | ||
| 2307 | AFSVolClone(fromconn, fromtid, 0, readonlyVolume1, vname, | ||
| 2308 | &tmpVol); | ||
| 2309 | cloneVol = tmpVol; | ||
| 2310 | EGOTO1(mfail, code, "Failed to clone the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to clone the source volume %u\n")), ((afromvol))) ; PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2311 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to clone the source volume %u\n")), ((afromvol))) ; PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2312 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2313 | |||
| 2314 | VPRINT1("Ending the transaction on the source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending the transaction on the source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2315 | rcode = 0; | ||
| 2316 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2317 | fromtid = 0; | ||
| 2318 | if (!code) | ||
| 2319 | code = rcode; | ||
| 2320 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2321 | "Failed to end the transaction on the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2322 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2323 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2324 | } | ||
| 2325 | |||
| 2326 | /* *** | ||
| 2327 | * Create the destination volume | ||
| 2328 | * ***/ | ||
| 2329 | |||
| 2330 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 2331 | VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on the cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2332 | tmp = clonetid; | ||
| 2333 | code = | ||
| 2334 | AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline1, | ||
| 2335 | &tmp); | ||
| 2336 | clonetid = tmp; | ||
| 2337 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2338 | "Failed to start a transaction on the cloned volume%u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2339 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2340 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2341 | |||
| 2342 | VPRINT1("Setting flags on cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Setting flags on cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2343 | code = | ||
| 2344 | AFSVolSetFlags(fromconn, clonetid, | ||
| 2345 | VTDeleteOnSalvage1 | VTOutOfService2); /*redundant */ | ||
| 2346 | EGOTO1(mfail, code, "Could not set flags on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set flags on the cloned volume %u\n")), ((cloneVol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2347 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set flags on the cloned volume %u\n")), ((cloneVol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2348 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2349 | |||
| 2350 | /* remember time from which we've dumped the volume */ | ||
| 2351 | VPRINT1("Getting status of cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Getting status of cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2352 | code = AFSVolGetStatus(fromconn, clonetid, &tstatus); | ||
| 2353 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the cloned volume %u\n")), ( (cloneVol))); PrintError(" ",(code)); } while (0); error = ( code); goto mfail; } } while (0) | ||
| 2354 | "Failed to get the status of the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the cloned volume %u\n")), ( (cloneVol))); PrintError(" ",(code)); } while (0); error = ( code); goto mfail; } } while (0) | ||
| 2355 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the cloned volume %u\n")), ( (cloneVol))); PrintError(" ",(code)); } while (0); error = ( code); goto mfail; } } while (0); | ||
| 2356 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2357 | |||
| 2358 | fromDate = CLOCKADJ(tstatus.creationDate)(((tstatus.creationDate) < 2) ? 0 : (tstatus.creationDate) - 2); | ||
| 2359 | } else { | ||
| 2360 | fromDate = 0; | ||
| 2361 | } | ||
| 2362 | |||
| 2363 | /* create a volume on the target machine */ | ||
| 2364 | cloneFromDate = 0; | ||
| 2365 | tmp = totid; | ||
| 2366 | code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline1, &tmp); | ||
| 2367 | totid = tmp; | ||
| 2368 | if (!code) { | ||
| 2369 | if ((flags & RV_CPINCR0x020000)) { | ||
| 2370 | VPRINT1("Getting status of pre-existing volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Getting status of pre-existing volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2371 | code = AFSVolGetStatus(toconn, totid, &tstatus); | ||
| 2372 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the pre-existing volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2373 | "Failed to get the status of the pre-existing volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the pre-existing volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2374 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to get the status of the pre-existing volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2375 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2376 | |||
| 2377 | /* Using the update date should be OK here, but add some fudge */ | ||
| 2378 | cloneFromDate = CLOCKADJ(tstatus.updateDate)(((tstatus.updateDate) < 2) ? 0 : (tstatus.updateDate) - 2 ); | ||
| 2379 | if ((flags & RV_NOCLONE0x080000)) | ||
| 2380 | fromDate = cloneFromDate; | ||
| 2381 | |||
| 2382 | /* XXX We should check that the source volume's creationDate is | ||
| 2383 | * XXX not newer than the existing target volume, and if not, | ||
| 2384 | * XXX throw away the existing target and do a full dump. */ | ||
| 2385 | |||
| 2386 | goto cpincr; | ||
| 2387 | } | ||
| 2388 | |||
| 2389 | /* Delete the existing volume. | ||
| 2390 | * While we are deleting the volume in these steps, the transaction | ||
| 2391 | * we started against the cloned volume (clonetid above) will be | ||
| 2392 | * sitting idle. It will get cleaned up after 600 seconds | ||
| 2393 | */ | ||
| 2394 | VPRINT1("Deleting pre-existing volume %u on destination ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Deleting pre-existing volume %u on destination ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2395 | code = AFSVolDeleteVolume(toconn, totid); | ||
| 2396 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the pre-existing volume %u on destination\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2397 | "Could not delete the pre-existing volume %u on destination\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the pre-existing volume %u on destination\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2398 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete the pre-existing volume %u on destination\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2399 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2400 | |||
| 2401 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on pre-existing volume %u on destination ..." ), (newVol)); fflush(__stdoutp); } } | ||
| 2402 | ("Ending transaction on pre-existing volume %u on destination ...",{ if (verbose) { fprintf(__stdoutp, ("Ending transaction on pre-existing volume %u on destination ..." ), (newVol)); fflush(__stdoutp); } } | ||
| 2403 | newVol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on pre-existing volume %u on destination ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2404 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 2405 | totid = 0; | ||
| 2406 | if (!code) | ||
| 2407 | code = rcode; | ||
| 2408 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction on pre-existing volume %u on destination\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2409 | "Could not end the transaction on pre-existing volume %u on destination\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction on pre-existing volume %u on destination\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2410 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end the transaction on pre-existing volume %u on destination\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2411 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2412 | } | ||
| 2413 | |||
| 2414 | VPRINT1("Creating the destination volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Creating the destination volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2415 | tmp = totid; | ||
| 2416 | code = | ||
| 2417 | AFSVolCreateVolume(toconn, atopart, atovolname, | ||
| 2418 | (flags & RV_RDONLY0x010000) ? volser_RO1 : volser_RW0, | ||
| 2419 | newVol, &newVol, &tmp); | ||
| 2420 | totid = tmp; | ||
| 2421 | EGOTO1(mfail, code, "Failed to create the destination volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create the destination volume %u\n")), ((newVol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2422 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create the destination volume %u\n")), ((newVol ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2423 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2424 | |||
| 2425 | VPRINT1("Setting volume flags on destination volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Setting volume flags on destination volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2426 | code = | ||
| 2427 | AFSVolSetFlags(toconn, totid, (VTDeleteOnSalvage1 | VTOutOfService2)); | ||
| 2428 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the destination volume %u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2429 | "Failed to set the flags on the destination volume %u\n", newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags on the destination volume %u\n") ), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2430 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2431 | |||
| 2432 | cpincr: | ||
| 2433 | |||
| 2434 | destination.destHost = ntohl(atoserver)(__builtin_constant_p(atoserver) ? ((((__uint32_t)(atoserver) ) >> 24) | ((((__uint32_t)(atoserver)) & (0xff << 16)) >> 8) | ((((__uint32_t)(atoserver)) & (0xff << 8)) << 8) | (((__uint32_t)(atoserver)) << 24)) : __bswap32_var(atoserver)); | ||
| 2435 | destination.destPort = AFSCONF_VOLUMEPORT7005; | ||
| 2436 | destination.destSSID = 1; | ||
| 2437 | |||
| 2438 | strncpy(cookie.name, atovolname, VOLSER_OLDMAXVOLNAME32); | ||
| 2439 | cookie.type = (flags & RV_RDONLY0x010000) ? ROVOL1 : RWVOL0; | ||
| 2440 | cookie.parent = 0; | ||
| 2441 | cookie.clone = 0; | ||
| 2442 | |||
| 2443 | /*** | ||
| 2444 | * Now dump the clone to the new volume | ||
| 2445 | ***/ | ||
| 2446 | |||
| 2447 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 2448 | /* XXX probably should have some code here that checks to see if | ||
| 2449 | * XXX we are copying to same server and partition - if so, just | ||
| 2450 | * XXX use a clone to save disk space */ | ||
| 2451 | |||
| 2452 | /* Copy the clone to the new volume */ | ||
| 2453 | VPRINT2("Dumping from clone %u on source to volume %u on destination ...",{ if (verbose) { fprintf(__stdoutp, ("Dumping from clone %u on source to volume %u on destination ..." ), (cloneVol), (newVol)); fflush(__stdoutp); } } | ||
| 2454 | cloneVol, newVol){ if (verbose) { fprintf(__stdoutp, ("Dumping from clone %u on source to volume %u on destination ..." ), (cloneVol), (newVol)); fflush(__stdoutp); } }; | ||
| 2455 | code = | ||
| 2456 | AFSVolForward(fromconn, clonetid, cloneFromDate, &destination, | ||
| 2457 | totid, &cookie); | ||
| 2458 | EGOTO1(mfail, code, "Failed to move data for the volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to move data for the volume %u\n")), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail ; } } while (0) | ||
| 2459 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to move data for the volume %u\n")), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail ; } } while (0); | ||
| 2460 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2461 | |||
| 2462 | VPRINT1("Ending transaction on cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2463 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 2464 | if (!code) | ||
| 2465 | code = rcode; | ||
| 2466 | clonetid = 0; | ||
| 2467 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2468 | "Failed to end the transaction on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2469 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2470 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2471 | } | ||
| 2472 | |||
| 2473 | /* *** | ||
| 2474 | * reattach to the main-line volume, and incrementally dump it. | ||
| 2475 | * ***/ | ||
| 2476 | |||
| 2477 | VPRINT1("Starting transaction on source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2478 | tmp = fromtid; | ||
| 2479 | code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, &tmp); | ||
| 2480 | fromtid = tmp; | ||
| 2481 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create a transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2482 | "Failed to create a transaction on the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create a transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2483 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to create a transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2484 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2485 | |||
| 2486 | /* now do the incremental */ | ||
| 2487 | VPRINT2{ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } } | ||
| 2488 | ("Doing the%s dump from source to destination for volume %u ... ",{ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } } | ||
| 2489 | (flags & RV_NOCLONE) ? "" : " incremental",{ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } } | ||
| 2490 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Doing the%s dump from source to destination for volume %u ... " ), ((flags & 0x080000) ? "" : " incremental"), (afromvol) ); fflush(__stdoutp); } }; | ||
| 2491 | code = | ||
| 2492 | AFSVolForward(fromconn, fromtid, fromDate, &destination, totid, | ||
| 2493 | &cookie); | ||
| 2494 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to do the%s dump from old site to new site\n")), ( ((flags & 0x080000) ? "" : " incremental"))); PrintError( " ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2495 | "Failed to do the%s dump from old site to new site\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to do the%s dump from old site to new site\n")), ( ((flags & 0x080000) ? "" : " incremental"))); PrintError( " ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2496 | (flags & RV_NOCLONE) ? "" : " incremental")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to do the%s dump from old site to new site\n")), ( ((flags & 0x080000) ? "" : " incremental"))); PrintError( " ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2497 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2498 | |||
| 2499 | VPRINT1("Setting volume flags on destination volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Setting volume flags on destination volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2500 | volflag = ((flags & RV_OFFLINE0x000002) ? VTOutOfService2 : 0); /* off or on-line */ | ||
| 2501 | code = AFSVolSetFlags(toconn, totid, volflag); | ||
| 2502 | EGOTO(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags to make destination volume online\n" ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2503 | "Failed to set the flags to make destination volume online\n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to set the flags to make destination volume online\n" ))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2504 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2505 | |||
| 2506 | /* put new volume online */ | ||
| 2507 | VPRINT1("Ending transaction on destination volume %u ...", newVol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on destination volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2508 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 2509 | totid = 0; | ||
| 2510 | if (!code) | ||
| 2511 | code = rcode; | ||
| 2512 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the destination volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2513 | "Failed to end the transaction on the destination volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the destination volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2514 | newVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the destination volume %u\n" )), ((newVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2515 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2516 | |||
| 2517 | VPRINT1("Ending transaction on source volume %u ...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2518 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2519 | fromtid = 0; | ||
| 2520 | if (!code) | ||
| 2521 | code = rcode; | ||
| 2522 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2523 | "Failed to end the transaction on the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2524 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the source volume %u\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2525 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2526 | |||
| 2527 | fromtid = 0; | ||
| 2528 | |||
| 2529 | if (!(flags & RV_NOCLONE0x080000)) { | ||
| 2530 | VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on the cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2531 | tmp = clonetid; | ||
| 2532 | code = | ||
| 2533 | AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline1, | ||
| 2534 | &tmp); | ||
| 2535 | clonetid = tmp; | ||
| 2536 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2537 | "Failed to start a transaction on the cloned volume%u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2538 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2539 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2540 | |||
| 2541 | /* now delete the clone */ | ||
| 2542 | VPRINT1("Deleting the cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Deleting the cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2543 | code = AFSVolDeleteVolume(fromconn, clonetid); | ||
| 2544 | EGOTO1(mfail, code, "Failed to delete the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the cloned volume %u\n")), ((cloneVol)) ); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2545 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to delete the cloned volume %u\n")), ((cloneVol)) ); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2546 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2547 | |||
| 2548 | VPRINT1("Ending transaction on cloned volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on cloned volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2549 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 2550 | if (!code) | ||
| 2551 | code = rcode; | ||
| 2552 | clonetid = 0; | ||
| 2553 | EGOTO1(mfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2554 | "Failed to end the transaction on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0) | ||
| 2555 | cloneVol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the cloned volume %u\n" )), ((cloneVol))); PrintError(" ",(code)); } while (0); error = (code); goto mfail; } } while (0); | ||
| 2556 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2557 | } | ||
| 2558 | |||
| 2559 | if (!(flags & RV_NOVLDB0x040000)) { | ||
| 2560 | /* create the vldb entry for the copied volume */ | ||
| 2561 | strncpy(newentry.name, atovolname, VOLSER_OLDMAXVOLNAME32); | ||
| 2562 | newentry.nServers = 1; | ||
| 2563 | newentry.serverNumber[0] = atoserver; | ||
| 2564 | newentry.serverPartition[0] = atopart; | ||
| 2565 | newentry.flags = (flags & RV_RDONLY0x010000) ? RO_EXISTS0x2000 : RW_EXISTS0x1000; | ||
| 2566 | newentry.serverFlags[0] = (flags & RV_RDONLY0x010000) ? ITSROVOL0x02 : ITSRWVOL0x04; | ||
| 2567 | newentry.volumeId[RWVOL0] = newVol; | ||
| 2568 | newentry.volumeId[ROVOL1] = (flags & RV_RDONLY0x010000) ? newVol : 0; | ||
| 2569 | newentry.volumeId[BACKVOL2] = 0; | ||
| 2570 | newentry.cloneId = 0; | ||
| 2571 | /*map into right byte order, before passing to xdr, the stuff has to be in host | ||
| 2572 | * byte order. Xdr converts it into network order */ | ||
| 2573 | MapNetworkToHost(&newentry, &storeEntry); | ||
| 2574 | /* create the vldb entry */ | ||
| 2575 | vcode = VLDB_CreateEntry(&storeEntry); | ||
| 2576 | if (vcode) { | ||
| 2577 | fprintf(STDERR__stderrp, | ||
| 2578 | "Could not create a VLDB entry for the volume %s %lu\n", | ||
| 2579 | atovolname, (unsigned long)newVol); | ||
| 2580 | /*destroy the created volume */ | ||
| 2581 | VPRINT1("Deleting the newly created volume %u\n", newVol){ if (verbose) { fprintf(__stdoutp, ("Deleting the newly created volume %u\n" ), (newVol)); fflush(__stdoutp); } }; | ||
| 2582 | AFSVolDeleteVolume(toconn, totid); | ||
| 2583 | error = vcode; | ||
| 2584 | goto mfail; | ||
| 2585 | } | ||
| 2586 | VPRINT2("Created the VLDB entry for the volume %s %u\n", atovolname,{ if (verbose) { fprintf(__stdoutp, ("Created the VLDB entry for the volume %s %u\n" ), (atovolname), (newVol)); fflush(__stdoutp); } } | ||
| 2587 | newVol){ if (verbose) { fprintf(__stdoutp, ("Created the VLDB entry for the volume %s %u\n" ), (atovolname), (newVol)); fflush(__stdoutp); } }; | ||
| 2588 | } | ||
| 2589 | |||
| 2590 | /* normal cleanup code */ | ||
| 2591 | |||
| 2592 | if (fromtid) { | ||
| 2593 | VPRINT1("Cleanup: Ending transaction on source volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } } | ||
| 2594 | afromvol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on source volume %u ..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 2595 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2596 | if (code || rcode) { | ||
| 2597 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 2598 | fprintf(STDERR__stderrp, | ||
| 2599 | "Could not end transaction on the source volume %lu\n", | ||
| 2600 | (unsigned long)afromvol); | ||
| 2601 | if (!error) | ||
| 2602 | error = (code ? code : rcode); | ||
| 2603 | } | ||
| 2604 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2605 | } | ||
| 2606 | |||
| 2607 | if (clonetid) { | ||
| 2608 | VPRINT1("Cleanup: Ending transaction on clone volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } } | ||
| 2609 | cloneVol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2610 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 2611 | if (code || rcode) { | ||
| 2612 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 2613 | fprintf(STDERR__stderrp, | ||
| 2614 | "Could not end transaction on the source's clone volume %lu\n", | ||
| 2615 | (unsigned long)cloneVol); | ||
| 2616 | if (!error) | ||
| 2617 | error = (code ? code : rcode); | ||
| 2618 | } | ||
| 2619 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2620 | } | ||
| 2621 | |||
| 2622 | if (totid) { | ||
| 2623 | VPRINT1("Cleanup: Ending transaction on destination volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on destination volume %u ..." ), (newVol)); fflush(__stdoutp); } } | ||
| 2624 | newVol){ if (verbose) { fprintf(__stdoutp, ("Cleanup: Ending transaction on destination volume %u ..." ), (newVol)); fflush(__stdoutp); } }; | ||
| 2625 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 2626 | if (code) { | ||
| 2627 | VPRINT("\n"){ if (verbose) { fprintf(__stdoutp, ("\n")); fflush(__stdoutp ); } }; | ||
| 2628 | fprintf(STDERR__stderrp, | ||
| 2629 | "Could not end transaction on destination volume %lu\n", | ||
| 2630 | (unsigned long)newVol); | ||
| 2631 | if (!error) | ||
| 2632 | error = (code ? code : rcode); | ||
| 2633 | } | ||
| 2634 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2635 | } | ||
| 2636 | if (fromconn) | ||
| 2637 | rx_DestroyConnection(fromconn); | ||
| 2638 | if (toconn) | ||
| 2639 | rx_DestroyConnection(toconn); | ||
| 2640 | PrintError("", error); | ||
| 2641 | return error; | ||
| 2642 | |||
| 2643 | /* come here only when the sky falls */ | ||
| 2644 | mfail: | ||
| 2645 | |||
| 2646 | if (pntg) { | ||
| 2647 | fprintf(STDOUT__stdoutp, | ||
| 2648 | "vos copy: operation interrupted, cleanup in progress...\n"); | ||
| 2649 | fprintf(STDOUT__stdoutp, "clear transaction contexts\n"); | ||
| 2650 | fflush(STDOUT__stdoutp); | ||
| 2651 | } | ||
| 2652 | |||
| 2653 | if (clonetid) { | ||
| 2654 | VPRINT("Recovery: Ending transaction on clone volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on clone volume ..." )); fflush(__stdoutp); } }; | ||
| 2655 | AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 2656 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2657 | } | ||
| 2658 | if (totid) { | ||
| 2659 | VPRINT("Recovery: Ending transaction on destination volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on destination volume ..." )); fflush(__stdoutp); } }; | ||
| 2660 | AFSVolEndTrans(toconn, totid, &rcode); | ||
| 2661 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2662 | } | ||
| 2663 | if (fromtid) { /* put it on-line */ | ||
| 2664 | VPRINT("Recovery: Ending transaction on source volume ..."){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on source volume ..." )); fflush(__stdoutp); } }; | ||
| 2665 | AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 2666 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2667 | } | ||
| 2668 | |||
| 2669 | VPRINT("Recovery: Accessing VLDB.\n"){ if (verbose) { fprintf(__stdoutp, ("Recovery: Accessing VLDB.\n" )); fflush(__stdoutp); } }; | ||
| 2670 | vcode = VLDB_GetEntryByID(afromvol, -1, &entry); | ||
| 2671 | if (vcode) { | ||
| 2672 | fprintf(STDOUT__stdoutp, "FATAL: VLDB access error: abort cleanup\n"); | ||
| 2673 | fflush(STDOUT__stdoutp); | ||
| 2674 | goto done; | ||
| 2675 | } | ||
| 2676 | MapHostToNetwork(&entry); | ||
| 2677 | |||
| 2678 | /* common cleanup - delete local clone */ | ||
| 2679 | if (cloneVol) { | ||
| 2680 | VPRINT1("Recovery: Creating transaction on clone volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } } | ||
| 2681 | cloneVol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Creating transaction on clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2682 | tmp = clonetid; | ||
| 2683 | code = | ||
| 2684 | AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline1, | ||
| 2685 | &tmp); | ||
| 2686 | clonetid = tmp; | ||
| 2687 | if (!code) { | ||
| 2688 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2689 | |||
| 2690 | VPRINT1("Recovery: Deleting clone volume %u ...", cloneVol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Deleting clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2691 | AFSVolDeleteVolume(fromconn, clonetid); | ||
| 2692 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2693 | |||
| 2694 | VPRINT1("Recovery: Ending transaction on clone volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } } | ||
| 2695 | cloneVol){ if (verbose) { fprintf(__stdoutp, ("Recovery: Ending transaction on clone volume %u ..." ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2696 | AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 2697 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2698 | } else { | ||
| 2699 | VPRINT1{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on clone volume %u.\n" ), (cloneVol)); fflush(__stdoutp); } } | ||
| 2700 | ("\nRecovery: Unable to start transaction on clone volume %u.\n",{ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on clone volume %u.\n" ), (cloneVol)); fflush(__stdoutp); } } | ||
| 2701 | cloneVol){ if (verbose) { fprintf(__stdoutp, ("\nRecovery: Unable to start transaction on clone volume %u.\n" ), (cloneVol)); fflush(__stdoutp); } }; | ||
| 2702 | } | ||
| 2703 | } | ||
| 2704 | |||
| 2705 | done: /* routine cleanup */ | ||
| 2706 | if (fromconn) | ||
| 2707 | rx_DestroyConnection(fromconn); | ||
| 2708 | if (toconn) | ||
| 2709 | rx_DestroyConnection(toconn); | ||
| 2710 | |||
| 2711 | if (pntg) { | ||
| 2712 | fprintf(STDOUT__stdoutp, "cleanup complete - user verify desired result\n"); | ||
| 2713 | fflush(STDOUT__stdoutp); | ||
| 2714 | } | ||
| 2715 | exit(1); | ||
| 2716 | } | ||
| 2717 | |||
| 2718 | |||
| 2719 | int | ||
| 2720 | UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart, | ||
| 2721 | char *atovolname, afs_uint32 atoserver, afs_int32 atopart) | ||
| 2722 | { | ||
| 2723 | return UV_CopyVolume2(afromvol, afromserver, afrompart, | ||
| 2724 | atovolname, atoserver, atopart, 0, 0); | ||
| 2725 | } | ||
| 2726 | |||
| 2727 | |||
| 2728 | |||
| 2729 | /* Make a new backup of volume <avolid> on <aserver> and <apart> | ||
| 2730 | * if one already exists, update it | ||
| 2731 | */ | ||
| 2732 | |||
| 2733 | int | ||
| 2734 | UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid) | ||
| 2735 | { | ||
| 2736 | struct rx_connection *aconn = (struct rx_connection *)0; | ||
| 2737 | afs_int32 ttid = 0, btid = 0; | ||
| 2738 | afs_uint32 backupID; | ||
| 2739 | afs_int32 code = 0, rcode = 0; | ||
| 2740 | char vname[VOLSER_MAXVOLNAME65 + 1]; | ||
| 2741 | struct nvldbentry entry, storeEntry; | ||
| 2742 | afs_int32 error = 0; | ||
| 2743 | int vldblocked = 0, vldbmod = 0, backexists = 1; | ||
| 2744 | |||
| 2745 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 2746 | |||
| 2747 | /* the calls to VLDB will succeed only if avolid is a RW volume, | ||
| 2748 | * since we are following the RW hash chain for searching */ | ||
| 2749 | code = VLDB_GetEntryByID(avolid, RWVOL0, &entry); | ||
| 2750 | if (code) { | ||
| 2751 | fprintf(STDERR__stderrp, | ||
| 2752 | "Could not fetch the entry for the volume %lu from the VLDB \n", | ||
| 2753 | (unsigned long)avolid); | ||
| 2754 | error = code; | ||
| 2755 | goto bfail; | ||
| 2756 | } | ||
| 2757 | MapHostToNetwork(&entry); | ||
| 2758 | |||
| 2759 | /* These operations require the VLDB be locked since it means the VLDB | ||
| 2760 | * will change or the vldb is already locked. | ||
| 2761 | */ | ||
| 2762 | if (!(entry.flags & BACK_EXISTS0x4000) || /* backup volume doesnt exist */ | ||
| 2763 | (entry.flags & VLOP_ALLOPERS( 0x10 | 0x20 | 0x40 | 0x80 | 0x100)) || /* vldb lock already held */ | ||
| 2764 | (entry.volumeId[BACKVOL2] == INVALID_BID0)) { /* no assigned backup volume id */ | ||
| 2765 | |||
| 2766 | code = ubik_VL_SetLock(cstruct, 0, avolid, RWVOL0, VLOP_BACKUP0x40); | ||
| 2767 | if (code) { | ||
| 2768 | fprintf(STDERR__stderrp, | ||
| 2769 | "Could not lock the VLDB entry for the volume %lu\n", | ||
| 2770 | (unsigned long)avolid); | ||
| 2771 | error = code; | ||
| 2772 | goto bfail; | ||
| 2773 | } | ||
| 2774 | vldblocked = 1; | ||
| 2775 | |||
| 2776 | /* Reread the vldb entry */ | ||
| 2777 | code = VLDB_GetEntryByID(avolid, RWVOL0, &entry); | ||
| 2778 | if (code) { | ||
| 2779 | fprintf(STDERR__stderrp, | ||
| 2780 | "Could not fetch the entry for the volume %lu from the VLDB \n", | ||
| 2781 | (unsigned long)avolid); | ||
| 2782 | error = code; | ||
| 2783 | goto bfail; | ||
| 2784 | } | ||
| 2785 | MapHostToNetwork(&entry); | ||
| 2786 | } | ||
| 2787 | |||
| 2788 | if (!ISNAMEVALID(entry.name)(strlen(entry.name) < (32 - 9))) { | ||
| 2789 | fprintf(STDERR__stderrp, "Name of the volume %s exceeds the size limit\n", | ||
| 2790 | entry.name); | ||
| 2791 | error = VOLSERBADNAME(1492325129L); | ||
| 2792 | goto bfail; | ||
| 2793 | } | ||
| 2794 | |||
| 2795 | backupID = entry.volumeId[BACKVOL2]; | ||
| 2796 | if (backupID == INVALID_BID0) { | ||
| 2797 | /* Get a backup volume id from the VLDB and update the vldb | ||
| 2798 | * entry with it. | ||
| 2799 | */ | ||
| 2800 | code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID); | ||
| 2801 | if (code) { | ||
| 2802 | fprintf(STDERR__stderrp, | ||
| 2803 | "Could not allocate ID for the backup volume of %lu from the VLDB\n", | ||
| 2804 | (unsigned long)avolid); | ||
| 2805 | error = code; | ||
| 2806 | goto bfail; | ||
| 2807 | } | ||
| 2808 | entry.volumeId[BACKVOL2] = backupID; | ||
| 2809 | vldbmod = 1; | ||
| 2810 | } | ||
| 2811 | |||
| 2812 | /* Test to see if the backup volume exists by trying to create | ||
| 2813 | * a transaction on the backup volume. We've assumed the backup exists. | ||
| 2814 | */ | ||
| 2815 | code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline1, &btid); | ||
| 2816 | if (code) { | ||
| 2817 | if (code != VNOVOL103) { | ||
| 2818 | fprintf(STDERR__stderrp, "Could not reach the backup volume %lu\n", | ||
| 2819 | (unsigned long)backupID); | ||
| 2820 | error = code; | ||
| 2821 | goto bfail; | ||
| 2822 | } | ||
| 2823 | backexists = 0; /* backup volume does not exist */ | ||
| 2824 | } | ||
| 2825 | if (btid) { | ||
| 2826 | code = AFSVolEndTrans(aconn, btid, &rcode); | ||
| 2827 | btid = 0; | ||
| 2828 | if (code || rcode) { | ||
| 2829 | fprintf(STDERR__stderrp, | ||
| 2830 | "Could not end transaction on the previous backup volume %lu\n", | ||
| 2831 | (unsigned long)backupID); | ||
| 2832 | error = (code ? code : rcode); | ||
| 2833 | goto bfail; | ||
| 2834 | } | ||
| 2835 | } | ||
| 2836 | |||
| 2837 | /* Now go ahead and try to clone the RW volume. | ||
| 2838 | * First start a transaction on the RW volume | ||
| 2839 | */ | ||
| 2840 | code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy2, &ttid); | ||
| 2841 | if (code) { | ||
| 2842 | fprintf(STDERR__stderrp, "Could not start a transaction on the volume %lu\n", | ||
| 2843 | (unsigned long)avolid); | ||
| 2844 | error = code; | ||
| 2845 | goto bfail; | ||
| 2846 | } | ||
| 2847 | |||
| 2848 | /* Clone or reclone the volume, depending on whether the backup | ||
| 2849 | * volume exists or not | ||
| 2850 | */ | ||
| 2851 | if (backexists) { | ||
| 2852 | VPRINT1("Re-cloning backup volume %u ...", backupID){ if (verbose) { fprintf(__stdoutp, ("Re-cloning backup volume %u ..." ), (backupID)); fflush(__stdoutp); } }; | ||
| 2853 | |||
| 2854 | code = AFSVolReClone(aconn, ttid, backupID); | ||
| 2855 | if (code) { | ||
| 2856 | fprintf(STDERR__stderrp, "Could not re-clone backup volume %lu\n", | ||
| 2857 | (unsigned long)backupID); | ||
| 2858 | error = code; | ||
| 2859 | goto bfail; | ||
| 2860 | } | ||
| 2861 | } else { | ||
| 2862 | VPRINT1("Creating a new backup clone %u ...", backupID){ if (verbose) { fprintf(__stdoutp, ("Creating a new backup clone %u ..." ), (backupID)); fflush(__stdoutp); } }; | ||
| 2863 | |||
| 2864 | strcpy(vname, entry.name); | ||
| 2865 | strcat(vname, ".backup"); | ||
| 2866 | |||
| 2867 | code = AFSVolClone(aconn, ttid, 0, backupVolume2, vname, &backupID); | ||
| 2868 | if (code) { | ||
| 2869 | fprintf(STDERR__stderrp, "Failed to clone the volume %lu\n", | ||
| 2870 | (unsigned long)avolid); | ||
| 2871 | error = code; | ||
| 2872 | goto bfail; | ||
| 2873 | } | ||
| 2874 | } | ||
| 2875 | |||
| 2876 | /* End the transaction on the RW volume */ | ||
| 2877 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 2878 | ttid = 0; | ||
| 2879 | if (code || rcode) { | ||
| 2880 | fprintf(STDERR__stderrp, | ||
| 2881 | "Failed to end the transaction on the rw volume %lu\n", | ||
| 2882 | (unsigned long)avolid); | ||
| 2883 | error = (code ? code : rcode); | ||
| 2884 | goto bfail; | ||
| 2885 | } | ||
| 2886 | |||
| 2887 | /* Mork vldb as backup exists */ | ||
| 2888 | if (!(entry.flags & BACK_EXISTS0x4000)) { | ||
| 2889 | entry.flags |= BACK_EXISTS0x4000; | ||
| 2890 | vldbmod = 1; | ||
| 2891 | } | ||
| 2892 | |||
| 2893 | /* Now go back to the backup volume and bring it on line */ | ||
| 2894 | code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline1, &btid); | ||
| 2895 | if (code) { | ||
| 2896 | fprintf(STDERR__stderrp, | ||
| 2897 | "Failed to start a transaction on the backup volume %lu\n", | ||
| 2898 | (unsigned long)backupID); | ||
| 2899 | error = code; | ||
| 2900 | goto bfail; | ||
| 2901 | } | ||
| 2902 | |||
| 2903 | code = AFSVolSetFlags(aconn, btid, 0); | ||
| 2904 | if (code) { | ||
| 2905 | fprintf(STDERR__stderrp, "Could not mark the backup volume %lu on line \n", | ||
| 2906 | (unsigned long)backupID); | ||
| 2907 | error = code; | ||
| 2908 | goto bfail; | ||
| 2909 | } | ||
| 2910 | |||
| 2911 | code = AFSVolEndTrans(aconn, btid, &rcode); | ||
| 2912 | btid = 0; | ||
| 2913 | if (code || rcode) { | ||
| 2914 | fprintf(STDERR__stderrp, | ||
| 2915 | "Failed to end the transaction on the backup volume %lu\n", | ||
| 2916 | (unsigned long)backupID); | ||
| 2917 | error = (code ? code : rcode); | ||
| 2918 | goto bfail; | ||
| 2919 | } | ||
| 2920 | |||
| 2921 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 2922 | |||
| 2923 | /* Will update the vldb below */ | ||
| 2924 | |||
| 2925 | bfail: | ||
| 2926 | if (ttid) { | ||
| 2927 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 2928 | if (code || rcode) { | ||
| 2929 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %lu\n", | ||
| 2930 | (unsigned long)avolid); | ||
| 2931 | if (!error) | ||
| 2932 | error = (code ? code : rcode); | ||
| 2933 | } | ||
| 2934 | } | ||
| 2935 | |||
| 2936 | if (btid) { | ||
| 2937 | code = AFSVolEndTrans(aconn, btid, &rcode); | ||
| 2938 | if (code || rcode) { | ||
| 2939 | fprintf(STDERR__stderrp, | ||
| 2940 | "Could not end transaction the backup volume %lu\n", | ||
| 2941 | (unsigned long)backupID); | ||
| 2942 | if (!error) | ||
| 2943 | error = (code ? code : rcode); | ||
| 2944 | } | ||
| 2945 | } | ||
| 2946 | |||
| 2947 | /* Now update the vldb - if modified */ | ||
| 2948 | if (vldblocked) { | ||
| 2949 | if (vldbmod) { | ||
| 2950 | MapNetworkToHost(&entry, &storeEntry); | ||
| 2951 | code = | ||
| 2952 | VLDB_ReplaceEntry(avolid, RWVOL0, &storeEntry, | ||
| 2953 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 2954 | LOCKREL_TIMESTAMP1)); | ||
| 2955 | if (code) { | ||
| 2956 | fprintf(STDERR__stderrp, | ||
| 2957 | "Could not update the VLDB entry for the volume %lu \n", | ||
| 2958 | (unsigned long)avolid); | ||
| 2959 | if (!error) | ||
| 2960 | error = code; | ||
| 2961 | } | ||
| 2962 | } else { | ||
| 2963 | code = | ||
| 2964 | ubik_VL_ReleaseLock(cstruct, 0, avolid, RWVOL0, | ||
| 2965 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 2966 | LOCKREL_TIMESTAMP1)); | ||
| 2967 | if (code) { | ||
| 2968 | fprintf(STDERR__stderrp, | ||
| 2969 | "Could not unlock the VLDB entry for the volume %lu \n", | ||
| 2970 | (unsigned long)avolid); | ||
| 2971 | if (!error) | ||
| 2972 | error = code; | ||
| 2973 | } | ||
| 2974 | } | ||
| 2975 | } | ||
| 2976 | |||
| 2977 | if (aconn) | ||
| 2978 | rx_DestroyConnection(aconn); | ||
| 2979 | |||
| 2980 | PrintError("", error); | ||
| 2981 | return error; | ||
| 2982 | } | ||
| 2983 | |||
| 2984 | /* Make a new clone of volume <avolid> on <aserver> and <apart> | ||
| 2985 | * using volume ID <acloneid>, or a new ID allocated from the VLDB. | ||
| 2986 | * The new volume is named by <aname>, or by appending ".clone" to | ||
| 2987 | * the existing name if <aname> is NULL. The following flags are | ||
| 2988 | * supported: | ||
| 2989 | * | ||
| 2990 | * RV_RDONLY - target volume is RO | ||
| 2991 | * RV_OFFLINE - leave target volume offline | ||
| 2992 | */ | ||
| 2993 | |||
| 2994 | int | ||
| 2995 | UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid, | ||
| 2996 | afs_uint32 acloneid, char *aname, int flags) | ||
| 2997 | { | ||
| 2998 | struct rx_connection *aconn = (struct rx_connection *)0; | ||
| 2999 | afs_int32 ttid = 0, btid = 0; | ||
| 3000 | afs_int32 code = 0, rcode = 0; | ||
| 3001 | char vname[VOLSER_MAXVOLNAME65 + 1]; | ||
| 3002 | afs_int32 error = 0; | ||
| 3003 | int backexists = 1; | ||
| 3004 | volEntries volumeInfo; | ||
| 3005 | |||
| 3006 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 3007 | |||
| 3008 | if (!aname) { | ||
| 3009 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 3010 | volumeInfo.volEntries_len = 0; | ||
| 3011 | code = AFSVolListOneVolume(aconn, apart, avolid, &volumeInfo); | ||
| 3012 | if (code) { | ||
| 3013 | fprintf(stderr__stderrp, "Could not get info for volume %lu\n", | ||
| 3014 | (unsigned long)avolid); | ||
| 3015 | error = code; | ||
| 3016 | goto bfail; | ||
| 3017 | } | ||
| 3018 | strncpy(vname, volumeInfo.volEntries_val[0].name, | ||
| 3019 | VOLSER_OLDMAXVOLNAME32 - 7); | ||
| 3020 | vname[VOLSER_OLDMAXVOLNAME32 - 7] = 0; | ||
| 3021 | strcat(vname, ".clone"); | ||
| 3022 | aname = vname; | ||
| 3023 | if (volumeInfo.volEntries_val) | ||
| 3024 | free(volumeInfo.volEntries_val); | ||
| 3025 | } | ||
| 3026 | |||
| 3027 | if (!acloneid) { | ||
| 3028 | /* Get a clone id */ | ||
| 3029 | VPRINT1("Allocating new volume id for clone of volume %u ...",{ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for clone of volume %u ..." ), (avolid)); fflush(__stdoutp); } } | ||
| 3030 | avolid){ if (verbose) { fprintf(__stdoutp, ("Allocating new volume id for clone of volume %u ..." ), (avolid)); fflush(__stdoutp); } }; | ||
| 3031 | code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &acloneid); | ||
| 3032 | EGOTO1(bfail, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((avolid))); PrintError(" ",(code)); } while (0); error = (code); goto bfail; } } while (0) | ||
| 3033 | "Could not get an ID for the clone of volume %u from the VLDB\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((avolid))); PrintError(" ",(code)); } while (0); error = (code); goto bfail; } } while (0) | ||
| 3034 | avolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((avolid))); PrintError(" ",(code)); } while (0); error = (code); goto bfail; } } while (0); | ||
| 3035 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3036 | } | ||
| 3037 | |||
| 3038 | /* Test to see if the clone volume exists by trying to create | ||
| 3039 | * a transaction on the clone volume. We've assumed the clone exists. | ||
| 3040 | */ | ||
| 3041 | /* XXX I wonder what happens if the clone has some other parent... */ | ||
| 3042 | code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline1, &btid); | ||
| 3043 | if (code) { | ||
| 3044 | if (code != VNOVOL103) { | ||
| 3045 | fprintf(STDERR__stderrp, "Could not reach the clone volume %lu\n", | ||
| 3046 | (unsigned long)acloneid); | ||
| 3047 | error = code; | ||
| 3048 | goto bfail; | ||
| 3049 | } | ||
| 3050 | backexists = 0; /* backup volume does not exist */ | ||
| 3051 | } | ||
| 3052 | if (btid) { | ||
| 3053 | code = AFSVolEndTrans(aconn, btid, &rcode); | ||
| 3054 | btid = 0; | ||
| 3055 | if (code || rcode) { | ||
| 3056 | fprintf(STDERR__stderrp, | ||
| 3057 | "Could not end transaction on the previous clone volume %lu\n", | ||
| 3058 | (unsigned long)acloneid); | ||
| 3059 | error = (code ? code : rcode); | ||
| 3060 | goto bfail; | ||
| 3061 | } | ||
| 3062 | } | ||
| 3063 | |||
| 3064 | /* Now go ahead and try to clone the RW volume. | ||
| 3065 | * First start a transaction on the RW volume | ||
| 3066 | */ | ||
| 3067 | code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy2, &ttid); | ||
| 3068 | if (code) { | ||
| 3069 | fprintf(STDERR__stderrp, "Could not start a transaction on the volume %lu\n", | ||
| 3070 | (unsigned long)avolid); | ||
| 3071 | error = code; | ||
| 3072 | goto bfail; | ||
| 3073 | } | ||
| 3074 | |||
| 3075 | /* Clone or reclone the volume, depending on whether the backup | ||
| 3076 | * volume exists or not | ||
| 3077 | */ | ||
| 3078 | if (backexists) { | ||
| 3079 | VPRINT1("Re-cloning clone volume %u ...", acloneid){ if (verbose) { fprintf(__stdoutp, ("Re-cloning clone volume %u ..." ), (acloneid)); fflush(__stdoutp); } }; | ||
| 3080 | |||
| 3081 | code = AFSVolReClone(aconn, ttid, acloneid); | ||
| 3082 | if (code) { | ||
| 3083 | fprintf(STDERR__stderrp, "Could not re-clone backup volume %lu\n", | ||
| 3084 | (unsigned long)acloneid); | ||
| 3085 | error = code; | ||
| 3086 | goto bfail; | ||
| 3087 | } | ||
| 3088 | } else { | ||
| 3089 | VPRINT1("Creating a new clone %u ...", acloneid){ if (verbose) { fprintf(__stdoutp, ("Creating a new clone %u ..." ), (acloneid)); fflush(__stdoutp); } }; | ||
| 3090 | |||
| 3091 | code = AFSVolClone(aconn, ttid, 0, | ||
| 3092 | (flags & RV_RDONLY0x010000) ? readonlyVolume1 : backupVolume2, | ||
| 3093 | aname, &acloneid); | ||
| 3094 | if (code) { | ||
| 3095 | fprintf(STDERR__stderrp, "Failed to clone the volume %lu\n", | ||
| 3096 | (unsigned long)avolid); | ||
| 3097 | error = code; | ||
| 3098 | goto bfail; | ||
| 3099 | } | ||
| 3100 | } | ||
| 3101 | |||
| 3102 | /* End the transaction on the RW volume */ | ||
| 3103 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 3104 | ttid = 0; | ||
| 3105 | if (code || rcode) { | ||
| 3106 | fprintf(STDERR__stderrp, | ||
| 3107 | "Failed to end the transaction on the rw volume %lu\n", | ||
| 3108 | (unsigned long)avolid); | ||
| 3109 | error = (code ? code : rcode); | ||
| 3110 | goto bfail; | ||
| 3111 | } | ||
| 3112 | |||
| 3113 | /* Now go back to the backup volume and bring it on line */ | ||
| 3114 | if (!(flags & RV_OFFLINE0x000002)) { | ||
| 3115 | code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline1, &btid); | ||
| 3116 | if (code) { | ||
| 3117 | fprintf(STDERR__stderrp, | ||
| 3118 | "Failed to start a transaction on the clone volume %lu\n", | ||
| 3119 | (unsigned long)acloneid); | ||
| 3120 | error = code; | ||
| 3121 | goto bfail; | ||
| 3122 | } | ||
| 3123 | |||
| 3124 | code = AFSVolSetFlags(aconn, btid, 0); | ||
| 3125 | if (code) { | ||
| 3126 | fprintf(STDERR__stderrp, "Could not mark the clone volume %lu on line \n", | ||
| 3127 | (unsigned long)acloneid); | ||
| 3128 | error = code; | ||
| 3129 | goto bfail; | ||
| 3130 | } | ||
| 3131 | |||
| 3132 | code = AFSVolEndTrans(aconn, btid, &rcode); | ||
| 3133 | btid = 0; | ||
| 3134 | if (code || rcode) { | ||
| 3135 | fprintf(STDERR__stderrp, | ||
| 3136 | "Failed to end the transaction on the clone volume %lu\n", | ||
| 3137 | (unsigned long)acloneid); | ||
| 3138 | error = (code ? code : rcode); | ||
| 3139 | goto bfail; | ||
| 3140 | } | ||
| 3141 | } | ||
| 3142 | |||
| 3143 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3144 | |||
| 3145 | bfail: | ||
| 3146 | if (ttid) { | ||
| 3147 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 3148 | if (code || rcode) { | ||
| 3149 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %lu\n", | ||
| 3150 | (unsigned long)avolid); | ||
| 3151 | if (!error) | ||
| 3152 | error = (code ? code : rcode); | ||
| 3153 | } | ||
| 3154 | } | ||
| 3155 | |||
| 3156 | if (btid) { | ||
| 3157 | code = AFSVolEndTrans(aconn, btid, &rcode); | ||
| 3158 | if (code || rcode) { | ||
| 3159 | fprintf(STDERR__stderrp, | ||
| 3160 | "Could not end transaction on the clone volume %lu\n", | ||
| 3161 | (unsigned long)acloneid); | ||
| 3162 | if (!error) | ||
| 3163 | error = (code ? code : rcode); | ||
| 3164 | } | ||
| 3165 | } | ||
| 3166 | |||
| 3167 | if (aconn) | ||
| 3168 | rx_DestroyConnection(aconn); | ||
| 3169 | |||
| 3170 | PrintError("", error); | ||
| 3171 | return error; | ||
| 3172 | } | ||
| 3173 | |||
| 3174 | static int | ||
| 3175 | DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part, | ||
| 3176 | afs_int32 flags) | ||
| 3177 | { | ||
| 3178 | afs_int32 acode, ccode, rcode, tid; | ||
| 3179 | ccode = rcode = tid = 0; | ||
| 3180 | |||
| 3181 | acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid); | ||
| 3182 | if (!acode) { /* It really was there */ | ||
| 3183 | acode = AFSVolDeleteVolume(conn, tid); | ||
| 3184 | if (acode) { | ||
| 3185 | fprintf(STDERR__stderrp, "Failed to delete volume %lu.\n", | ||
| 3186 | (unsigned long)vid); | ||
| 3187 | PrintError("", acode); | ||
| 3188 | } | ||
| 3189 | ccode = AFSVolEndTrans(conn, tid, &rcode); | ||
| 3190 | if (!ccode) | ||
| 3191 | ccode = rcode; | ||
| 3192 | if (ccode) { | ||
| 3193 | fprintf(STDERR__stderrp, "Failed to end transaction on volume %lu.\n", | ||
| 3194 | (unsigned long)vid); | ||
| 3195 | PrintError("", ccode); | ||
| 3196 | } | ||
| 3197 | } | ||
| 3198 | |||
| 3199 | return acode; | ||
| 3200 | } | ||
| 3201 | |||
| 3202 | #define ONERROR(ec, ep, es)do { if (ec) { fprintf(__stderrp, (es), (ep)); error = (ec); goto rfail; } } while (0) do { \ | ||
| 3203 | if (ec) { \ | ||
| 3204 | fprintf(STDERR__stderrp, (es), (ep)); \ | ||
| 3205 | error = (ec); \ | ||
| 3206 | goto rfail; \ | ||
| 3207 | } \ | ||
| 3208 | } while (0) | ||
| 3209 | #define ONERROR0(ec, es)do { if (ec) { fprintf(__stderrp, (es)); error = (ec); goto rfail ; } } while (0) do { \ | ||
| 3210 | if (ec) { \ | ||
| 3211 | fprintf(STDERR__stderrp, (es)); \ | ||
| 3212 | error = (ec); \ | ||
| 3213 | goto rfail; \ | ||
| 3214 | } \ | ||
| 3215 | } while (0) | ||
| 3216 | #define ERROREXIT(ec)do { error = (ec); goto rfail; } while (0) do { \ | ||
| 3217 | error = (ec); \ | ||
| 3218 | goto rfail; \ | ||
| 3219 | } while (0) | ||
| 3220 | |||
| 3221 | /* Get a "transaction" on this replica. Create the volume | ||
| 3222 | * if necessary. Return the time from which a dump should | ||
| 3223 | * be made (0 if it's a new volume) | ||
| 3224 | */ | ||
| 3225 | static int | ||
| 3226 | GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index, | ||
| 3227 | struct rx_connection **connPtr, afs_int32 * transPtr, | ||
| 3228 | afs_uint32 * crtimePtr, afs_uint32 * uptimePtr, | ||
| 3229 | afs_int32 *origflags) | ||
| 3230 | { | ||
| 3231 | afs_uint32 volid; | ||
| 3232 | struct volser_status tstatus; | ||
| 3233 | int code = 0; | ||
| 3234 | int rcode, tcode; | ||
| 3235 | char hoststr[16]; | ||
| 3236 | |||
| 3237 | *connPtr = (struct rx_connection *)0; | ||
| 3238 | *transPtr = 0; | ||
| 3239 | *crtimePtr = 0; | ||
| 3240 | *uptimePtr = 0; | ||
| 3241 | |||
| 3242 | /* get connection to the replication site */ | ||
| 3243 | *connPtr = UV_Bind(vldbEntryPtr->serverNumber[index], AFSCONF_VOLUMEPORT7005); | ||
| 3244 | if (!*connPtr) | ||
| 3245 | goto fail; /* server is down */ | ||
| 3246 | |||
| 3247 | volid = vldbEntryPtr->volumeId[ROVOL1]; | ||
| 3248 | if (volid) { | ||
| 3249 | code = | ||
| 3250 | AFSVolTransCreate_retry(*connPtr, volid, | ||
| 3251 | vldbEntryPtr->serverPartition[index], ITOffline1, | ||
| 3252 | transPtr); | ||
| 3253 | |||
| 3254 | if (!code && (origflags[index] & RO_DONTUSE0x20)) { | ||
| 3255 | /* If RO_DONTUSE is set, this is supposed to be an entirely new | ||
| 3256 | * site. Don't trust any data on it, since it is possible we | ||
| 3257 | * have encountered some temporary volume from some other | ||
| 3258 | * incomplete volume operation. It is difficult to detect if | ||
| 3259 | * that has happened vs if this is a legit volume, so just | ||
| 3260 | * delete it to be safe. */ | ||
| 3261 | |||
| 3262 | VPRINT1("Deleting extant RO_DONTUSE site on %s...",{ if (verbose) { fprintf(__stdoutp, ("Deleting extant RO_DONTUSE site on %s..." ), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr-> serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3263 | noresolve ? afs_inet_ntoa_r(vldbEntryPtr->{ if (verbose) { fprintf(__stdoutp, ("Deleting extant RO_DONTUSE site on %s..." ), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr-> serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3264 | serverNumber[index], hoststr) :{ if (verbose) { fprintf(__stdoutp, ("Deleting extant RO_DONTUSE site on %s..." ), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr-> serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3265 | hostutil_GetNameByINet(vldbEntryPtr->{ if (verbose) { fprintf(__stdoutp, ("Deleting extant RO_DONTUSE site on %s..." ), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr-> serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3266 | serverNumber[index])){ if (verbose) { fprintf(__stdoutp, ("Deleting extant RO_DONTUSE site on %s..." ), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr-> serverNumber [index]))); fflush(__stdoutp); } }; | ||
| 3267 | |||
| 3268 | code = AFSVolDeleteVolume(*connPtr, *transPtr); | ||
| 3269 | if (code) { | ||
| 3270 | PrintError("Failed to delete RO_DONTUSE site: ", code); | ||
| 3271 | goto fail; | ||
| 3272 | } | ||
| 3273 | |||
| 3274 | tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode); | ||
| 3275 | *transPtr = 0; | ||
| 3276 | if (!tcode) { | ||
| 3277 | tcode = rcode; | ||
| 3278 | } | ||
| 3279 | if (tcode) { | ||
| 3280 | PrintError("Failed to end transaction on RO_DONTUSE site: ", | ||
| 3281 | tcode); | ||
| 3282 | goto fail; | ||
| 3283 | } | ||
| 3284 | |||
| 3285 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3286 | |||
| 3287 | /* emulate what TransCreate would have returned, so we try to | ||
| 3288 | * create the volume below */ | ||
| 3289 | code = VNOVOL103; | ||
| 3290 | } | ||
| 3291 | } | ||
| 3292 | |||
| 3293 | /* If the volume does not exist, create it */ | ||
| 3294 | if (!volid || code) { | ||
| 3295 | char volname[64]; | ||
| 3296 | char hoststr[16]; | ||
| 3297 | |||
| 3298 | if (volid && (code != VNOVOL103)) { | ||
| 3299 | PrintError("Failed to start a transaction on the RO volume.\n", | ||
| 3300 | code); | ||
| 3301 | goto fail; | ||
| 3302 | } | ||
| 3303 | |||
| 3304 | strcpy(volname, vldbEntryPtr->name); | ||
| 3305 | strcat(volname, ".readonly"); | ||
| 3306 | |||
| 3307 | if (verbose) { | ||
| 3308 | fprintf(STDOUT__stdoutp, | ||
| 3309 | "Creating new volume %lu on replication site %s: ", | ||
| 3310 | (unsigned long)volid, | ||
| 3311 | noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> | ||
| 3312 | serverNumber[index], hoststr) : | ||
| 3313 | hostutil_GetNameByINet(vldbEntryPtr-> | ||
| 3314 | serverNumber[index])); | ||
| 3315 | fflush(STDOUT__stdoutp); | ||
| 3316 | } | ||
| 3317 | |||
| 3318 | code = | ||
| 3319 | AFSVolCreateVolume(*connPtr, vldbEntryPtr->serverPartition[index], | ||
| 3320 | volname, volser_RO1, | ||
| 3321 | vldbEntryPtr->volumeId[RWVOL0], &volid, | ||
| 3322 | transPtr); | ||
| 3323 | if (code) { | ||
| 3324 | PrintError("Failed to create the ro volume: ", code); | ||
| 3325 | goto fail; | ||
| 3326 | } | ||
| 3327 | vldbEntryPtr->volumeId[ROVOL1] = volid; | ||
| 3328 | |||
| 3329 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3330 | |||
| 3331 | /* The following is a bit redundant, since create sets these flags by default */ | ||
| 3332 | code = | ||
| 3333 | AFSVolSetFlags(*connPtr, *transPtr, | ||
| 3334 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 3335 | if (code) { | ||
| 3336 | PrintError("Failed to set flags on the ro volume: ", code); | ||
| 3337 | goto fail; | ||
| 3338 | } | ||
| 3339 | } | ||
| 3340 | |||
| 3341 | /* Otherwise, the transaction did succeed, so get the creation date of the | ||
| 3342 | * latest RO volume on the replication site | ||
| 3343 | */ | ||
| 3344 | else { | ||
| 3345 | VPRINT2("Updating existing ro volume %u on %s ...\n", volid,{ if (verbose) { fprintf(__stdoutp, ("Updating existing ro volume %u on %s ...\n" ), (volid), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr->serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3346 | noresolve ? afs_inet_ntoa_r(vldbEntryPtr->{ if (verbose) { fprintf(__stdoutp, ("Updating existing ro volume %u on %s ...\n" ), (volid), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr->serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3347 | serverNumber[index], hoststr) :{ if (verbose) { fprintf(__stdoutp, ("Updating existing ro volume %u on %s ...\n" ), (volid), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr->serverNumber [index]))); fflush(__stdoutp); } } | ||
| 3348 | hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index])){ if (verbose) { fprintf(__stdoutp, ("Updating existing ro volume %u on %s ...\n" ), (volid), (noresolve ? afs_inet_ntoa_r(vldbEntryPtr-> serverNumber [index], hoststr) : hostutil_GetNameByINet(vldbEntryPtr->serverNumber [index]))); fflush(__stdoutp); } }; | ||
| 3349 | |||
| 3350 | code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus); | ||
| 3351 | if (code) { | ||
| 3352 | PrintError("Failed to get status of volume on destination: ", | ||
| 3353 | code); | ||
| 3354 | goto fail; | ||
| 3355 | } | ||
| 3356 | *crtimePtr = CLOCKADJ(tstatus.creationDate)(((tstatus.creationDate) < 2) ? 0 : (tstatus.creationDate) - 2); | ||
| 3357 | *uptimePtr = CLOCKADJ(tstatus.updateDate)(((tstatus.updateDate) < 2) ? 0 : (tstatus.updateDate) - 2 ); | ||
| 3358 | } | ||
| 3359 | |||
| 3360 | return 0; | ||
| 3361 | |||
| 3362 | fail: | ||
| 3363 | if (*transPtr) { | ||
| 3364 | tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode); | ||
| 3365 | *transPtr = 0; | ||
| 3366 | if (!tcode) | ||
| 3367 | tcode = rcode; | ||
| 3368 | if (tcode) | ||
| 3369 | PrintError("Could not end transaction on a ro volume: ", tcode); | ||
| 3370 | } | ||
| 3371 | |||
| 3372 | return code; | ||
| 3373 | } | ||
| 3374 | |||
| 3375 | static int | ||
| 3376 | SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid, | ||
| 3377 | afs_int32 fromdate, manyDests * tr, afs_int32 flags, | ||
| 3378 | void *cookie, manyResults * results) | ||
| 3379 | { | ||
| 3380 | unsigned int i; | ||
| 3381 | |||
| 3382 | for (i = 0; i < tr->manyDests_len; i++) { | ||
| 3383 | results->manyResults_val[i] = | ||
| 3384 | AFSVolForward(fromconn, fromtid, fromdate, | ||
| 3385 | &(tr->manyDests_val[i].server), | ||
| 3386 | tr->manyDests_val[i].trans, cookie); | ||
| 3387 | } | ||
| 3388 | return 0; | ||
| 3389 | } | ||
| 3390 | |||
| 3391 | /** | ||
| 3392 | * Check if a trans has timed out, and recreate it if necessary. | ||
| 3393 | * | ||
| 3394 | * @param[in] aconn RX connection to the relevant server | ||
| 3395 | * @param[inout] atid Transaction ID to check; if we recreated the trans, | ||
| 3396 | * contains the new trans ID on success | ||
| 3397 | * @param[in] apart Partition for the transaction | ||
| 3398 | * @param[in] astat The status of the original transaction | ||
| 3399 | * | ||
| 3400 | * @return operation status | ||
| 3401 | * @retval 0 existing transaction is still valid, or we managed to recreate | ||
| 3402 | * the trans successfully | ||
| 3403 | * @retval nonzero Fatal error; bail out | ||
| 3404 | */ | ||
| 3405 | static int | ||
| 3406 | CheckTrans(struct rx_connection *aconn, afs_int32 *atid, afs_int32 apart, | ||
| 3407 | struct volser_status *astat) | ||
| 3408 | { | ||
| 3409 | struct volser_status new_status; | ||
| 3410 | afs_int32 code; | ||
| 3411 | |||
| 3412 | memset(&new_status, 0, sizeof(new_status)); | ||
| 3413 | code = AFSVolGetStatus(aconn, *atid, &new_status); | ||
| 3414 | if (code) { | ||
| 3415 | if (code == ENOENT2) { | ||
| 3416 | *atid = 0; | ||
| 3417 | VPRINT1("Old transaction on cloned volume %lu timed out, "{ if (verbose) { fprintf(__stdoutp, ("Old transaction on cloned volume %lu timed out, " "restarting transaction\n"), ((long unsigned) astat->volID )); fflush(__stdoutp); } } | ||
| 3418 | "restarting transaction\n", (long unsigned) astat->volID){ if (verbose) { fprintf(__stdoutp, ("Old transaction on cloned volume %lu timed out, " "restarting transaction\n"), ((long unsigned) astat->volID )); fflush(__stdoutp); } }; | ||
| 3419 | code = AFSVolTransCreate_retry(aconn, astat->volID, apart, | ||
| 3420 | ITBusy2, atid); | ||
| 3421 | if (code) { | ||
| 3422 | PrintError("Failed to recreate cloned RO volume transaction\n", | ||
| 3423 | code); | ||
| 3424 | return 1; | ||
| 3425 | } | ||
| 3426 | |||
| 3427 | memset(&new_status, 0, sizeof(new_status)); | ||
| 3428 | code = AFSVolGetStatus(aconn, *atid, &new_status); | ||
| 3429 | if (code) { | ||
| 3430 | PrintError("Failed to get status on recreated transaction\n", | ||
| 3431 | code); | ||
| 3432 | return 1; | ||
| 3433 | } | ||
| 3434 | |||
| 3435 | if (memcmp(&new_status, astat, sizeof(new_status)) != 0) { | ||
| 3436 | PrintError("Recreated transaction on cloned RO volume, but " | ||
| 3437 | "the volume has changed!\n", 0); | ||
| 3438 | return 1; | ||
| 3439 | } | ||
| 3440 | } else { | ||
| 3441 | PrintError("Unable to get status of current cloned RO transaction\n", | ||
| 3442 | code); | ||
| 3443 | return 1; | ||
| 3444 | } | ||
| 3445 | } else { | ||
| 3446 | if (memcmp(&new_status, astat, sizeof(new_status)) != 0) { | ||
| 3447 | /* sanity check */ | ||
| 3448 | PrintError("Internal error: current GetStatus does not match " | ||
| 3449 | "original GetStatus?\n", 0); | ||
| 3450 | return 1; | ||
| 3451 | } | ||
| 3452 | } | ||
| 3453 | |||
| 3454 | return 0; | ||
| 3455 | } | ||
| 3456 | |||
| 3457 | |||
| 3458 | /* UV_ReleaseVolume() | ||
| 3459 | * Release volume <afromvol> on <afromserver> <afrompart> to all | ||
| 3460 | * its RO sites (full release). Unless the previous release was | ||
| 3461 | * incomplete: in which case we bring the remaining incomplete | ||
| 3462 | * volumes up to date with the volumes that were released | ||
| 3463 | * successfully. | ||
| 3464 | * forceflag: Performs a full release. | ||
| 3465 | * | ||
| 3466 | * Will create a clone from the RW, then dump the clone out to | ||
| 3467 | * the remaining replicas. If there is more than 1 RO sites, | ||
| 3468 | * ensure that the VLDB says at least one RO is available all | ||
| 3469 | * the time: Influences when we write back the VLDB entry. | ||
| 3470 | */ | ||
| 3471 | |||
| 3472 | int | ||
| 3473 | UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver, | ||
| 3474 | afs_int32 afrompart, int forceflag) | ||
| 3475 | { | ||
| 3476 | char vname[64]; | ||
| 3477 | afs_int32 code = 0; | ||
| 3478 | afs_int32 vcode, rcode, tcode; | ||
| 3479 | afs_uint32 cloneVolId, roVolId; | ||
| 3480 | struct replica *replicas = 0; | ||
| 3481 | struct nvldbentry entry, storeEntry; | ||
| 3482 | int i, volcount, m, fullrelease, vldbindex; | ||
| 3483 | int failure; | ||
| 3484 | struct restoreCookie cookie; | ||
| 3485 | struct rx_connection **toconns = 0; | ||
| 3486 | struct release *times = 0; | ||
| 3487 | int nservers = 0; | ||
| 3488 | struct rx_connection *fromconn = (struct rx_connection *)0; | ||
| 3489 | afs_int32 error = 0; | ||
| 3490 | int islocked = 0; | ||
| 3491 | afs_int32 clonetid = 0, onlinetid; | ||
| 3492 | afs_int32 fromtid = 0; | ||
| 3493 | afs_uint32 fromdate = 0; | ||
| 3494 | afs_uint32 thisdate; | ||
| 3495 | time_t tmv; | ||
| 3496 | int s; | ||
| 3497 | manyDests tr; | ||
| 3498 | manyResults results; | ||
| 3499 | int rwindex, roindex, roclone, roexists; | ||
| 3500 | afs_uint32 rwcrdate = 0; | ||
| 3501 | afs_uint32 clcrdate; | ||
| 3502 | struct rtime { | ||
| 3503 | int validtime; | ||
| 3504 | afs_uint32 uptime; | ||
| 3505 | } remembertime[NMAXNSERVERS13]; | ||
| 3506 | int releasecount = 0; | ||
| 3507 | struct volser_status volstatus; | ||
| 3508 | char hoststr[16]; | ||
| 3509 | afs_int32 origflags[NMAXNSERVERS13]; | ||
| 3510 | struct volser_status orig_status; | ||
| 3511 | |||
| 3512 | memset(remembertime, 0, sizeof(remembertime)); | ||
| 3513 | memset(&results, 0, sizeof(results)); | ||
| 3514 | memset(origflags, 0, sizeof(origflags)); | ||
| 3515 | |||
| 3516 | vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL0, VLOP_RELEASE0x20); | ||
| 3517 | if (vcode != VL_RERELEASE(363544L)) | ||
| 3518 | ONERROR(vcode, afromvol,do { if (vcode) { fprintf(__stderrp, ("Could not lock the VLDB entry for the volume %u.\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0) | ||
| 3519 | "Could not lock the VLDB entry for the volume %u.\n")do { if (vcode) { fprintf(__stderrp, ("Could not lock the VLDB entry for the volume %u.\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0); | ||
| 3520 | islocked = 1; | ||
| 3521 | |||
| 3522 | /* Get the vldb entry in readable format */ | ||
| 3523 | vcode = VLDB_GetEntryByID(afromvol, RWVOL0, &entry); | ||
| 3524 | ONERROR(vcode, afromvol,do { if (vcode) { fprintf(__stderrp, ("Could not fetch the entry for the volume %u from the VLDB.\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0) | ||
| 3525 | "Could not fetch the entry for the volume %u from the VLDB.\n")do { if (vcode) { fprintf(__stderrp, ("Could not fetch the entry for the volume %u from the VLDB.\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0); | ||
| 3526 | MapHostToNetwork(&entry); | ||
| 3527 | |||
| 3528 | if (verbose) | ||
| 3529 | EnumerateEntry(&entry); | ||
| 3530 | |||
| 3531 | if (!ISNAMEVALID(entry.name)(strlen(entry.name) < (32 - 9))) | ||
| 3532 | ONERROR(VOLSERBADOP, entry.name,do { if ((1492325131L)) { fprintf(__stderrp, ("Volume name %s is too long, rename before releasing.\n" ), (entry.name)); error = ((1492325131L)); goto rfail; } } while (0) | ||
| 3533 | "Volume name %s is too long, rename before releasing.\n")do { if ((1492325131L)) { fprintf(__stderrp, ("Volume name %s is too long, rename before releasing.\n" ), (entry.name)); error = ((1492325131L)); goto rfail; } } while (0); | ||
| 3534 | if (entry.volumeId[RWVOL0] != afromvol) | ||
| 3535 | ONERROR(VOLSERBADOP, afromvol,do { if ((1492325131L)) { fprintf(__stderrp, ("The volume %u being released is not a read-write volume.\n" ), (afromvol)); error = ((1492325131L)); goto rfail; } } while (0) | ||
| 3536 | "The volume %u being released is not a read-write volume.\n")do { if ((1492325131L)) { fprintf(__stderrp, ("The volume %u being released is not a read-write volume.\n" ), (afromvol)); error = ((1492325131L)); goto rfail; } } while (0); | ||
| 3537 | if (entry.nServers <= 1) | ||
| 3538 | ONERROR(VOLSERBADOP, afromvol,do { if ((1492325131L)) { fprintf(__stderrp, ("Volume %u has no replicas - release operation is meaningless!\n" ), (afromvol)); error = ((1492325131L)); goto rfail; } } while (0) | ||
| 3539 | "Volume %u has no replicas - release operation is meaningless!\n")do { if ((1492325131L)) { fprintf(__stderrp, ("Volume %u has no replicas - release operation is meaningless!\n" ), (afromvol)); error = ((1492325131L)); goto rfail; } } while (0); | ||
| 3540 | if (strlen(entry.name) > (VOLSER_OLDMAXVOLNAME32 - 10)) | ||
| 3541 | ONERROR(VOLSERBADOP, entry.name,do { if ((1492325131L)) { fprintf(__stderrp, ("RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n" ), (entry.name)); error = ((1492325131L)); goto rfail; } } while (0) | ||
| 3542 | "RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n")do { if ((1492325131L)) { fprintf(__stderrp, ("RO volume name %s exceeds (VOLSER_OLDMAXVOLNAME - 10) character limit\n" ), (entry.name)); error = ((1492325131L)); goto rfail; } } while (0); | ||
| 3543 | |||
| 3544 | /* roclone is true if one of the RO volumes is on the same | ||
| 3545 | * partition as the RW volume. In this case, we make the RO volume | ||
| 3546 | * on the same partition a clone instead of a complete copy. | ||
| 3547 | */ | ||
| 3548 | |||
| 3549 | roindex = Lp_ROMatch(afromserver, afrompart, &entry) - 1; | ||
| 3550 | roclone = ((roindex == -1) ? 0 : 1); | ||
| 3551 | rwindex = Lp_GetRwIndex(&entry); | ||
| 3552 | if (rwindex < 0) | ||
| 3553 | ONERROR0(VOLSERNOVOL, "There is no RW volume \n")do { if ((1492325135L)) { fprintf(__stderrp, ("There is no RW volume \n" )); error = ((1492325135L)); goto rfail; } } while (0); | ||
| 3554 | |||
| 3555 | /* Make sure we have a RO volume id to work with */ | ||
| 3556 | if (entry.volumeId[ROVOL1] == INVALID_BID0) { | ||
| 3557 | /* need to get a new RO volume id */ | ||
| 3558 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &roVolId); | ||
| 3559 | ONERROR(vcode, entry.name, "Cant allocate ID for RO volume of %s\n")do { if (vcode) { fprintf(__stderrp, ("Cant allocate ID for RO volume of %s\n" ), (entry.name)); error = (vcode); goto rfail; } } while (0); | ||
| 3560 | |||
| 3561 | entry.volumeId[ROVOL1] = roVolId; | ||
| 3562 | MapNetworkToHost(&entry, &storeEntry); | ||
| 3563 | vcode = VLDB_ReplaceEntry(afromvol, RWVOL0, &storeEntry, 0); | ||
| 3564 | ONERROR(vcode, entry.name, "Could not update vldb entry for %s.\n")do { if (vcode) { fprintf(__stderrp, ("Could not update vldb entry for %s.\n" ), (entry.name)); error = (vcode); goto rfail; } } while (0); | ||
| 3565 | } | ||
| 3566 | |||
| 3567 | /* Will we be completing a previously unfinished release. -force overrides */ | ||
| 3568 | for (s = 0, m = 0, fullrelease=0, i=0; (i<entry.nServers); i++) { | ||
| 3569 | if (entry.serverFlags[i] & ITSROVOL0x02) { | ||
| 3570 | m++; | ||
| 3571 | if (entry.serverFlags[i] & NEW_REPSITE0x01) s++; | ||
| 3572 | } | ||
| 3573 | origflags[i] = entry.serverFlags[i]; | ||
| 3574 | } | ||
| 3575 | if ((forceflag && !fullrelease) || (s == m) || (s == 0)) | ||
| 3576 | fullrelease = 1; | ||
| 3577 | |||
| 3578 | /* Determine which volume id to use and see if it exists */ | ||
| 3579 | cloneVolId = | ||
| 3580 | ((fullrelease | ||
| 3581 | || (entry.cloneId == 0)) ? entry.volumeId[ROVOL1] : entry.cloneId); | ||
| 3582 | code = VolumeExists(afromserver, afrompart, cloneVolId); | ||
| 3583 | roexists = ((code == ENODEV19) ? 0 : 1); | ||
| 3584 | |||
| 3585 | fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 3586 | if (!fromconn) | ||
| 3587 | ONERROR(-1, afromserver,do { if (-1) { fprintf(__stderrp, ("Cannot establish connection with server 0x%x\n" ), (afromserver)); error = (-1); goto rfail; } } while (0) | ||
| 3588 | "Cannot establish connection with server 0x%x\n")do { if (-1) { fprintf(__stderrp, ("Cannot establish connection with server 0x%x\n" ), (afromserver)); error = (-1); goto rfail; } } while (0); | ||
| 3589 | |||
| 3590 | if (!fullrelease) { | ||
| 3591 | if (!roexists) | ||
| 3592 | fullrelease = 1; /* Do a full release if RO clone does not exist */ | ||
| 3593 | else { | ||
| 3594 | /* Begin transaction on RW and mark it busy while we query it */ | ||
| 3595 | code = AFSVolTransCreate_retry( | ||
| 3596 | fromconn, afromvol, afrompart, ITBusy2, &fromtid | ||
| 3597 | ); | ||
| 3598 | ONERROR(code, afromvol,do { if (code) { fprintf(__stderrp, ("Failed to start transaction on RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0) | ||
| 3599 | "Failed to start transaction on RW volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to start transaction on RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0); | ||
| 3600 | |||
| 3601 | /* Query the creation date for the RW */ | ||
| 3602 | code = AFSVolGetStatus(fromconn, fromtid, &volstatus); | ||
| 3603 | ONERROR(code, afromvol,do { if (code) { fprintf(__stderrp, ("Failed to get the status of RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0) | ||
| 3604 | "Failed to get the status of RW volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to get the status of RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0); | ||
| 3605 | rwcrdate = volstatus.creationDate; | ||
| 3606 | |||
| 3607 | /* End transaction on RW */ | ||
| 3608 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 3609 | fromtid = 0; | ||
| 3610 | ONERROR((code ? code : rcode), afromvol,do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end transaction on RW volume %u\n" ), (afromvol)); error = ((code ? code : rcode)); goto rfail; } } while (0) | ||
| 3611 | "Failed to end transaction on RW volume %u\n")do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end transaction on RW volume %u\n" ), (afromvol)); error = ((code ? code : rcode)); goto rfail; } } while (0); | ||
| 3612 | |||
| 3613 | /* Begin transaction on clone and mark it busy while we query it */ | ||
| 3614 | code = AFSVolTransCreate_retry( | ||
| 3615 | fromconn, cloneVolId, afrompart, ITBusy2, &clonetid | ||
| 3616 | ); | ||
| 3617 | ONERROR(code, cloneVolId,do { if (code) { fprintf(__stderrp, ("Failed to start transaction on RW clone %u\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0) | ||
| 3618 | "Failed to start transaction on RW clone %u\n")do { if (code) { fprintf(__stderrp, ("Failed to start transaction on RW clone %u\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0); | ||
| 3619 | |||
| 3620 | /* Query the creation date for the clone */ | ||
| 3621 | code = AFSVolGetStatus(fromconn, clonetid, &volstatus); | ||
| 3622 | ONERROR(code, cloneVolId,do { if (code) { fprintf(__stderrp, ("Failed to get the status of RW clone %u\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0) | ||
| 3623 | "Failed to get the status of RW clone %u\n")do { if (code) { fprintf(__stderrp, ("Failed to get the status of RW clone %u\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0); | ||
| 3624 | clcrdate = volstatus.creationDate; | ||
| 3625 | |||
| 3626 | /* End transaction on clone */ | ||
| 3627 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 3628 | clonetid = 0; | ||
| 3629 | ONERROR((code ? code : rcode), cloneVolId,do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end transaction on RW clone %u\n" ), (cloneVolId)); error = ((code ? code : rcode)); goto rfail ; } } while (0) | ||
| 3630 | "Failed to end transaction on RW clone %u\n")do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end transaction on RW clone %u\n" ), (cloneVolId)); error = ((code ? code : rcode)); goto rfail ; } } while (0); | ||
| 3631 | |||
| 3632 | if (rwcrdate > clcrdate) | ||
| 3633 | fullrelease = 2;/* Do a full release if RO clone older than RW */ | ||
| 3634 | } | ||
| 3635 | } | ||
| 3636 | |||
| 3637 | if (verbose) { | ||
| 3638 | switch (fullrelease) { | ||
| 3639 | case 2: | ||
| 3640 | fprintf(STDOUT__stdoutp, "RW %lu changed, doing a complete release\n", | ||
| 3641 | (unsigned long)afromvol); | ||
| 3642 | break; | ||
| 3643 | case 1: | ||
| 3644 | fprintf(STDOUT__stdoutp, "This is a complete release of volume %lu\n", | ||
| 3645 | (unsigned long)afromvol); | ||
| 3646 | break; | ||
| 3647 | case 0: | ||
| 3648 | fprintf(STDOUT__stdoutp, "This is a completion of a previous release\n"); | ||
| 3649 | break; | ||
| 3650 | } | ||
| 3651 | } | ||
| 3652 | |||
| 3653 | if (fullrelease) { | ||
| 3654 | /* If the RO clone exists, then if the clone is a temporary | ||
| 3655 | * clone, delete it. Or if the RO clone is marked RO_DONTUSE | ||
| 3656 | * (it was recently added), then also delete it. We do not | ||
| 3657 | * want to "reclone" a temporary RO clone. | ||
| 3658 | */ | ||
| 3659 | if (roexists | ||
| 3660 | && (!roclone || (entry.serverFlags[roindex] & RO_DONTUSE0x20))) { | ||
| 3661 | code = DelVol(fromconn, cloneVolId, afrompart, ITOffline1); | ||
| 3662 | if (code && (code != VNOVOL103)) | ||
| 3663 | ERROREXIT(code)do { error = (code); goto rfail; } while (0); | ||
| 3664 | roexists = 0; | ||
| 3665 | } | ||
| 3666 | |||
| 3667 | /* Mark all the ROs in the VLDB entry as RO_DONTUSE. We don't | ||
| 3668 | * write this entry out to the vlserver until after the first | ||
| 3669 | * RO volume is released (temp RO clones don't count). | ||
| 3670 | */ | ||
| 3671 | for (i = 0; i < entry.nServers; i++) { | ||
| 3672 | entry.serverFlags[i] &= ~NEW_REPSITE0x01; | ||
| 3673 | entry.serverFlags[i] |= RO_DONTUSE0x20; | ||
| 3674 | } | ||
| 3675 | entry.serverFlags[rwindex] |= NEW_REPSITE0x01; | ||
| 3676 | entry.serverFlags[rwindex] &= ~RO_DONTUSE0x20; | ||
| 3677 | |||
| 3678 | /* Begin transaction on RW and mark it busy while we clone it */ | ||
| 3679 | code = | ||
| 3680 | AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, | ||
| 3681 | &clonetid); | ||
| 3682 | ONERROR(code, afromvol, "Failed to start transaction on volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to start transaction on volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0); | ||
| 3683 | |||
| 3684 | /* Clone or reclone the volume */ | ||
| 3685 | if (roexists) { | ||
| 3686 | VPRINT1("Recloning RW volume %u...", cloneVolId){ if (verbose) { fprintf(__stdoutp, ("Recloning RW volume %u..." ), (cloneVolId)); fflush(__stdoutp); } }; | ||
| 3687 | code = AFSVolReClone(fromconn, clonetid, cloneVolId); | ||
| 3688 | ONERROR(code, afromvol, "Failed to reclone the RW volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to reclone the RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0); | ||
| 3689 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3690 | } else { | ||
| 3691 | if (roclone) { | ||
| 3692 | strcpy(vname, entry.name); | ||
| 3693 | strcat(vname, ".readonly"); | ||
| 3694 | VPRINT1("Cloning RW volume %u to permanent RO...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Cloning RW volume %u to permanent RO..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 3695 | } else { | ||
| 3696 | strcpy(vname, "readonly-clone-temp"); | ||
| 3697 | VPRINT1("Cloning RW volume %u to temporary RO...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Cloning RW volume %u to temporary RO..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 3698 | } | ||
| 3699 | code = | ||
| 3700 | AFSVolClone(fromconn, clonetid, 0, readonlyVolume1, vname, | ||
| 3701 | &cloneVolId); | ||
| 3702 | ONERROR(code, afromvol, "Failed to clone the RW volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to clone the RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0); | ||
| 3703 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3704 | } | ||
| 3705 | |||
| 3706 | /* Get the time the RW was created for future information */ | ||
| 3707 | VPRINT1("Getting status of RW volume %u...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Getting status of RW volume %u..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 3708 | code = AFSVolGetStatus(fromconn, clonetid, &volstatus); | ||
| 3709 | ONERROR(code, afromvol,do { if (code) { fprintf(__stderrp, ("Failed to get the status of the RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0) | ||
| 3710 | "Failed to get the status of the RW volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to get the status of the RW volume %u\n" ), (afromvol)); error = (code); goto rfail; } } while (0); | ||
| 3711 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3712 | rwcrdate = volstatus.creationDate; | ||
| 3713 | |||
| 3714 | /* End the transaction on the RW volume */ | ||
| 3715 | VPRINT1("Ending cloning transaction on RW volume %u...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending cloning transaction on RW volume %u..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 3716 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 3717 | clonetid = 0; | ||
| 3718 | ONERROR((code ? code : rcode), afromvol,do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end cloning transaction on RW %u\n" ), (afromvol)); error = ((code ? code : rcode)); goto rfail; } } while (0) | ||
| 3719 | "Failed to end cloning transaction on RW %u\n")do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end cloning transaction on RW %u\n" ), (afromvol)); error = ((code ? code : rcode)); goto rfail; } } while (0); | ||
| 3720 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3721 | |||
| 3722 | /* Remember clone volume ID in case we fail or are interrupted */ | ||
| 3723 | entry.cloneId = cloneVolId; | ||
| 3724 | |||
| 3725 | if (roclone) { | ||
| 3726 | /* Bring the RO clone online - though not if it's a temporary clone */ | ||
| 3727 | VPRINT1("Starting transaction on RO clone volume %u...",{ if (verbose) { fprintf(__stdoutp, ("Starting transaction on RO clone volume %u..." ), (cloneVolId)); fflush(__stdoutp); } } | ||
| 3728 | cloneVolId){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on RO clone volume %u..." ), (cloneVolId)); fflush(__stdoutp); } }; | ||
| 3729 | code = | ||
| 3730 | AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline1, | ||
| 3731 | &onlinetid); | ||
| 3732 | ONERROR(code, cloneVolId,do { if (code) { fprintf(__stderrp, ("Failed to start transaction on volume %u\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0) | ||
| 3733 | "Failed to start transaction on volume %u\n")do { if (code) { fprintf(__stderrp, ("Failed to start transaction on volume %u\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0); | ||
| 3734 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3735 | |||
| 3736 | VPRINT1("Setting volume flags for volume %u...", cloneVolId){ if (verbose) { fprintf(__stdoutp, ("Setting volume flags for volume %u..." ), (cloneVolId)); fflush(__stdoutp); } }; | ||
| 3737 | tcode = AFSVolSetFlags(fromconn, onlinetid, 0); | ||
| 3738 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3739 | |||
| 3740 | VPRINT1("Ending transaction on volume %u...", cloneVolId){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on volume %u..." ), (cloneVolId)); fflush(__stdoutp); } }; | ||
| 3741 | code = AFSVolEndTrans(fromconn, onlinetid, &rcode); | ||
| 3742 | ONERROR((code ? code : rcode), cloneVolId,do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end transaction on RO clone %u\n" ), (cloneVolId)); error = ((code ? code : rcode)); goto rfail ; } } while (0) | ||
| 3743 | "Failed to end transaction on RO clone %u\n")do { if ((code ? code : rcode)) { fprintf(__stderrp, ("Failed to end transaction on RO clone %u\n" ), (cloneVolId)); error = ((code ? code : rcode)); goto rfail ; } } while (0); | ||
| 3744 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3745 | |||
| 3746 | ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n")do { if (tcode) { fprintf(__stderrp, ("Could not bring volume %u on line\n" ), (cloneVolId)); error = (tcode); goto rfail; } } while (0); | ||
| 3747 | |||
| 3748 | /* Sleep so that a client searching for an online volume won't | ||
| 3749 | * find the clone offline and then the next RO offline while the | ||
| 3750 | * release brings the clone online and the next RO offline (race). | ||
| 3751 | * There is a fix in the 3.4 client that does not need this sleep | ||
| 3752 | * anymore, but we don't know what clients we have. | ||
| 3753 | */ | ||
| 3754 | if (entry.nServers > 2) | ||
| 3755 | sleep(5); | ||
| 3756 | |||
| 3757 | /* Mark the RO clone in the VLDB as a good site (already released) */ | ||
| 3758 | entry.serverFlags[roindex] |= NEW_REPSITE0x01; | ||
| 3759 | entry.serverFlags[roindex] &= ~RO_DONTUSE0x20; | ||
| 3760 | entry.flags |= RO_EXISTS0x2000; | ||
| 3761 | |||
| 3762 | releasecount++; | ||
| 3763 | |||
| 3764 | /* Write out the VLDB entry only if the clone is not a temporary | ||
| 3765 | * clone. If we did this to a temporary clone then we would end | ||
| 3766 | * up marking all the ROs as "old release" making the ROs | ||
| 3767 | * temporarily unavailable. | ||
| 3768 | */ | ||
| 3769 | MapNetworkToHost(&entry, &storeEntry); | ||
| 3770 | VPRINT1("Replacing VLDB entry for %s...", entry.name){ if (verbose) { fprintf(__stdoutp, ("Replacing VLDB entry for %s..." ), (entry.name)); fflush(__stdoutp); } }; | ||
| 3771 | vcode = VLDB_ReplaceEntry(afromvol, RWVOL0, &storeEntry, 0); | ||
| 3772 | ONERROR(vcode, entry.name,do { if (vcode) { fprintf(__stderrp, ("Could not update vldb entry for %s.\n" ), (entry.name)); error = (vcode); goto rfail; } } while (0) | ||
| 3773 | "Could not update vldb entry for %s.\n")do { if (vcode) { fprintf(__stderrp, ("Could not update vldb entry for %s.\n" ), (entry.name)); error = (vcode); goto rfail; } } while (0); | ||
| 3774 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3775 | } | ||
| 3776 | } | ||
| 3777 | |||
| 3778 | /* Now we will release from the clone to the remaining RO replicas. | ||
| 3779 | * The first 2 ROs (counting the non-temporary RO clone) are released | ||
| 3780 | * individually: releasecount. This is to reduce the race condition | ||
| 3781 | * of clients trying to find an on-line RO volume. The remaining ROs | ||
| 3782 | * are released in parallel but no more than half the number of ROs | ||
| 3783 | * (rounded up) at a time: nservers. | ||
| 3784 | */ | ||
| 3785 | |||
| 3786 | strcpy(vname, entry.name); | ||
| 3787 | strcat(vname, ".readonly"); | ||
| 3788 | memset(&cookie, 0, sizeof(cookie)); | ||
| 3789 | strncpy(cookie.name, vname, VOLSER_OLDMAXVOLNAME32); | ||
| 3790 | cookie.type = ROVOL1; | ||
| 3791 | cookie.parent = entry.volumeId[RWVOL0]; | ||
| 3792 | cookie.clone = 0; | ||
| 3793 | |||
| 3794 | nservers = entry.nServers / 2; /* how many to do at once, excluding clone */ | ||
| 3795 | replicas = | ||
| 3796 | (struct replica *)malloc(sizeof(struct replica) * nservers + 1); | ||
| 3797 | times = (struct release *)malloc(sizeof(struct release) * nservers + 1); | ||
| 3798 | toconns = | ||
| 3799 | (struct rx_connection **)malloc(sizeof(struct rx_connection *) * | ||
| 3800 | nservers + 1); | ||
| 3801 | results.manyResults_val = | ||
| 3802 | (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1); | ||
| 3803 | if (!replicas || !times || !!!results.manyResults_val || !toconns) | ||
| 3804 | ONERROR0(ENOMEM,do { if (12) { fprintf(__stderrp, ("Failed to create transaction on the release clone\n" )); error = (12); goto rfail; } } while (0) | ||
| 3805 | "Failed to create transaction on the release clone\n")do { if (12) { fprintf(__stderrp, ("Failed to create transaction on the release clone\n" )); error = (12); goto rfail; } } while (0); | ||
| 3806 | |||
| 3807 | memset(replicas, 0, (sizeof(struct replica) * nservers + 1)); | ||
| 3808 | memset(times, 0, (sizeof(struct release) * nservers + 1)); | ||
| 3809 | memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1)); | ||
| 3810 | memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1)); | ||
| 3811 | |||
| 3812 | /* Create a transaction on the cloned volume */ | ||
| 3813 | VPRINT1("Starting transaction on cloned volume %u...", cloneVolId){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on cloned volume %u..." ), (cloneVolId)); fflush(__stdoutp); } }; | ||
| 3814 | code = | ||
| 3815 | AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy2, &fromtid); | ||
| 3816 | if (!code) { | ||
| 3817 | memset(&orig_status, 0, sizeof(orig_status)); | ||
| 3818 | code = AFSVolGetStatus(fromconn, fromtid, &orig_status); | ||
| 3819 | } | ||
| 3820 | if (!fullrelease && code) | ||
| 3821 | ONERROR(VOLSERNOVOL, afromvol,do { if ((1492325135L)) { fprintf(__stderrp, ("Old clone is inaccessible. Try vos release -f %u.\n" ), (afromvol)); error = ((1492325135L)); goto rfail; } } while (0) | ||
| 3822 | "Old clone is inaccessible. Try vos release -f %u.\n")do { if ((1492325135L)) { fprintf(__stderrp, ("Old clone is inaccessible. Try vos release -f %u.\n" ), (afromvol)); error = ((1492325135L)); goto rfail; } } while (0); | ||
| 3823 | ONERROR0(code, "Failed to create transaction on the release clone\n")do { if (code) { fprintf(__stderrp, ("Failed to create transaction on the release clone\n" )); error = (code); goto rfail; } } while (0); | ||
| 3824 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 3825 | |||
| 3826 | /* For each index in the VLDB */ | ||
| 3827 | for (vldbindex = 0; vldbindex < entry.nServers;) { | ||
| 3828 | |||
| 3829 | /* Get a transaction on the replicas. Pick replacas which have an old release. */ | ||
| 3830 | for (volcount = 0; | ||
| 3831 | ((volcount < nservers) && (vldbindex < entry.nServers)); | ||
| 3832 | vldbindex++) { | ||
| 3833 | /* The first two RO volumes will be released individually. | ||
| 3834 | * The rest are then released in parallel. This is a hack | ||
| 3835 | * for clients not recognizing right away when a RO volume | ||
| 3836 | * comes back on-line. | ||
| 3837 | */ | ||
| 3838 | if ((volcount == 1) && (releasecount < 2)) | ||
| 3839 | break; | ||
| 3840 | |||
| 3841 | if (vldbindex == roindex) | ||
| 3842 | continue; /* the clone */ | ||
| 3843 | if ((entry.serverFlags[vldbindex] & NEW_REPSITE0x01) | ||
| 3844 | && !(entry.serverFlags[vldbindex] & RO_DONTUSE0x20)) | ||
| 3845 | continue; | ||
| 3846 | if (!(entry.serverFlags[vldbindex] & ITSROVOL0x02)) | ||
| 3847 | continue; /* not a RO vol */ | ||
| 3848 | |||
| 3849 | |||
| 3850 | /* Get a Transaction on this replica. Get a new connection if | ||
| 3851 | * necessary. Create the volume if necessary. Return the | ||
| 3852 | * time from which the dump should be made (0 if it's a new | ||
| 3853 | * volume). Each volume might have a different time. | ||
| 3854 | */ | ||
| 3855 | replicas[volcount].server.destHost = | ||
| 3856 | ntohl(entry.serverNumber[vldbindex])(__builtin_constant_p(entry.serverNumber[vldbindex]) ? ((((__uint32_t )(entry.serverNumber[vldbindex])) >> 24) | ((((__uint32_t )(entry.serverNumber[vldbindex])) & (0xff << 16)) >> 8) | ((((__uint32_t)(entry.serverNumber[vldbindex])) & ( 0xff << 8)) << 8) | (((__uint32_t)(entry.serverNumber [vldbindex])) << 24)) : __bswap32_var(entry.serverNumber [vldbindex])); | ||
| 3857 | replicas[volcount].server.destPort = AFSCONF_VOLUMEPORT7005; | ||
| 3858 | replicas[volcount].server.destSSID = 1; | ||
| 3859 | times[volcount].vldbEntryIndex = vldbindex; | ||
| 3860 | |||
| 3861 | code = | ||
| 3862 | GetTrans(&entry, vldbindex, &(toconns[volcount]), | ||
| 3863 | &(replicas[volcount].trans), | ||
| 3864 | &(times[volcount].crtime), | ||
| 3865 | &(times[volcount].uptime), | ||
| 3866 | origflags); | ||
| 3867 | if (code) | ||
| 3868 | continue; | ||
| 3869 | |||
| 3870 | /* Thisdate is the date from which we want to pick up all changes */ | ||
| 3871 | if (forceflag || !fullrelease | ||
| 3872 | || (rwcrdate > times[volcount].crtime)) { | ||
| 3873 | /* If the forceflag is set, then we want to do a full dump. | ||
| 3874 | * If it's not a full release, we can't be sure that the creation | ||
| 3875 | * date is good (so we also do a full dump). | ||
| 3876 | * If the RW volume was replaced (its creation date is newer than | ||
| 3877 | * the last release), then we can't be sure what has changed (so | ||
| 3878 | * we do a full dump). | ||
| 3879 | */ | ||
| 3880 | thisdate = 0; | ||
| 3881 | } else if (remembertime[vldbindex].validtime) { | ||
| 3882 | /* Trans was prev ended. Use the time from the prev trans | ||
| 3883 | * because, prev trans may have created the volume. In which | ||
| 3884 | * case time[volcount].time would be now instead of 0. | ||
| 3885 | */ | ||
| 3886 | thisdate = | ||
| 3887 | (remembertime[vldbindex].uptime < times[volcount].uptime) | ||
| 3888 | ? remembertime[vldbindex].uptime | ||
| 3889 | : times[volcount].uptime; | ||
| 3890 | } else { | ||
| 3891 | thisdate = times[volcount].uptime; | ||
| 3892 | } | ||
| 3893 | remembertime[vldbindex].validtime = 1; | ||
| 3894 | remembertime[vldbindex].uptime = thisdate; | ||
| 3895 | |||
| 3896 | if (volcount == 0) { | ||
| 3897 | fromdate = thisdate; | ||
| 3898 | } else { | ||
| 3899 | /* Include this volume if it is within 15 minutes of the earliest */ | ||
| 3900 | if (((fromdate > | ||
| 3901 | thisdate) ? (fromdate - thisdate) : (thisdate - | ||
| 3902 | fromdate)) > 900) { | ||
| 3903 | AFSVolEndTrans(toconns[volcount], | ||
| 3904 | replicas[volcount].trans, &rcode); | ||
| 3905 | replicas[volcount].trans = 0; | ||
| 3906 | break; | ||
| 3907 | } | ||
| 3908 | if (thisdate < fromdate) | ||
| 3909 | fromdate = thisdate; | ||
| 3910 | } | ||
| 3911 | volcount++; | ||
| 3912 | } | ||
| 3913 | if (!volcount) | ||
| 3914 | continue; | ||
| 3915 | |||
| 3916 | code = CheckTrans(fromconn, &fromtid, afrompart, &orig_status); | ||
| 3917 | if (code) { | ||
| 3918 | code = ENOENT2; | ||
| 3919 | goto rfail; | ||
| 3920 | } | ||
| 3921 | |||
| 3922 | if (verbose) { | ||
| 3923 | fprintf(STDOUT__stdoutp, "Starting ForwardMulti from %lu to %u on %s", | ||
| 3924 | (unsigned long)cloneVolId, entry.volumeId[ROVOL1], | ||
| 3925 | noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[0]. | ||
| 3926 | vldbEntryIndex], hoststr) : | ||
| 3927 | hostutil_GetNameByINet(entry. | ||
| 3928 | serverNumber[times[0]. | ||
| 3929 | vldbEntryIndex])); | ||
| 3930 | |||
| 3931 | for (s = 1; s < volcount; s++) { | ||
| 3932 | fprintf(STDOUT__stdoutp, " and %s", | ||
| 3933 | noresolve ? afs_inet_ntoa_r(entry.serverNumber[times[s]. | ||
| 3934 | vldbEntryIndex], hoststr) : | ||
| 3935 | hostutil_GetNameByINet(entry. | ||
| 3936 | serverNumber[times[s]. | ||
| 3937 | vldbEntryIndex])); | ||
| 3938 | } | ||
| 3939 | |||
| 3940 | if (fromdate == 0) | ||
| 3941 | fprintf(STDOUT__stdoutp, " (full release)"); | ||
| 3942 | else { | ||
| 3943 | tmv = fromdate; | ||
| 3944 | fprintf(STDOUT__stdoutp, " (as of %.24s)", ctime(&tmv)); | ||
| 3945 | } | ||
| 3946 | fprintf(STDOUT__stdoutp, ".\n"); | ||
| 3947 | fflush(STDOUT__stdoutp); | ||
| 3948 | } | ||
| 3949 | |||
| 3950 | /* Release the ones we have collected */ | ||
| 3951 | tr.manyDests_val = &(replicas[0]); | ||
| 3952 | tr.manyDests_len = results.manyResults_len = volcount; | ||
| 3953 | code = | ||
| 3954 | AFSVolForwardMultiple(fromconn, fromtid, fromdate, &tr, | ||
| 3955 | 0 /*spare */ , &cookie, &results); | ||
| 3956 | if (code == RXGEN_OPCODE-455) { /* RPC Interface Mismatch */ | ||
| 3957 | code = | ||
| 3958 | SimulateForwardMultiple(fromconn, fromtid, fromdate, &tr, | ||
| 3959 | 0 /*spare */ , &cookie, &results); | ||
| 3960 | nservers = 1; | ||
| 3961 | } | ||
| 3962 | |||
| 3963 | if (code) { | ||
| 3964 | PrintError("Release failed: ", code); | ||
| 3965 | } else { | ||
| 3966 | for (m = 0; m < volcount; m++) { | ||
| 3967 | if (results.manyResults_val[m]) { | ||
| 3968 | if ((m == 0) || (results.manyResults_val[m] != ENOENT2)) { | ||
| 3969 | /* we retry timed out transaction. When it is | ||
| 3970 | * not the first volume and the transaction wasn't found | ||
| 3971 | * (assume it timed out and was garbage collected by volser). | ||
| 3972 | */ | ||
| 3973 | PrintError | ||
| 3974 | ("Failed to dump volume from clone to a ro site: ", | ||
| 3975 | results.manyResults_val[m]); | ||
| 3976 | } | ||
| 3977 | continue; | ||
| 3978 | } | ||
| 3979 | |||
| 3980 | code = | ||
| 3981 | AFSVolSetIdsTypes(toconns[m], replicas[m].trans, vname, | ||
| 3982 | ROVOL1, entry.volumeId[RWVOL0], 0, 0); | ||
| 3983 | if (code) { | ||
| 3984 | if ((m == 0) || (code != ENOENT2)) { | ||
| 3985 | PrintError("Failed to set correct names and ids: ", | ||
| 3986 | code); | ||
| 3987 | } | ||
| 3988 | continue; | ||
| 3989 | } | ||
| 3990 | |||
| 3991 | /* have to clear dest. flags to ensure new vol goes online: | ||
| 3992 | * because the restore (forwarded) operation copied | ||
| 3993 | * the V_inService(=0) flag over to the destination. | ||
| 3994 | */ | ||
| 3995 | code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0); | ||
| 3996 | if (code) { | ||
| 3997 | if ((m == 0) || (code != ENOENT2)) { | ||
| 3998 | PrintError("Failed to set flags on ro volume: ", | ||
| 3999 | code); | ||
| 4000 | } | ||
| 4001 | continue; | ||
| 4002 | } | ||
| 4003 | |||
| 4004 | entry.serverFlags[times[m].vldbEntryIndex] |= NEW_REPSITE0x01; | ||
| 4005 | entry.serverFlags[times[m].vldbEntryIndex] &= ~RO_DONTUSE0x20; | ||
| 4006 | entry.flags |= RO_EXISTS0x2000; | ||
| 4007 | releasecount++; | ||
| 4008 | } | ||
| 4009 | } | ||
| 4010 | |||
| 4011 | /* End the transactions and destroy the connections */ | ||
| 4012 | for (s = 0; s < volcount; s++) { | ||
| 4013 | if (replicas[s].trans) | ||
| 4014 | code = AFSVolEndTrans(toconns[s], replicas[s].trans, &rcode); | ||
| 4015 | replicas[s].trans = 0; | ||
| 4016 | if (!code) | ||
| 4017 | code = rcode; | ||
| 4018 | if (code) { | ||
| 4019 | if ((s == 0) || (code != ENOENT2)) { | ||
| 4020 | PrintError("Could not end transaction on a ro volume: ", | ||
| 4021 | code); | ||
| 4022 | } else { | ||
| 4023 | PrintError | ||
| 4024 | ("Transaction timed out on a ro volume. Will retry.\n", | ||
| 4025 | 0); | ||
| 4026 | if (times[s].vldbEntryIndex < vldbindex) | ||
| 4027 | vldbindex = times[s].vldbEntryIndex; | ||
| 4028 | } | ||
| 4029 | } | ||
| 4030 | |||
| 4031 | if (toconns[s]) | ||
| 4032 | rx_DestroyConnection(toconns[s]); | ||
| 4033 | toconns[s] = 0; | ||
| 4034 | } | ||
| 4035 | |||
| 4036 | MapNetworkToHost(&entry, &storeEntry); | ||
| 4037 | vcode = VLDB_ReplaceEntry(afromvol, RWVOL0, &storeEntry, 0); | ||
| 4038 | ONERROR(vcode, afromvol,do { if (vcode) { fprintf(__stderrp, (" Could not update VLDB entry for volume %u\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0) | ||
| 4039 | " Could not update VLDB entry for volume %u\n")do { if (vcode) { fprintf(__stderrp, (" Could not update VLDB entry for volume %u\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0); | ||
| 4040 | } /* for each index in the vldb */ | ||
| 4041 | |||
| 4042 | /* End the transaction on the cloned volume */ | ||
| 4043 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 4044 | fromtid = 0; | ||
| 4045 | if (!code) | ||
| 4046 | code = rcode; | ||
| 4047 | if (code) | ||
| 4048 | PrintError("Failed to end transaction on rw volume: ", code); | ||
| 4049 | |||
| 4050 | /* Figure out if any volume were not released and say so */ | ||
| 4051 | for (failure = 0, i = 0; i < entry.nServers; i++) { | ||
| 4052 | if (!(entry.serverFlags[i] & NEW_REPSITE0x01)) | ||
| 4053 | failure++; | ||
| 4054 | } | ||
| 4055 | if (failure) { | ||
| 4056 | char pname[10]; | ||
| 4057 | fprintf(STDERR__stderrp, | ||
| 4058 | "The volume %lu could not be released to the following %d sites:\n", | ||
| 4059 | (unsigned long)afromvol, failure); | ||
| 4060 | for (i = 0; i < entry.nServers; i++) { | ||
| 4061 | if (!(entry.serverFlags[i] & NEW_REPSITE0x01)) { | ||
| 4062 | MapPartIdIntoName(entry.serverPartition[i], pname); | ||
| 4063 | fprintf(STDERR__stderrp, "\t%35s %s\n", | ||
| 4064 | noresolve ? afs_inet_ntoa_r(entry.serverNumber[i], hoststr) : | ||
| 4065 | hostutil_GetNameByINet(entry.serverNumber[i]), pname); | ||
| 4066 | } | ||
| 4067 | } | ||
| 4068 | |||
| 4069 | MapNetworkToHost(&entry, &storeEntry); | ||
| 4070 | vcode = | ||
| 4071 | VLDB_ReplaceEntry(afromvol, RWVOL0, &storeEntry, | ||
| 4072 | LOCKREL_TIMESTAMP1); | ||
| 4073 | ONERROR(vcode, afromvol,do { if (vcode) { fprintf(__stderrp, (" Could not update VLDB entry for volume %u\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0) | ||
| 4074 | " Could not update VLDB entry for volume %u\n")do { if (vcode) { fprintf(__stderrp, (" Could not update VLDB entry for volume %u\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0); | ||
| 4075 | |||
| 4076 | ERROREXIT(VOLSERBADRELEASE)do { error = ((1492325132L)); goto rfail; } while (0); | ||
| 4077 | } | ||
| 4078 | |||
| 4079 | /* All the ROs were release successfully. Remove the temporary clone */ | ||
| 4080 | if (!roclone) { | ||
| 4081 | if (verbose) { | ||
| 4082 | fprintf(STDOUT__stdoutp, "Deleting the releaseClone %lu ...", | ||
| 4083 | (unsigned long)cloneVolId); | ||
| 4084 | fflush(STDOUT__stdoutp); | ||
| 4085 | } | ||
| 4086 | code = DelVol(fromconn, cloneVolId, afrompart, ITOffline1); | ||
| 4087 | ONERROR(code, cloneVolId, "Failed to delete volume %u.\n")do { if (code) { fprintf(__stderrp, ("Failed to delete volume %u.\n" ), (cloneVolId)); error = (code); goto rfail; } } while (0); | ||
| 4088 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 4089 | } | ||
| 4090 | entry.cloneId = 0; | ||
| 4091 | |||
| 4092 | for (i = 0; i < entry.nServers; i++) | ||
| 4093 | entry.serverFlags[i] &= ~NEW_REPSITE0x01; | ||
| 4094 | |||
| 4095 | /* Update the VLDB */ | ||
| 4096 | VPRINT("updating VLDB ..."){ if (verbose) { fprintf(__stdoutp, ("updating VLDB ...")); fflush (__stdoutp); } }; | ||
| 4097 | |||
| 4098 | MapNetworkToHost(&entry, &storeEntry); | ||
| 4099 | vcode = | ||
| 4100 | VLDB_ReplaceEntry(afromvol, RWVOL0, &storeEntry, | ||
| 4101 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 4102 | ONERROR(vcode, afromvol, " Could not update VLDB entry for volume %u\n")do { if (vcode) { fprintf(__stderrp, (" Could not update VLDB entry for volume %u\n" ), (afromvol)); error = (vcode); goto rfail; } } while (0); | ||
| 4103 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 4104 | |||
| 4105 | rfail: | ||
| 4106 | if (clonetid) { | ||
| 4107 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 4108 | clonetid = 0; | ||
| 4109 | if (code) { | ||
| 4110 | fprintf(STDERR__stderrp, | ||
| 4111 | "Failed to end cloning transaction on the RW volume %lu\n", | ||
| 4112 | (unsigned long)afromvol); | ||
| 4113 | if (!error) | ||
| 4114 | error = code; | ||
| 4115 | } | ||
| 4116 | } | ||
| 4117 | if (fromtid) { | ||
| 4118 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 4119 | fromtid = 0; | ||
| 4120 | if (code) { | ||
| 4121 | fprintf(STDERR__stderrp, | ||
| 4122 | "Failed to end transaction on the release clone %lu\n", | ||
| 4123 | (unsigned long)cloneVolId); | ||
| 4124 | if (!error) | ||
| 4125 | error = code; | ||
| 4126 | } | ||
| 4127 | } | ||
| 4128 | for (i = 0; i < nservers; i++) { | ||
| 4129 | if (replicas && replicas[i].trans) { | ||
| 4130 | code = AFSVolEndTrans(toconns[i], replicas[i].trans, &rcode); | ||
| 4131 | replicas[i].trans = 0; | ||
| 4132 | if (code) { | ||
| 4133 | fprintf(STDERR__stderrp, | ||
| 4134 | "Failed to end transaction on ro volume %u at server %s\n", | ||
| 4135 | entry.volumeId[ROVOL1], | ||
| 4136 | noresolve ? afs_inet_ntoa_r(htonl(replicas[i].server.(__builtin_constant_p(replicas[i].server. destHost) ? ((((__uint32_t )(replicas[i].server. destHost)) >> 24) | ((((__uint32_t )(replicas[i].server. destHost)) & (0xff << 16)) >> 8) | ((((__uint32_t)(replicas[i].server. destHost)) & (0xff << 8)) << 8) | (((__uint32_t)(replicas[i].server . destHost)) << 24)) : __bswap32_var(replicas[i].server . destHost)) | ||
| 4137 | destHost)(__builtin_constant_p(replicas[i].server. destHost) ? ((((__uint32_t )(replicas[i].server. destHost)) >> 24) | ((((__uint32_t )(replicas[i].server. destHost)) & (0xff << 16)) >> 8) | ((((__uint32_t)(replicas[i].server. destHost)) & (0xff << 8)) << 8) | (((__uint32_t)(replicas[i].server . destHost)) << 24)) : __bswap32_var(replicas[i].server . destHost)), hoststr) : | ||
| 4138 | hostutil_GetNameByINet(htonl(__builtin_constant_p(replicas[i].server.destHost) ? ((((__uint32_t )(replicas[i].server.destHost)) >> 24) | ((((__uint32_t )(replicas[i].server.destHost)) & (0xff << 16)) >> 8) | ((((__uint32_t)(replicas[i].server.destHost)) & (0xff << 8)) << 8) | (((__uint32_t)(replicas[i].server .destHost)) << 24)) : __bswap32_var(replicas[i].server. destHost)) | ||
| 4139 | (replicas[i].server.destHost)(__builtin_constant_p(replicas[i].server.destHost) ? ((((__uint32_t )(replicas[i].server.destHost)) >> 24) | ((((__uint32_t )(replicas[i].server.destHost)) & (0xff << 16)) >> 8) | ((((__uint32_t)(replicas[i].server.destHost)) & (0xff << 8)) << 8) | (((__uint32_t)(replicas[i].server .destHost)) << 24)) : __bswap32_var(replicas[i].server. destHost)))); | ||
| 4140 | if (!error) | ||
| 4141 | error = code; | ||
| 4142 | } | ||
| 4143 | } | ||
| 4144 | if (toconns && toconns[i]) { | ||
| 4145 | rx_DestroyConnection(toconns[i]); | ||
| 4146 | toconns[i] = 0; | ||
| 4147 | } | ||
| 4148 | } | ||
| 4149 | if (islocked) { | ||
| 4150 | vcode = | ||
| 4151 | ubik_VL_ReleaseLock(cstruct, 0, afromvol, RWVOL0, | ||
| 4152 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 4153 | if (vcode) { | ||
| 4154 | fprintf(STDERR__stderrp, | ||
| 4155 | "Could not release lock on the VLDB entry for volume %lu\n", | ||
| 4156 | (unsigned long)afromvol); | ||
| 4157 | if (!error) | ||
| 4158 | error = vcode; | ||
| 4159 | } | ||
| 4160 | } | ||
| 4161 | |||
| 4162 | PrintError("", error); | ||
| 4163 | |||
| 4164 | if (fromconn) | ||
| 4165 | rx_DestroyConnection(fromconn); | ||
| 4166 | if (results.manyResults_val) | ||
| 4167 | free(results.manyResults_val); | ||
| 4168 | if (replicas) | ||
| 4169 | free(replicas); | ||
| 4170 | if (toconns) | ||
| 4171 | free(toconns); | ||
| 4172 | if (times) | ||
| 4173 | free(times); | ||
| 4174 | return error; | ||
| 4175 | } | ||
| 4176 | |||
| 4177 | |||
| 4178 | static void | ||
| 4179 | dump_sig_handler(int x) | ||
| 4180 | { | ||
| 4181 | fprintf(STDERR__stderrp, "\nSignal handler: vos dump operation\n"); | ||
| 4182 | longjmp(env, 0); | ||
| 4183 | } | ||
| 4184 | |||
| 4185 | /* Dump the volume <afromvol> on <afromserver> and | ||
| 4186 | * <afrompart> to <afilename> starting from <fromdate>. | ||
| 4187 | * DumpFunction does the real work behind the scenes after | ||
| 4188 | * extracting parameters from the rock | ||
| 4189 | */ | ||
| 4190 | int | ||
| 4191 | UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart, | ||
| 4192 | afs_int32 fromdate, | ||
| 4193 | afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock, | ||
| 4194 | afs_int32 flags) | ||
| 4195 | { | ||
| 4196 | /* declare stuff 'volatile' that may be used from setjmp/longjmp and may | ||
| 4197 | * be changing during the dump */ | ||
| 4198 | struct rx_call * volatile fromcall = NULL((void *)0); | ||
| 4199 | struct rx_connection * volatile fromconn = NULL((void *)0); | ||
| 4200 | afs_int32 volatile fromtid = 0; | ||
| 4201 | |||
| 4202 | afs_int32 rxError = 0, rcode = 0; | ||
| 4203 | afs_int32 code, error = 0; | ||
| 4204 | afs_int32 tmp; | ||
| 4205 | time_t tmv = fromdate; | ||
| 4206 | |||
| 4207 | if (setjmp(env)) | ||
| 4208 | ERROR_EXIT(EPIPE)do { error = (32); goto error_exit; } while (0); | ||
| 4209 | #ifndef AFS_NT40_ENV | ||
| 4210 | (void)signal(SIGPIPE13, dump_sig_handler); | ||
| 4211 | #endif | ||
| 4212 | (void)signal(SIGINT2, dump_sig_handler); | ||
| 4213 | |||
| 4214 | if (!fromdate) { | ||
| 4215 | VEPRINT("Full Dump ...\n"){ if (verbose) { fprintf(__stderrp, ("Full Dump ...\n")); fflush (__stderrp); } }; | ||
| 4216 | } else { | ||
| 4217 | VEPRINT1("Incremental Dump (as of %.24s)...\n",{ if (verbose) { fprintf(__stderrp, ("Incremental Dump (as of %.24s)...\n" ), (ctime(&tmv))); fflush(__stderrp); } } | ||
| 4218 | ctime(&tmv)){ if (verbose) { fprintf(__stderrp, ("Incremental Dump (as of %.24s)...\n" ), (ctime(&tmv))); fflush(__stderrp); } }; | ||
| 4219 | } | ||
| 4220 | |||
| 4221 | /* get connections to the servers */ | ||
| 4222 | fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 4223 | |||
| 4224 | VEPRINT1("Starting transaction on volume %u...", afromvol){ if (verbose) { fprintf(__stderrp, ("Starting transaction on volume %u..." ), (afromvol)); fflush(__stderrp); } }; | ||
| 4225 | tmp = fromtid; | ||
| 4226 | code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, &tmp); | ||
| 4227 | fromtid = tmp; | ||
| 4228 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be dumped\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4229 | "Could not start transaction on the volume %u to be dumped\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be dumped\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4230 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be dumped\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4231 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4232 | |||
| 4233 | fromcall = rx_NewCall(fromconn); | ||
| 4234 | |||
| 4235 | VEPRINT1("Starting volume dump on volume %u...", afromvol){ if (verbose) { fprintf(__stderrp, ("Starting volume dump on volume %u..." ), (afromvol)); fflush(__stderrp); } }; | ||
| 4236 | if (flags & VOLDUMPV2_OMITDIRS1) | ||
| 4237 | code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags); | ||
| 4238 | else | ||
| 4239 | code = StartAFSVolDump(fromcall, fromtid, fromdate); | ||
| 4240 | EGOTO(error_exit, code, "Could not start the dump process \n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start the dump process \n"))); PrintError(" " ,(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4241 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4242 | |||
| 4243 | VEPRINT1("Dumping volume %u...", afromvol){ if (verbose) { fprintf(__stderrp, ("Dumping volume %u..."), (afromvol)); fflush(__stderrp); } }; | ||
| 4244 | code = DumpFunction(fromcall, rock); | ||
| 4245 | if (code == RXGEN_OPCODE-455) | ||
| 4246 | goto error_exit; | ||
| 4247 | EGOTO(error_exit, code, "Error while dumping volume \n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Error while dumping volume \n"))); PrintError(" ",(code )); } while (0); error = (code); goto error_exit; } } while ( 0); | ||
| 4248 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4249 | |||
| 4250 | error_exit: | ||
| 4251 | if (fromcall) { | ||
| 4252 | code = rx_EndCall(fromcall, rxError); | ||
| 4253 | if (code && code != RXGEN_OPCODE-455) | ||
| 4254 | fprintf(STDERR__stderrp, "Error in rx_EndCall\n"); | ||
| 4255 | if (code && !error) | ||
| 4256 | error = code; | ||
| 4257 | } | ||
| 4258 | if (fromtid) { | ||
| 4259 | VEPRINT1("Ending transaction on volume %u...", afromvol){ if (verbose) { fprintf(__stderrp, ("Ending transaction on volume %u..." ), (afromvol)); fflush(__stderrp); } }; | ||
| 4260 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 4261 | if (code || rcode) { | ||
| 4262 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %lu\n", | ||
| 4263 | (unsigned long)afromvol); | ||
| 4264 | if (!error) | ||
| 4265 | error = (code ? code : rcode); | ||
| 4266 | } | ||
| 4267 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4268 | } | ||
| 4269 | if (fromconn) | ||
| 4270 | rx_DestroyConnection(fromconn); | ||
| 4271 | |||
| 4272 | if (error != RXGEN_OPCODE-455) | ||
| 4273 | PrintError("", error); | ||
| 4274 | return (error); | ||
| 4275 | } | ||
| 4276 | |||
| 4277 | /* Clone the volume <afromvol> on <afromserver> and | ||
| 4278 | * <afrompart>, and then dump the clone volume to | ||
| 4279 | * <afilename> starting from <fromdate>. | ||
| 4280 | * DumpFunction does the real work behind the scenes after | ||
| 4281 | * extracting parameters from the rock | ||
| 4282 | */ | ||
| 4283 | int | ||
| 4284 | UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver, | ||
| 4285 | afs_int32 afrompart, afs_int32 fromdate, | ||
| 4286 | afs_int32(*DumpFunction) (struct rx_call *, void *), | ||
| 4287 | void *rock, afs_int32 flags) | ||
| 4288 | { | ||
| 4289 | /* declare stuff 'volatile' that may be used from setjmp/longjmp and may | ||
| 4290 | * be changing during the dump */ | ||
| 4291 | struct rx_connection * volatile fromconn = NULL((void *)0); | ||
| 4292 | struct rx_call * volatile fromcall = NULL((void *)0); | ||
| 4293 | afs_int32 volatile clonetid = 0; | ||
| 4294 | afs_uint32 volatile clonevol = 0; | ||
| 4295 | |||
| 4296 | afs_int32 tmp; | ||
| 4297 | afs_int32 fromtid = 0, rxError = 0, rcode = 0; | ||
| 4298 | afs_int32 code = 0, error = 0; | ||
| 4299 | afs_uint32 tmpVol; | ||
| 4300 | char vname[64]; | ||
| 4301 | time_t tmv = fromdate; | ||
| 4302 | |||
| 4303 | if (setjmp(env)) | ||
| |||
| 4304 | ERROR_EXIT(EPIPE)do { error = (32); goto error_exit; } while (0); | ||
| 4305 | #ifndef AFS_NT40_ENV | ||
| 4306 | (void)signal(SIGPIPE13, dump_sig_handler); | ||
| 4307 | #endif | ||
| 4308 | (void)signal(SIGINT2, dump_sig_handler); | ||
| 4309 | |||
| 4310 | if (!fromdate) { | ||
| |||
| 4311 | VEPRINT("Full Dump ...\n"){ if (verbose) { fprintf(__stderrp, ("Full Dump ...\n")); fflush (__stderrp); } }; | ||
| 4312 | } else { | ||
| 4313 | VEPRINT1("Incremental Dump (as of %.24s)...\n",{ if (verbose) { fprintf(__stderrp, ("Incremental Dump (as of %.24s)...\n" ), (ctime(&tmv))); fflush(__stderrp); } } | ||
| 4314 | ctime(&tmv)){ if (verbose) { fprintf(__stderrp, ("Incremental Dump (as of %.24s)...\n" ), (ctime(&tmv))); fflush(__stderrp); } }; | ||
| 4315 | } | ||
| 4316 | |||
| 4317 | /* get connections to the servers */ | ||
| 4318 | fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 4319 | |||
| 4320 | VEPRINT1("Starting transaction on volume %u...", afromvol){ if (verbose) { fprintf(__stderrp, ("Starting transaction on volume %u..." ), (afromvol)); fflush(__stderrp); } }; | ||
| 4321 | code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy2, &fromtid); | ||
| 4322 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be dumped\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4323 | "Could not start transaction on the volume %u to be dumped\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be dumped\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4324 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be dumped\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4325 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4326 | |||
| 4327 | /* Get a clone id */ | ||
| 4328 | VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol){ if (verbose) { fprintf(__stderrp, ("Allocating new volume id for clone of volume %u ..." ), (afromvol)); fflush(__stderrp); } }; | ||
| 4329 | tmpVol = clonevol; | ||
| 4330 | code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol); | ||
| 4331 | clonevol = tmpVol; | ||
| 4332 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4333 | "Could not get an ID for the clone of volume %u from the VLDB\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4334 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get an ID for the clone of volume %u from the VLDB\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4335 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4336 | |||
| 4337 | /* Do the clone. Default flags on clone are set to delete on salvage and out of service */ | ||
| 4338 | VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,{ if (verbose) { fprintf(__stderrp, ("Cloning source volume %u to clone volume %u..." ), (afromvol), (clonevol)); fflush(__stderrp); } } | ||
| 4339 | clonevol){ if (verbose) { fprintf(__stderrp, ("Cloning source volume %u to clone volume %u..." ), (afromvol), (clonevol)); fflush(__stderrp); } }; | ||
| 4340 | strcpy(vname, "dump-clone-temp"); | ||
| 4341 | tmpVol = clonevol; | ||
| |||
| 4342 | code = | ||
| 4343 | AFSVolClone(fromconn, fromtid, 0, readonlyVolume1, vname, &tmpVol); | ||
| 4344 | clonevol = tmpVol; | ||
| 4345 | EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to clone the source volume %u\n")), ((afromvol))) ; PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4346 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to clone the source volume %u\n")), ((afromvol))) ; PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4347 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4348 | |||
| 4349 | VEPRINT1("Ending the transaction on the volume %u ...", afromvol){ if (verbose) { fprintf(__stderrp, ("Ending the transaction on the volume %u ..." ), (afromvol)); fflush(__stderrp); } }; | ||
| 4350 | rcode = 0; | ||
| 4351 | code = AFSVolEndTrans(fromconn, fromtid, &rcode); | ||
| 4352 | fromtid = 0; | ||
| 4353 | if (!code) | ||
| 4354 | code = rcode; | ||
| 4355 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4356 | "Failed to end the transaction on the volume %u\n", afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to end the transaction on the volume %u\n")), ((afromvol ))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4357 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4358 | |||
| 4359 | |||
| 4360 | VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol){ if (verbose) { fprintf(__stderrp, ("Starting transaction on the cloned volume %u ..." ), (clonevol)); fflush(__stderrp); } }; | ||
| 4361 | tmp = clonetid; | ||
| 4362 | code = | ||
| 4363 | AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline1, | ||
| 4364 | &tmp); | ||
| 4365 | clonetid = tmp; | ||
| 4366 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((clonevol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4367 | "Failed to start a transaction on the cloned volume%u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((clonevol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4368 | clonevol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start a transaction on the cloned volume%u\n") ), ((clonevol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4369 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4370 | |||
| 4371 | VEPRINT1("Setting flags on cloned volume %u ...", clonevol){ if (verbose) { fprintf(__stderrp, ("Setting flags on cloned volume %u ..." ), (clonevol)); fflush(__stderrp); } }; | ||
| 4372 | code = AFSVolSetFlags(fromconn, clonetid, VTDeleteOnSalvage1 | VTOutOfService2); /*redundant */ | ||
| 4373 | EGOTO1(error_exit, code, "Could not set falgs on the cloned volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set falgs on the cloned volume %u\n")), ((clonevol ))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 4374 | clonevol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set falgs on the cloned volume %u\n")), ((clonevol ))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4375 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4376 | |||
| 4377 | |||
| 4378 | fromcall = rx_NewCall(fromconn); | ||
| 4379 | |||
| 4380 | VEPRINT1("Starting volume dump from cloned volume %u...", clonevol){ if (verbose) { fprintf(__stderrp, ("Starting volume dump from cloned volume %u..." ), (clonevol)); fflush(__stderrp); } }; | ||
| 4381 | if (flags & VOLDUMPV2_OMITDIRS1) | ||
| 4382 | code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags); | ||
| 4383 | else | ||
| 4384 | code = StartAFSVolDump(fromcall, clonetid, fromdate); | ||
| 4385 | EGOTO(error_exit, code, "Could not start the dump process \n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start the dump process \n"))); PrintError(" " ,(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 4386 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4387 | |||
| 4388 | VEPRINT1("Dumping volume %u...", afromvol){ if (verbose) { fprintf(__stderrp, ("Dumping volume %u..."), (afromvol)); fflush(__stderrp); } }; | ||
| 4389 | code = DumpFunction(fromcall, rock); | ||
| 4390 | EGOTO(error_exit, code, "Error while dumping volume \n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Error while dumping volume \n"))); PrintError(" ",(code )); } while (0); error = (code); goto error_exit; } } while ( 0); | ||
| 4391 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4392 | |||
| 4393 | error_exit: | ||
| 4394 | /* now delete the clone */ | ||
| 4395 | VEPRINT1("Deleting the cloned volume %u ...", clonevol){ if (verbose) { fprintf(__stderrp, ("Deleting the cloned volume %u ..." ), (clonevol)); fflush(__stderrp); } }; | ||
| 4396 | code = AFSVolDeleteVolume(fromconn, clonetid); | ||
| 4397 | if (code) { | ||
| 4398 | fprintf(STDERR__stderrp, "Failed to delete the cloned volume %lu\n", | ||
| 4399 | (unsigned long)clonevol); | ||
| 4400 | } else { | ||
| 4401 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4402 | } | ||
| 4403 | |||
| 4404 | if (fromcall) { | ||
| 4405 | code = rx_EndCall(fromcall, rxError); | ||
| 4406 | if (code) { | ||
| 4407 | fprintf(STDERR__stderrp, "Error in rx_EndCall\n"); | ||
| 4408 | if (!error) | ||
| 4409 | error = code; | ||
| 4410 | } | ||
| 4411 | } | ||
| 4412 | if (clonetid) { | ||
| 4413 | VEPRINT1("Ending transaction on cloned volume %u...", clonevol){ if (verbose) { fprintf(__stderrp, ("Ending transaction on cloned volume %u..." ), (clonevol)); fflush(__stderrp); } }; | ||
| 4414 | code = AFSVolEndTrans(fromconn, clonetid, &rcode); | ||
| 4415 | if (code || rcode) { | ||
| 4416 | fprintf(STDERR__stderrp, | ||
| 4417 | "Could not end transaction on the cloned volume %lu\n", | ||
| 4418 | (unsigned long)clonevol); | ||
| 4419 | if (!error) | ||
| 4420 | error = (code ? code : rcode); | ||
| 4421 | } | ||
| 4422 | VEDONE{ if (verbose) { fprintf(__stderrp, " done\n"); fflush(__stderrp ); } }; | ||
| 4423 | } | ||
| 4424 | if (fromconn) | ||
| 4425 | rx_DestroyConnection(fromconn); | ||
| 4426 | |||
| 4427 | PrintError("", error); | ||
| 4428 | return (error); | ||
| 4429 | } | ||
| 4430 | |||
| 4431 | |||
| 4432 | |||
| 4433 | /* | ||
| 4434 | * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from | ||
| 4435 | * the dump file <afilename>. WriteData does all the real work | ||
| 4436 | * after extracting params from the rock | ||
| 4437 | */ | ||
| 4438 | int | ||
| 4439 | UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid, | ||
| 4440 | afs_uint32 toparentid, char tovolname[], int flags, | ||
| 4441 | afs_int32(*WriteData) (struct rx_call *, void *), | ||
| 4442 | void *rock) | ||
| 4443 | { | ||
| 4444 | struct rx_connection *toconn, *tempconn; | ||
| 4445 | struct rx_call *tocall; | ||
| 4446 | afs_int32 totid, code, rcode, vcode, terror = 0; | ||
| 4447 | afs_int32 rxError = 0; | ||
| 4448 | struct volser_status tstatus; | ||
| 4449 | struct volintInfo vinfo; | ||
| 4450 | char partName[10]; | ||
| 4451 | char tovolreal[VOLSER_OLDMAXVOLNAME32]; | ||
| 4452 | afs_uint32 pvolid; | ||
| 4453 | afs_int32 temptid, pparentid; | ||
| 4454 | int success; | ||
| 4455 | struct nvldbentry entry, storeEntry; | ||
| 4456 | afs_int32 error; | ||
| 4457 | int islocked; | ||
| 4458 | struct restoreCookie cookie; | ||
| 4459 | int reuseID; | ||
| 4460 | afs_int32 volflag, voltype, volsertype; | ||
| 4461 | afs_int32 oldCreateDate, oldUpdateDate, newCreateDate, newUpdateDate; | ||
| 4462 | int index, same, errcode; | ||
| 4463 | char apartName[10]; | ||
| 4464 | char hoststr[16]; | ||
| 4465 | |||
| 4466 | memset(&cookie, 0, sizeof(cookie)); | ||
| 4467 | islocked = 0; | ||
| 4468 | success = 0; | ||
| 4469 | error = 0; | ||
| 4470 | reuseID = 1; | ||
| 4471 | tocall = (struct rx_call *)0; | ||
| 4472 | toconn = (struct rx_connection *)0; | ||
| 4473 | tempconn = (struct rx_connection *)0; | ||
| 4474 | totid = 0; | ||
| 4475 | temptid = 0; | ||
| 4476 | |||
| 4477 | if (flags & RV_RDONLY0x010000) { | ||
| 4478 | voltype = ROVOL1; | ||
| 4479 | volsertype = volser_RO1; | ||
| 4480 | } else { | ||
| 4481 | voltype = RWVOL0; | ||
| 4482 | volsertype = volser_RW0; | ||
| 4483 | } | ||
| 4484 | |||
| 4485 | pvolid = tovolid; | ||
| 4486 | pparentid = toparentid; | ||
| 4487 | toconn = UV_Bind(toserver, AFSCONF_VOLUMEPORT7005); | ||
| 4488 | if (pvolid == 0) { /*alot a new id if needed */ | ||
| 4489 | vcode = VLDB_GetEntryByName(tovolname, &entry); | ||
| 4490 | if (vcode == VL_NOENT(363524L)) { | ||
| 4491 | vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &pvolid); | ||
| 4492 | if (vcode) { | ||
| 4493 | fprintf(STDERR__stderrp, "Could not get an Id for the volume %s\n", | ||
| 4494 | tovolname); | ||
| 4495 | error = vcode; | ||
| 4496 | goto refail; | ||
| 4497 | } | ||
| 4498 | reuseID = 0; | ||
| 4499 | } else if (flags & RV_RDONLY0x010000) { | ||
| 4500 | if (entry.flags & RW_EXISTS0x1000) { | ||
| 4501 | fprintf(STDERR__stderrp, | ||
| 4502 | "Entry for ReadWrite volume %s already exists!\n", | ||
| 4503 | entry.name); | ||
| 4504 | error = VOLSERBADOP(1492325131L); | ||
| 4505 | goto refail; | ||
| 4506 | } | ||
| 4507 | if (!entry.volumeId[ROVOL1]) { | ||
| 4508 | fprintf(STDERR__stderrp, | ||
| 4509 | "Existing entry for volume %s has no ReadOnly ID\n", | ||
| 4510 | tovolname); | ||
| 4511 | error = VOLSERBADOP(1492325131L); | ||
| 4512 | goto refail; | ||
| 4513 | } | ||
| 4514 | pvolid = entry.volumeId[ROVOL1]; | ||
| 4515 | pparentid = entry.volumeId[RWVOL0]; | ||
| 4516 | } else { | ||
| 4517 | pvolid = entry.volumeId[RWVOL0]; | ||
| 4518 | pparentid = entry.volumeId[RWVOL0]; | ||
| 4519 | } | ||
| 4520 | } | ||
| 4521 | if (!pparentid) pparentid = pvolid; | ||
| 4522 | /* at this point we have a volume id to use/reuse for the volume to be restored */ | ||
| 4523 | strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME32); | ||
| 4524 | |||
| 4525 | if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME32 - 1)) { | ||
| 4526 | EGOTO1(refail, VOLSERBADOP,do { if ((1492325131L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n" )), ((tovolname))); PrintError(" ",((1492325131L))); } while (0); error = ((1492325131L)); goto refail; } } while (0) | ||
| 4527 | "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",do { if ((1492325131L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n" )), ((tovolname))); PrintError(" ",((1492325131L))); } while (0); error = ((1492325131L)); goto refail; } } while (0) | ||
| 4528 | tovolname)do { if ((1492325131L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n" )), ((tovolname))); PrintError(" ",((1492325131L))); } while (0); error = ((1492325131L)); goto refail; } } while (0); | ||
| 4529 | } else { | ||
| 4530 | if ((pparentid != pvolid) && (flags & RV_RDONLY0x010000)) { | ||
| 4531 | if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME32 - 10)) { | ||
| 4532 | EGOTO1(refail, VOLSERBADOP,do { if ((1492325131L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n" )), ((tovolname))); PrintError(" ",((1492325131L))); } while (0); error = ((1492325131L)); goto refail; } } while (0) | ||
| 4533 | "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n", tovolname)do { if ((1492325131L)) { do { fprintf(__stderrp, "\n"); fprintf (__stderrp, (("The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n" )), ((tovolname))); PrintError(" ",((1492325131L))); } while (0); error = ((1492325131L)); goto refail; } } while (0); | ||
| 4534 | } | ||
| 4535 | snprintf(tovolreal, VOLSER_OLDMAXVOLNAME32, "%s.readonly", tovolname); | ||
| 4536 | } | ||
| 4537 | } | ||
| 4538 | MapPartIdIntoName(topart, partName); | ||
| 4539 | fprintf(STDOUT__stdoutp, "Restoring volume %s Id %lu on server %s partition %s ..", | ||
| 4540 | tovolreal, (unsigned long)pvolid, | ||
| 4541 | noresolve ? afs_inet_ntoa_r(toserver, hoststr) : | ||
| 4542 | hostutil_GetNameByINet(toserver), partName); | ||
| 4543 | fflush(STDOUT__stdoutp); | ||
| 4544 | code = | ||
| 4545 | AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, &pvolid, | ||
| 4546 | &totid); | ||
| 4547 | if (code) { | ||
| 4548 | if (flags & RV_FULLRST0x000001) { /* full restore: delete then create anew */ | ||
| 4549 | VPRINT1("Deleting the previous volume %u ...", pvolid){ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u ..." ), (pvolid)); fflush(__stdoutp); } }; | ||
| 4550 | |||
| 4551 | code = | ||
| 4552 | AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline1, &totid); | ||
| 4553 | EGOTO1(refail, code, "Failed to start transaction on %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start transaction on %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0) | ||
| 4554 | pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start transaction on %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4555 | |||
| 4556 | code = AFSVolGetStatus(toconn, totid, &tstatus); | ||
| 4557 | EGOTO1(refail, code, "Could not get timestamp from volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get timestamp from volume %u\n")), ((pvolid))) ; PrintError(" ",(code)); } while (0); error = (code); goto refail; } } while (0) | ||
| 4558 | pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get timestamp from volume %u\n")), ((pvolid))) ; PrintError(" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4559 | |||
| 4560 | oldCreateDate = tstatus.creationDate; | ||
| 4561 | oldUpdateDate = tstatus.updateDate; | ||
| 4562 | |||
| 4563 | code = | ||
| 4564 | AFSVolSetFlags(toconn, totid, | ||
| 4565 | VTDeleteOnSalvage1 | VTOutOfService2); | ||
| 4566 | EGOTO1(refail, code, "Could not set flags on volume %u \n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set flags on volume %u \n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0) | ||
| 4567 | pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not set flags on volume %u \n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4568 | |||
| 4569 | code = AFSVolDeleteVolume(toconn, totid); | ||
| 4570 | EGOTO1(refail, code, "Could not delete volume %u\n", pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not delete volume %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4571 | |||
| 4572 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 4573 | totid = 0; | ||
| 4574 | if (!code) | ||
| 4575 | code = rcode; | ||
| 4576 | EGOTO1(refail, code, "Could not end transaction on %u\n", pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not end transaction on %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4577 | |||
| 4578 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 4579 | |||
| 4580 | code = | ||
| 4581 | AFSVolCreateVolume(toconn, topart, tovolreal, volsertype, pparentid, | ||
| 4582 | &pvolid, &totid); | ||
| 4583 | EGOTO1(refail, code, "Could not create new volume %u\n", pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not create new volume %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4584 | } else { | ||
| 4585 | code = | ||
| 4586 | AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline1, &totid); | ||
| 4587 | EGOTO1(refail, code, "Failed to start transaction on %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start transaction on %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0) | ||
| 4588 | pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Failed to start transaction on %u\n")), ((pvolid))); PrintError (" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4589 | |||
| 4590 | code = AFSVolGetStatus(toconn, totid, &tstatus); | ||
| 4591 | EGOTO1(refail, code, "Could not get timestamp from volume %u\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get timestamp from volume %u\n")), ((pvolid))) ; PrintError(" ",(code)); } while (0); error = (code); goto refail; } } while (0) | ||
| 4592 | pvolid)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not get timestamp from volume %u\n")), ((pvolid))) ; PrintError(" ",(code)); } while (0); error = (code); goto refail; } } while (0); | ||
| 4593 | |||
| 4594 | oldCreateDate = tstatus.creationDate; | ||
| 4595 | oldUpdateDate = tstatus.updateDate; | ||
| 4596 | } | ||
| 4597 | } else { | ||
| 4598 | oldCreateDate = 0; | ||
| 4599 | oldUpdateDate = 0; | ||
| 4600 | } | ||
| 4601 | |||
| 4602 | cookie.parent = pparentid; | ||
| 4603 | cookie.type = voltype; | ||
| 4604 | cookie.clone = 0; | ||
| 4605 | strncpy(cookie.name, tovolreal, VOLSER_OLDMAXVOLNAME32); | ||
| 4606 | |||
| 4607 | tocall = rx_NewCall(toconn); | ||
| 4608 | terror = StartAFSVolRestore(tocall, totid, 1, &cookie); | ||
| 4609 | if (terror) { | ||
| 4610 | fprintf(STDERR__stderrp, "Volume restore Failed \n"); | ||
| 4611 | error = terror; | ||
| 4612 | goto refail; | ||
| 4613 | } | ||
| 4614 | code = WriteData(tocall, rock); | ||
| 4615 | if (code) { | ||
| 4616 | fprintf(STDERR__stderrp, "Could not transmit data\n"); | ||
| 4617 | error = code; | ||
| 4618 | goto refail; | ||
| 4619 | } | ||
| 4620 | terror = rx_EndCall(tocall, rxError); | ||
| 4621 | tocall = (struct rx_call *)0; | ||
| 4622 | if (terror) { | ||
| 4623 | fprintf(STDERR__stderrp, "rx_EndCall Failed \n"); | ||
| 4624 | error = terror; | ||
| 4625 | goto refail; | ||
| 4626 | } | ||
| 4627 | code = AFSVolGetStatus(toconn, totid, &tstatus); | ||
| 4628 | if (code) { | ||
| 4629 | fprintf(STDERR__stderrp, | ||
| 4630 | "Could not get status information about the volume %lu\n", | ||
| 4631 | (unsigned long)pvolid); | ||
| 4632 | error = code; | ||
| 4633 | goto refail; | ||
| 4634 | } | ||
| 4635 | code = AFSVolSetIdsTypes(toconn, totid, tovolreal, voltype, pparentid, 0, 0); | ||
| 4636 | if (code) { | ||
| 4637 | fprintf(STDERR__stderrp, "Could not set the right type and ID on %lu\n", | ||
| 4638 | (unsigned long)pvolid); | ||
| 4639 | error = code; | ||
| 4640 | goto refail; | ||
| 4641 | } | ||
| 4642 | |||
| 4643 | if (flags & RV_CRDUMP0x000010) | ||
| 4644 | newCreateDate = tstatus.creationDate; | ||
| 4645 | else if (flags & RV_CRKEEP0x000020 && oldCreateDate != 0) | ||
| 4646 | newCreateDate = oldCreateDate; | ||
| 4647 | else | ||
| 4648 | newCreateDate = time(0); | ||
| 4649 | if (flags & RV_LUDUMP0x000100) | ||
| 4650 | newUpdateDate = tstatus.updateDate; | ||
| 4651 | else if (flags & RV_LUKEEP0x000200) | ||
| 4652 | newUpdateDate = oldUpdateDate; | ||
| 4653 | else | ||
| 4654 | newUpdateDate = time(0); | ||
| 4655 | code = AFSVolSetDate(toconn,totid, newCreateDate); | ||
| 4656 | if (code) { | ||
| 4657 | fprintf(STDERR__stderrp, "Could not set the 'creation' date on %u\n", pvolid); | ||
| 4658 | error = code; | ||
| 4659 | goto refail; | ||
| 4660 | } | ||
| 4661 | |||
| 4662 | init_volintInfo(&vinfo); | ||
| 4663 | vinfo.creationDate = newCreateDate; | ||
| 4664 | vinfo.updateDate = newUpdateDate; | ||
| 4665 | code = AFSVolSetInfo(toconn, totid, &vinfo); | ||
| 4666 | if (code) { | ||
| 4667 | fprintf(STDERR__stderrp, "Could not set the 'last updated' date on %u\n", | ||
| 4668 | pvolid); | ||
| 4669 | error = code; | ||
| 4670 | goto refail; | ||
| 4671 | } | ||
| 4672 | |||
| 4673 | volflag = ((flags & RV_OFFLINE0x000002) ? VTOutOfService2 : 0); /* off or on-line */ | ||
| 4674 | code = AFSVolSetFlags(toconn, totid, volflag); | ||
| 4675 | if (code) { | ||
| 4676 | fprintf(STDERR__stderrp, "Could not mark %lu online\n", (unsigned long)pvolid); | ||
| 4677 | error = code; | ||
| 4678 | goto refail; | ||
| 4679 | } | ||
| 4680 | |||
| 4681 | /* It isn't handled right in refail */ | ||
| 4682 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 4683 | totid = 0; | ||
| 4684 | if (!code) | ||
| 4685 | code = rcode; | ||
| 4686 | if (code) { | ||
| 4687 | fprintf(STDERR__stderrp, "Could not end transaction on %lu\n", | ||
| 4688 | (unsigned long)pvolid); | ||
| 4689 | error = code; | ||
| 4690 | goto refail; | ||
| 4691 | } | ||
| 4692 | |||
| 4693 | success = 1; | ||
| 4694 | fprintf(STDOUT__stdoutp, " done\n"); | ||
| 4695 | fflush(STDOUT__stdoutp); | ||
| 4696 | if (success && (!reuseID || (flags & RV_FULLRST0x000001))) { | ||
| 4697 | /* Volume was restored on the file server, update the | ||
| 4698 | * VLDB to reflect the change. | ||
| 4699 | */ | ||
| 4700 | vcode = VLDB_GetEntryByID(pvolid, voltype, &entry); | ||
| 4701 | if (vcode && vcode != VL_NOENT(363524L) && vcode != VL_ENTDELETED(363526L)) { | ||
| 4702 | fprintf(STDERR__stderrp, | ||
| 4703 | "Could not fetch the entry for volume number %lu from VLDB \n", | ||
| 4704 | (unsigned long)pvolid); | ||
| 4705 | error = vcode; | ||
| 4706 | goto refail; | ||
| 4707 | } | ||
| 4708 | if (!vcode) | ||
| 4709 | MapHostToNetwork(&entry); | ||
| 4710 | if (vcode == VL_NOENT(363524L)) { /* it doesnot exist already */ | ||
| 4711 | /*make the vldb return this indication specifically */ | ||
| 4712 | VPRINT("------- Creating a new VLDB entry ------- \n"){ if (verbose) { fprintf(__stdoutp, ("------- Creating a new VLDB entry ------- \n" )); fflush(__stdoutp); } }; | ||
| 4713 | strcpy(entry.name, tovolname); | ||
| 4714 | entry.nServers = 1; | ||
| 4715 | entry.serverNumber[0] = toserver; /*should be indirect */ | ||
| 4716 | entry.serverPartition[0] = topart; | ||
| 4717 | entry.serverFlags[0] = (flags & RV_RDONLY0x010000) ? ITSROVOL0x02 : ITSRWVOL0x04; | ||
| 4718 | entry.flags = (flags & RV_RDONLY0x010000) ? RO_EXISTS0x2000 : RW_EXISTS0x1000; | ||
| 4719 | if (flags & RV_RDONLY0x010000) | ||
| 4720 | entry.volumeId[ROVOL1] = pvolid; | ||
| 4721 | else if (tstatus.cloneID != 0) { | ||
| 4722 | entry.volumeId[ROVOL1] = tstatus.cloneID; /*this should come from status info on the volume if non zero */ | ||
| 4723 | } else | ||
| 4724 | entry.volumeId[ROVOL1] = INVALID_BID0; | ||
| 4725 | entry.volumeId[RWVOL0] = pparentid; | ||
| 4726 | entry.cloneId = 0; | ||
| 4727 | if (tstatus.backupID != 0) { | ||
| 4728 | entry.volumeId[BACKVOL2] = tstatus.backupID; | ||
| 4729 | /*this should come from status info on the volume if non zero */ | ||
| 4730 | } else | ||
| 4731 | entry.volumeId[BACKVOL2] = INVALID_BID0; | ||
| 4732 | MapNetworkToHost(&entry, &storeEntry); | ||
| 4733 | vcode = VLDB_CreateEntry(&storeEntry); | ||
| 4734 | if (vcode) { | ||
| 4735 | fprintf(STDERR__stderrp, | ||
| 4736 | "Could not create the VLDB entry for volume number %lu \n", | ||
| 4737 | (unsigned long)pvolid); | ||
| 4738 | error = vcode; | ||
| 4739 | goto refail; | ||
| 4740 | } | ||
| 4741 | islocked = 0; | ||
| 4742 | if (verbose) | ||
| 4743 | EnumerateEntry(&entry); | ||
| 4744 | } else { /*update the existing entry */ | ||
| 4745 | if (verbose) { | ||
| 4746 | fprintf(STDOUT__stdoutp, "Updating the existing VLDB entry\n"); | ||
| 4747 | fprintf(STDOUT__stdoutp, "------- Old entry -------\n"); | ||
| 4748 | EnumerateEntry(&entry); | ||
| 4749 | fprintf(STDOUT__stdoutp, "------- New entry -------\n"); | ||
| 4750 | } | ||
| 4751 | vcode = | ||
| 4752 | ubik_VL_SetLock(cstruct, 0, pvolid, voltype, | ||
| 4753 | VLOP_RESTORE0x100); | ||
| 4754 | if (vcode) { | ||
| 4755 | fprintf(STDERR__stderrp, | ||
| 4756 | "Could not lock the entry for volume number %lu \n", | ||
| 4757 | (unsigned long)pvolid); | ||
| 4758 | error = vcode; | ||
| 4759 | goto refail; | ||
| 4760 | } | ||
| 4761 | islocked = 1; | ||
| 4762 | strcpy(entry.name, tovolname); | ||
| 4763 | |||
| 4764 | /* Update the vlentry with the new information */ | ||
| 4765 | if (flags & RV_RDONLY0x010000) | ||
| 4766 | index = Lp_ROMatch(toserver, topart, &entry) - 1; | ||
| 4767 | else | ||
| 4768 | index = Lp_GetRwIndex(&entry); | ||
| 4769 | if (index == -1) { | ||
| 4770 | /* Add the new site for the volume being restored */ | ||
| 4771 | entry.serverNumber[entry.nServers] = toserver; | ||
| 4772 | entry.serverPartition[entry.nServers] = topart; | ||
| 4773 | entry.serverFlags[entry.nServers] = | ||
| 4774 | (flags & RV_RDONLY0x010000) ? ITSROVOL0x02 : ITSRWVOL0x04; | ||
| 4775 | entry.nServers++; | ||
| 4776 | } else { | ||
| 4777 | /* This volume should be deleted on the old site | ||
| 4778 | * if its different from new site. | ||
| 4779 | */ | ||
| 4780 | same = | ||
| 4781 | VLDB_IsSameAddrs(toserver, entry.serverNumber[index], | ||
| 4782 | &errcode); | ||
| 4783 | if (errcode) | ||
| 4784 | EPRINT2(errcode,do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Failed to get info about server's %d address(es) from vlserver (err=%d)\n" ), (toserver), (errcode)); PrintError(" ",errcode); } while (0) | ||
| 4785 | "Failed to get info about server's %d address(es) from vlserver (err=%d)\n",do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Failed to get info about server's %d address(es) from vlserver (err=%d)\n" ), (toserver), (errcode)); PrintError(" ",errcode); } while (0) | ||
| 4786 | toserver, errcode)do { fprintf(__stderrp, "\n"); fprintf(__stderrp, ("Failed to get info about server's %d address(es) from vlserver (err=%d)\n" ), (toserver), (errcode)); PrintError(" ",errcode); } while (0); | ||
| 4787 | if ((!errcode && !same) | ||
| 4788 | || (entry.serverPartition[index] != topart)) { | ||
| 4789 | if (flags & RV_NODEL0x100000) { | ||
| 4790 | VPRINT2{ if (verbose) { fprintf(__stdoutp, ("Not deleting the previous volume %u on server %s, ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index]))); fflush(__stdoutp); } } | ||
| 4791 | ("Not deleting the previous volume %u on server %s, ...",{ if (verbose) { fprintf(__stdoutp, ("Not deleting the previous volume %u on server %s, ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index]))); fflush(__stdoutp); } } | ||
| 4792 | pvolid,{ if (verbose) { fprintf(__stdoutp, ("Not deleting the previous volume %u on server %s, ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index]))); fflush(__stdoutp); } } | ||
| 4793 | noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :{ if (verbose) { fprintf(__stdoutp, ("Not deleting the previous volume %u on server %s, ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index]))); fflush(__stdoutp); } } | ||
| 4794 | hostutil_GetNameByINet(entry.serverNumber[index])){ if (verbose) { fprintf(__stdoutp, ("Not deleting the previous volume %u on server %s, ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index]))); fflush(__stdoutp); } }; | ||
| 4795 | } else { | ||
| 4796 | tempconn = | ||
| 4797 | UV_Bind(entry.serverNumber[index], | ||
| 4798 | AFSCONF_VOLUMEPORT7005); | ||
| 4799 | |||
| 4800 | MapPartIdIntoName(entry.serverPartition[index], | ||
| 4801 | apartName); | ||
| 4802 | VPRINT3{ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u on server %s, partition %s ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index])), (apartName)); fflush(__stdoutp); } } | ||
| 4803 | ("Deleting the previous volume %u on server %s, partition %s ...",{ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u on server %s, partition %s ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index])), (apartName)); fflush(__stdoutp); } } | ||
| 4804 | pvolid,{ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u on server %s, partition %s ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index])), (apartName)); fflush(__stdoutp); } } | ||
| 4805 | noresolve ? afs_inet_ntoa_r(entry.serverNumber[index], hoststr) :{ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u on server %s, partition %s ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index])), (apartName)); fflush(__stdoutp); } } | ||
| 4806 | hostutil_GetNameByINet(entry.serverNumber[index]),{ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u on server %s, partition %s ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index])), (apartName)); fflush(__stdoutp); } } | ||
| 4807 | apartName){ if (verbose) { fprintf(__stdoutp, ("Deleting the previous volume %u on server %s, partition %s ..." ), (pvolid), (noresolve ? afs_inet_ntoa_r(entry.serverNumber[ index], hoststr) : hostutil_GetNameByINet(entry.serverNumber[ index])), (apartName)); fflush(__stdoutp); } }; | ||
| 4808 | code = | ||
| 4809 | AFSVolTransCreate_retry(tempconn, pvolid, | ||
| 4810 | entry.serverPartition[index], | ||
| 4811 | ITOffline1, &temptid); | ||
| 4812 | if (!code) { | ||
| 4813 | code = | ||
| 4814 | AFSVolSetFlags(tempconn, temptid, | ||
| 4815 | VTDeleteOnSalvage1 | | ||
| 4816 | VTOutOfService2); | ||
| 4817 | if (code) { | ||
| 4818 | fprintf(STDERR__stderrp, | ||
| 4819 | "Could not set flags on volume %lu on the older site\n", | ||
| 4820 | (unsigned long)pvolid); | ||
| 4821 | error = code; | ||
| 4822 | goto refail; | ||
| 4823 | } | ||
| 4824 | code = AFSVolDeleteVolume(tempconn, temptid); | ||
| 4825 | if (code) { | ||
| 4826 | fprintf(STDERR__stderrp, | ||
| 4827 | "Could not delete volume %lu on the older site\n", | ||
| 4828 | (unsigned long)pvolid); | ||
| 4829 | error = code; | ||
| 4830 | goto refail; | ||
| 4831 | } | ||
| 4832 | code = AFSVolEndTrans(tempconn, temptid, &rcode); | ||
| 4833 | temptid = 0; | ||
| 4834 | if (!code) | ||
| 4835 | code = rcode; | ||
| 4836 | if (code) { | ||
| 4837 | fprintf(STDERR__stderrp, | ||
| 4838 | "Could not end transaction on volume %lu on the older site\n", | ||
| 4839 | (unsigned long)pvolid); | ||
| 4840 | error = code; | ||
| 4841 | goto refail; | ||
| 4842 | } | ||
| 4843 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 4844 | MapPartIdIntoName(entry.serverPartition[index], | ||
| 4845 | partName); | ||
| 4846 | } | ||
| 4847 | } | ||
| 4848 | } | ||
| 4849 | entry.serverNumber[index] = toserver; | ||
| 4850 | entry.serverPartition[index] = topart; | ||
| 4851 | } | ||
| 4852 | |||
| 4853 | entry.flags |= (flags & RV_RDONLY0x010000) ? RO_EXISTS0x2000 : RW_EXISTS0x1000; | ||
| 4854 | MapNetworkToHost(&entry, &storeEntry); | ||
| 4855 | vcode = | ||
| 4856 | VLDB_ReplaceEntry(pvolid, voltype, &storeEntry, | ||
| 4857 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 4858 | LOCKREL_TIMESTAMP1); | ||
| 4859 | if (vcode) { | ||
| 4860 | fprintf(STDERR__stderrp, | ||
| 4861 | "Could not update the entry for volume number %lu \n", | ||
| 4862 | (unsigned long)pvolid); | ||
| 4863 | error = vcode; | ||
| 4864 | goto refail; | ||
| 4865 | } | ||
| 4866 | islocked = 0; | ||
| 4867 | if (verbose) | ||
| 4868 | EnumerateEntry(&entry); | ||
| 4869 | } | ||
| 4870 | |||
| 4871 | |||
| 4872 | } | ||
| 4873 | refail: | ||
| 4874 | if (tocall) { | ||
| 4875 | code = rx_EndCall(tocall, rxError); | ||
| 4876 | if (!error) | ||
| 4877 | error = code; | ||
| 4878 | } | ||
| 4879 | if (islocked) { | ||
| 4880 | vcode = | ||
| 4881 | ubik_VL_ReleaseLock(cstruct, 0, pvolid, voltype, | ||
| 4882 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 4883 | if (vcode) { | ||
| 4884 | fprintf(STDERR__stderrp, | ||
| 4885 | "Could not release lock on the VLDB entry for the volume %lu\n", | ||
| 4886 | (unsigned long)pvolid); | ||
| 4887 | if (!error) | ||
| 4888 | error = vcode; | ||
| 4889 | } | ||
| 4890 | } | ||
| 4891 | if (totid) { | ||
| 4892 | code = AFSVolEndTrans(toconn, totid, &rcode); | ||
| 4893 | if (!code) | ||
| 4894 | code = rcode; | ||
| 4895 | if (code) { | ||
| 4896 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %lu \n", | ||
| 4897 | (unsigned long)pvolid); | ||
| 4898 | if (!error) | ||
| 4899 | error = code; | ||
| 4900 | } | ||
| 4901 | } | ||
| 4902 | if (temptid) { | ||
| 4903 | code = AFSVolEndTrans(toconn, temptid, &rcode); | ||
| 4904 | if (!code) | ||
| 4905 | code = rcode; | ||
| 4906 | if (code) { | ||
| 4907 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %lu \n", | ||
| 4908 | (unsigned long)pvolid); | ||
| 4909 | if (!error) | ||
| 4910 | error = code; | ||
| 4911 | } | ||
| 4912 | } | ||
| 4913 | if (tempconn) | ||
| 4914 | rx_DestroyConnection(tempconn); | ||
| 4915 | if (toconn) | ||
| 4916 | rx_DestroyConnection(toconn); | ||
| 4917 | PrintError("", error); | ||
| 4918 | return error; | ||
| 4919 | } | ||
| 4920 | |||
| 4921 | int | ||
| 4922 | UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid, | ||
| 4923 | char tovolname[], int flags, | ||
| 4924 | afs_int32(*WriteData) (struct rx_call *, void *), | ||
| 4925 | void *rock) | ||
| 4926 | { | ||
| 4927 | return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags, | ||
| 4928 | WriteData, rock); | ||
| 4929 | } | ||
| 4930 | |||
| 4931 | |||
| 4932 | /*unlocks the vldb entry associated with <volid> */ | ||
| 4933 | int | ||
| 4934 | UV_LockRelease(afs_uint32 volid) | ||
| 4935 | { | ||
| 4936 | afs_int32 vcode; | ||
| 4937 | |||
| 4938 | VPRINT("Binding to the VLDB server\n"){ if (verbose) { fprintf(__stdoutp, ("Binding to the VLDB server\n" )); fflush(__stdoutp); } }; | ||
| 4939 | vcode = | ||
| 4940 | ubik_VL_ReleaseLock(cstruct, 0, volid, -1, | ||
| 4941 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 4942 | if (vcode) { | ||
| 4943 | fprintf(STDERR__stderrp, | ||
| 4944 | "Could not unlock the entry for volume number %lu in VLDB \n", | ||
| 4945 | (unsigned long)volid); | ||
| 4946 | PrintError("", vcode); | ||
| 4947 | return (vcode); | ||
| 4948 | } | ||
| 4949 | VPRINT("VLDB updated\n"){ if (verbose) { fprintf(__stdoutp, ("VLDB updated\n")); fflush (__stdoutp); } }; | ||
| 4950 | return 0; | ||
| 4951 | |||
| 4952 | } | ||
| 4953 | |||
| 4954 | /* old interface to add rosites */ | ||
| 4955 | int | ||
| 4956 | UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid, | ||
| 4957 | afs_int32 valid) | ||
| 4958 | { | ||
| 4959 | return UV_AddSite2(server, part, volid, 0, valid); | ||
| 4960 | } | ||
| 4961 | |||
| 4962 | /*adds <server> and <part> as a readonly replication site for <volid> | ||
| 4963 | *in vldb */ | ||
| 4964 | int | ||
| 4965 | UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid, | ||
| 4966 | afs_uint32 rovolid, afs_int32 valid) | ||
| 4967 | { | ||
| 4968 | int j, nro = 0, islocked = 0; | ||
| 4969 | struct nvldbentry entry, storeEntry, entry2; | ||
| 4970 | afs_int32 vcode, error = 0; | ||
| 4971 | char apartName[10]; | ||
| 4972 | |||
| 4973 | error = ubik_VL_SetLock(cstruct, 0, volid, RWVOL0, VLOP_ADDSITE0x80); | ||
| 4974 | if (error) { | ||
| 4975 | fprintf(STDERR__stderrp, | ||
| 4976 | " Could not lock the VLDB entry for the volume %lu \n", | ||
| 4977 | (unsigned long)volid); | ||
| 4978 | goto asfail; | ||
| 4979 | } | ||
| 4980 | islocked = 1; | ||
| 4981 | |||
| 4982 | error = VLDB_GetEntryByID(volid, RWVOL0, &entry); | ||
| 4983 | if (error) { | ||
| 4984 | fprintf(STDERR__stderrp, | ||
| 4985 | "Could not fetch the VLDB entry for volume number %lu \n", | ||
| 4986 | (unsigned long)volid); | ||
| 4987 | goto asfail; | ||
| 4988 | |||
| 4989 | } | ||
| 4990 | if (!ISNAMEVALID(entry.name)(strlen(entry.name) < (32 - 9))) { | ||
| 4991 | fprintf(STDERR__stderrp, | ||
| 4992 | "Volume name %s is too long, rename before adding site\n", | ||
| 4993 | entry.name); | ||
| 4994 | error = VOLSERBADOP(1492325131L); | ||
| 4995 | goto asfail; | ||
| 4996 | } | ||
| 4997 | MapHostToNetwork(&entry); | ||
| 4998 | |||
| 4999 | /* See if it's too many entries */ | ||
| 5000 | if (entry.nServers >= NMAXNSERVERS13) { | ||
| 5001 | fprintf(STDERR__stderrp, "Total number of entries will exceed %u\n", | ||
| 5002 | NMAXNSERVERS13); | ||
| 5003 | error = VOLSERBADOP(1492325131L); | ||
| 5004 | goto asfail; | ||
| 5005 | } | ||
| 5006 | |||
| 5007 | /* See if it's on the same server */ | ||
| 5008 | for (j = 0; j < entry.nServers; j++) { | ||
| 5009 | if (entry.serverFlags[j] & ITSROVOL0x02) { | ||
| 5010 | nro++; | ||
| 5011 | if (VLDB_IsSameAddrs(server, entry.serverNumber[j], &error)) { | ||
| 5012 | if (error) { | ||
| 5013 | fprintf(STDERR__stderrp, | ||
| 5014 | "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", | ||
| 5015 | server, error); | ||
| 5016 | } else { | ||
| 5017 | MapPartIdIntoName(entry.serverPartition[j], apartName); | ||
| 5018 | fprintf(STDERR__stderrp, | ||
| 5019 | "RO already exists on partition %s. Multiple ROs on a single server aren't allowed\n", | ||
| 5020 | apartName); | ||
| 5021 | error = VOLSERBADOP(1492325131L); | ||
| 5022 | } | ||
| 5023 | goto asfail; | ||
| 5024 | } | ||
| 5025 | } | ||
| 5026 | } | ||
| 5027 | |||
| 5028 | /* See if it's too many RO sites - leave one for the RW */ | ||
| 5029 | if (nro >= NMAXNSERVERS13 - 1) { | ||
| 5030 | fprintf(STDERR__stderrp, "Total number of sites will exceed %u\n", | ||
| 5031 | NMAXNSERVERS13 - 1); | ||
| 5032 | error = VOLSERBADOP(1492325131L); | ||
| 5033 | goto asfail; | ||
| 5034 | } | ||
| 5035 | |||
| 5036 | /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't | ||
| 5037 | * have an RO volid at this point (i.e. entry.volumeId[ROVOL] == | ||
| 5038 | * INVALID_BID) and we leave it alone, it gets an RO volid at release-time. | ||
| 5039 | */ | ||
| 5040 | if (rovolid) { | ||
| 5041 | if (entry.volumeId[ROVOL1] == INVALID_BID0) { | ||
| 5042 | vcode = VLDB_GetEntryByID(rovolid, -1, &entry2); | ||
| 5043 | if (!vcode) { | ||
| 5044 | fprintf(STDERR__stderrp, "Volume ID %d already exists\n", rovolid); | ||
| 5045 | return VVOLEXISTS104; | ||
| 5046 | } | ||
| 5047 | VPRINT1("Using RO volume id %d.\n", rovolid){ if (verbose) { fprintf(__stdoutp, ("Using RO volume id %d.\n" ), (rovolid)); fflush(__stdoutp); } }; | ||
| 5048 | entry.volumeId[ROVOL1] = rovolid; | ||
| 5049 | } else { | ||
| 5050 | fprintf(STDERR__stderrp, "Ignoring given RO id %d, since volume already has RO id %d\n", | ||
| 5051 | rovolid, entry.volumeId[ROVOL1]); | ||
| 5052 | } | ||
| 5053 | } | ||
| 5054 | |||
| 5055 | VPRINT("Adding a new site ..."){ if (verbose) { fprintf(__stdoutp, ("Adding a new site ...") ); fflush(__stdoutp); } }; | ||
| 5056 | entry.serverNumber[entry.nServers] = server; | ||
| 5057 | entry.serverPartition[entry.nServers] = part; | ||
| 5058 | if (!valid) { | ||
| 5059 | entry.serverFlags[entry.nServers] = (ITSROVOL0x02 | RO_DONTUSE0x20); | ||
| 5060 | } else { | ||
| 5061 | entry.serverFlags[entry.nServers] = (ITSROVOL0x02); | ||
| 5062 | } | ||
| 5063 | entry.nServers++; | ||
| 5064 | |||
| 5065 | MapNetworkToHost(&entry, &storeEntry); | ||
| 5066 | error = | ||
| 5067 | VLDB_ReplaceEntry(volid, RWVOL0, &storeEntry, | ||
| 5068 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5069 | if (error) { | ||
| 5070 | fprintf(STDERR__stderrp, "Could not update entry for volume %lu \n", | ||
| 5071 | (unsigned long)volid); | ||
| 5072 | goto asfail; | ||
| 5073 | } | ||
| 5074 | islocked = 0; | ||
| 5075 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 5076 | |||
| 5077 | asfail: | ||
| 5078 | if (islocked) { | ||
| 5079 | vcode = | ||
| 5080 | ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL0, | ||
| 5081 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5082 | if (vcode) { | ||
| 5083 | fprintf(STDERR__stderrp, | ||
| 5084 | "Could not release lock on volume entry for %lu \n", | ||
| 5085 | (unsigned long)volid); | ||
| 5086 | PrintError("", vcode); | ||
| 5087 | } | ||
| 5088 | } | ||
| 5089 | |||
| 5090 | PrintError("", error); | ||
| 5091 | return error; | ||
| 5092 | } | ||
| 5093 | |||
| 5094 | /*removes <server> <part> as read only site for <volid> from the vldb */ | ||
| 5095 | int | ||
| 5096 | UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid) | ||
| 5097 | { | ||
| 5098 | afs_int32 vcode; | ||
| 5099 | struct nvldbentry entry, storeEntry; | ||
| 5100 | |||
| 5101 | vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL0, VLOP_ADDSITE0x80); | ||
| 5102 | if (vcode) { | ||
| 5103 | fprintf(STDERR__stderrp, " Could not lock the VLDB entry for volume %lu \n", | ||
| 5104 | (unsigned long)volid); | ||
| 5105 | PrintError("", vcode); | ||
| 5106 | return (vcode); | ||
| 5107 | } | ||
| 5108 | vcode = VLDB_GetEntryByID(volid, RWVOL0, &entry); | ||
| 5109 | if (vcode) { | ||
| 5110 | fprintf(STDERR__stderrp, | ||
| 5111 | "Could not fetch the entry for volume number %lu from VLDB \n", | ||
| 5112 | (unsigned long)volid); | ||
| 5113 | PrintError("", vcode); | ||
| 5114 | return (vcode); | ||
| 5115 | } | ||
| 5116 | MapHostToNetwork(&entry); | ||
| 5117 | if (!Lp_ROMatch(server, part, &entry)) { | ||
| 5118 | /*this site doesnot exist */ | ||
| 5119 | fprintf(STDERR__stderrp, "This site is not a replication site \n"); | ||
| 5120 | vcode = | ||
| 5121 | ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL0, | ||
| 5122 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5123 | if (vcode) { | ||
| 5124 | fprintf(STDERR__stderrp, "Could not update entry for volume %lu \n", | ||
| 5125 | (unsigned long)volid); | ||
| 5126 | PrintError("", vcode); | ||
| 5127 | ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL0, | ||
| 5128 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5129 | return (vcode); | ||
| 5130 | } | ||
| 5131 | return VOLSERBADOP(1492325131L); | ||
| 5132 | } else { /*remove the rep site */ | ||
| 5133 | Lp_SetROValue(&entry, server, part, 0, 0); | ||
| 5134 | entry.nServers--; | ||
| 5135 | if ((entry.nServers == 1) && (entry.flags & RW_EXISTS0x1000)) | ||
| 5136 | entry.flags &= ~RO_EXISTS0x2000; | ||
| 5137 | if (entry.nServers < 1) { /*this is the last ref */ | ||
| 5138 | VPRINT1("Deleting the VLDB entry for %u ...", volid){ if (verbose) { fprintf(__stdoutp, ("Deleting the VLDB entry for %u ..." ), (volid)); fflush(__stdoutp); } }; | ||
| 5139 | fflush(STDOUT__stdoutp); | ||
| 5140 | vcode = ubik_VL_DeleteEntry(cstruct, 0, volid, ROVOL1); | ||
| 5141 | if (vcode) { | ||
| 5142 | fprintf(STDERR__stderrp, | ||
| 5143 | "Could not delete VLDB entry for volume %lu \n", | ||
| 5144 | (unsigned long)volid); | ||
| 5145 | PrintError("", vcode); | ||
| 5146 | return (vcode); | ||
| 5147 | } | ||
| 5148 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 5149 | } | ||
| 5150 | MapNetworkToHost(&entry, &storeEntry); | ||
| 5151 | fprintf(STDOUT__stdoutp, "Deleting the replication site for volume %lu ...", | ||
| 5152 | (unsigned long)volid); | ||
| 5153 | fflush(STDOUT__stdoutp); | ||
| 5154 | vcode = | ||
| 5155 | VLDB_ReplaceEntry(volid, RWVOL0, &storeEntry, | ||
| 5156 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 5157 | LOCKREL_TIMESTAMP1); | ||
| 5158 | if (vcode) { | ||
| 5159 | fprintf(STDERR__stderrp, | ||
| 5160 | "Could not release lock on volume entry for %lu \n", | ||
| 5161 | (unsigned long)volid); | ||
| 5162 | PrintError("", vcode); | ||
| 5163 | ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL0, | ||
| 5164 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5165 | return (vcode); | ||
| 5166 | } | ||
| 5167 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 5168 | } | ||
| 5169 | return 0; | ||
| 5170 | } | ||
| 5171 | |||
| 5172 | /*sets <server> <part> as read/write site for <volid> in the vldb */ | ||
| 5173 | int | ||
| 5174 | UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid) | ||
| 5175 | { | ||
| 5176 | afs_int32 vcode; | ||
| 5177 | struct nvldbentry entry, storeEntry; | ||
| 5178 | int index; | ||
| 5179 | |||
| 5180 | vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL0, VLOP_ADDSITE0x80); | ||
| 5181 | if (vcode) { | ||
| 5182 | fprintf(STDERR__stderrp, " Could not lock the VLDB entry for volume %lu \n", | ||
| 5183 | (unsigned long)volid); | ||
| 5184 | PrintError("", vcode); | ||
| 5185 | return (vcode); | ||
| 5186 | } | ||
| 5187 | vcode = VLDB_GetEntryByID(volid, RWVOL0, &entry); | ||
| 5188 | if (vcode) { | ||
| 5189 | fprintf(STDERR__stderrp, | ||
| 5190 | "Could not fetch the entry for volume number %lu from VLDB \n", | ||
| 5191 | (unsigned long)volid); | ||
| 5192 | PrintError("", vcode); | ||
| 5193 | return (vcode); | ||
| 5194 | } | ||
| 5195 | MapHostToNetwork(&entry); | ||
| 5196 | index = Lp_GetRwIndex(&entry); | ||
| 5197 | if (index < 0) { | ||
| 5198 | /* no RW site exists */ | ||
| 5199 | fprintf(STDERR__stderrp, "No existing RW site for volume %lu", | ||
| 5200 | (unsigned long)volid); | ||
| 5201 | vcode = | ||
| 5202 | ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL0, | ||
| 5203 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5204 | if (vcode) { | ||
| 5205 | fprintf(STDERR__stderrp, | ||
| 5206 | "Could not release lock on entry for volume %lu \n", | ||
| 5207 | (unsigned long)volid); | ||
| 5208 | PrintError("", vcode); | ||
| 5209 | return (vcode); | ||
| 5210 | } | ||
| 5211 | return VOLSERBADOP(1492325131L); | ||
| 5212 | } else { /* change the RW site */ | ||
| 5213 | entry.serverNumber[index] = server; | ||
| 5214 | entry.serverPartition[index] = part; | ||
| 5215 | MapNetworkToHost(&entry, &storeEntry); | ||
| 5216 | vcode = | ||
| 5217 | VLDB_ReplaceEntry(volid, RWVOL0, &storeEntry, | ||
| 5218 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 5219 | LOCKREL_TIMESTAMP1); | ||
| 5220 | if (vcode) { | ||
| 5221 | fprintf(STDERR__stderrp, "Could not update entry for volume %lu \n", | ||
| 5222 | (unsigned long)volid); | ||
| 5223 | PrintError("", vcode); | ||
| 5224 | ubik_VL_ReleaseLock(cstruct, 0, volid, RWVOL0, | ||
| 5225 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 5226 | return (vcode); | ||
| 5227 | } | ||
| 5228 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 5229 | } | ||
| 5230 | return 0; | ||
| 5231 | } | ||
| 5232 | |||
| 5233 | /*list all the partitions on <aserver> */ | ||
| 5234 | int | ||
| 5235 | UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList, | ||
| 5236 | afs_int32 * cntp) | ||
| 5237 | { | ||
| 5238 | struct rx_connection *aconn; | ||
| 5239 | struct pIDs partIds; | ||
| 5240 | struct partEntries partEnts; | ||
| 5241 | int i, j = 0, code; | ||
| 5242 | |||
| 5243 | *cntp = 0; | ||
| 5244 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 5245 | |||
| 5246 | partEnts.partEntries_len = 0; | ||
| 5247 | partEnts.partEntries_val = NULL((void *)0); | ||
| 5248 | code = AFSVolXListPartitions(aconn, &partEnts); /* this is available only on new servers */ | ||
| 5249 | if (code == RXGEN_OPCODE-455) { | ||
| 5250 | for (i = 0; i < 26; i++) /* try old interface */ | ||
| 5251 | partIds.partIds[i] = -1; | ||
| 5252 | code = AFSVolListPartitions(aconn, &partIds); | ||
| 5253 | if (!code) { | ||
| 5254 | for (i = 0; i < 26; i++) { | ||
| 5255 | if ((partIds.partIds[i]) != -1) { | ||
| 5256 | ptrPartList->partId[j] = partIds.partIds[i]; | ||
| 5257 | ptrPartList->partFlags[j] = PARTVALID0x01; | ||
| 5258 | j++; | ||
| 5259 | } else | ||
| 5260 | ptrPartList->partFlags[i] = 0; | ||
| 5261 | } | ||
| 5262 | *cntp = j; | ||
| 5263 | } | ||
| 5264 | } else if (!code) { | ||
| 5265 | *cntp = partEnts.partEntries_len; | ||
| 5266 | if (*cntp > VOLMAXPARTS255) { | ||
| 5267 | fprintf(STDERR__stderrp, | ||
| 5268 | "Warning: number of partitions on the server too high %d (process only %d)\n", | ||
| 5269 | *cntp, VOLMAXPARTS255); | ||
| 5270 | *cntp = VOLMAXPARTS255; | ||
| 5271 | } | ||
| 5272 | for (i = 0; i < *cntp; i++) { | ||
| 5273 | ptrPartList->partId[i] = partEnts.partEntries_val[i]; | ||
| 5274 | ptrPartList->partFlags[i] = PARTVALID0x01; | ||
| 5275 | } | ||
| 5276 | free(partEnts.partEntries_val); | ||
| 5277 | } | ||
| 5278 | |||
| 5279 | /* out: */ | ||
| 5280 | if (code) | ||
| 5281 | fprintf(STDERR__stderrp, | ||
| 5282 | "Could not fetch the list of partitions from the server\n"); | ||
| 5283 | PrintError("", code); | ||
| 5284 | if (aconn) | ||
| 5285 | rx_DestroyConnection(aconn); | ||
| 5286 | return code; | ||
| 5287 | } | ||
| 5288 | |||
| 5289 | |||
| 5290 | /*zap the list of volumes specified by volPtrArray (the volCloneId field). | ||
| 5291 | This is used by the backup system */ | ||
| 5292 | int | ||
| 5293 | UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart, | ||
| 5294 | struct volDescription *volPtr, afs_int32 arraySize) | ||
| 5295 | { | ||
| 5296 | struct rx_connection *aconn; | ||
| 5297 | struct volDescription *curPtr; | ||
| 5298 | int curPos; | ||
| 5299 | afs_int32 code = 0; | ||
| 5300 | afs_int32 rcode = 0; | ||
| 5301 | afs_int32 success = 1; | ||
| 5302 | afs_int32 tid; | ||
| 5303 | |||
| 5304 | aconn = (struct rx_connection *)0; | ||
| 5305 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 5306 | curPos = 0; | ||
| 5307 | for (curPtr = volPtr; curPos < arraySize; curPtr++) { | ||
| 5308 | if (curPtr->volFlags & CLONEVALID0x02) { | ||
| 5309 | curPtr->volFlags &= ~CLONEZAPPED0x04; | ||
| 5310 | success = 1; | ||
| 5311 | code = | ||
| 5312 | AFSVolTransCreate_retry(aconn, curPtr->volCloneId, apart, ITOffline1, | ||
| 5313 | &tid); | ||
| 5314 | if (code) | ||
| 5315 | success = 0; | ||
| 5316 | else { | ||
| 5317 | code = AFSVolDeleteVolume(aconn, tid); | ||
| 5318 | if (code) | ||
| 5319 | success = 0; | ||
| 5320 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 5321 | if (code || rcode) | ||
| 5322 | success = 0; | ||
| 5323 | } | ||
| 5324 | if (success) | ||
| 5325 | curPtr->volFlags |= CLONEZAPPED0x04; | ||
| 5326 | if (!success) | ||
| 5327 | fprintf(STDERR__stderrp, "Could not zap volume %lu\n", | ||
| 5328 | (unsigned long)curPtr->volCloneId); | ||
| 5329 | if (success) | ||
| 5330 | VPRINT2("Clone of %s %u deleted\n", curPtr->volName,{ if (verbose) { fprintf(__stdoutp, ("Clone of %s %u deleted\n" ), (curPtr->volName), (curPtr->volCloneId)); fflush(__stdoutp ); } } | ||
| 5331 | curPtr->volCloneId){ if (verbose) { fprintf(__stdoutp, ("Clone of %s %u deleted\n" ), (curPtr->volName), (curPtr->volCloneId)); fflush(__stdoutp ); } }; | ||
| 5332 | curPos++; | ||
| 5333 | tid = 0; | ||
| 5334 | } | ||
| 5335 | } | ||
| 5336 | if (aconn) | ||
| 5337 | rx_DestroyConnection(aconn); | ||
| 5338 | return 0; | ||
| 5339 | } | ||
| 5340 | |||
| 5341 | /*return a list of clones of the volumes specified by volPtrArray. Used by the | ||
| 5342 | backup system */ | ||
| 5343 | int | ||
| 5344 | UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart, | ||
| 5345 | struct volDescription *volPtr, afs_int32 arraySize) | ||
| 5346 | { | ||
| 5347 | struct rx_connection *aconn; | ||
| 5348 | struct volDescription *curPtr; | ||
| 5349 | int curPos; | ||
| 5350 | afs_int32 code = 0; | ||
| 5351 | afs_int32 rcode = 0; | ||
| 5352 | afs_int32 tid; | ||
| 5353 | int reuseCloneId = 0; | ||
| 5354 | afs_uint32 curCloneId = 0; | ||
| 5355 | char cloneName[256]; /*max vol name */ | ||
| 5356 | |||
| 5357 | aconn = (struct rx_connection *)0; | ||
| 5358 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 5359 | curPos = 0; | ||
| 5360 | if ((volPtr->volFlags & REUSECLONEID0x80) && (volPtr->volFlags & ENTRYVALID0x40)) | ||
| 5361 | reuseCloneId = 1; | ||
| 5362 | else { /*get a bunch of id's from vldb */ | ||
| 5363 | code = | ||
| 5364 | ubik_VL_GetNewVolumeId(cstruct, 0, arraySize, &curCloneId); | ||
| 5365 | if (code) { | ||
| 5366 | fprintf(STDERR__stderrp, "Could not get ID's for the clone from VLDB\n"); | ||
| 5367 | PrintError("", code); | ||
| 5368 | return code; | ||
| 5369 | } | ||
| 5370 | } | ||
| 5371 | |||
| 5372 | for (curPtr = volPtr; curPos < arraySize; curPtr++) { | ||
| 5373 | if (curPtr->volFlags & ENTRYVALID0x40) { | ||
| 5374 | |||
| 5375 | curPtr->volFlags |= CLONEVALID0x02; | ||
| 5376 | /*make a clone of curParentId and record as curPtr->volCloneId */ | ||
| 5377 | code = | ||
| 5378 | AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline1, | ||
| 5379 | &tid); | ||
| 5380 | if (code) | ||
| 5381 | VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,{ if (verbose) { fprintf(__stdoutp, ("Clone for volume %s %u failed \n" ), (curPtr->volName), (curPtr->volId)); fflush(__stdoutp ); } } | ||
| 5382 | curPtr->volId){ if (verbose) { fprintf(__stdoutp, ("Clone for volume %s %u failed \n" ), (curPtr->volName), (curPtr->volId)); fflush(__stdoutp ); } }; | ||
| 5383 | if (code) { | ||
| 5384 | curPtr->volFlags &= ~CLONEVALID0x02; /*cant clone */ | ||
| 5385 | curPos++; | ||
| 5386 | continue; | ||
| 5387 | } | ||
| 5388 | if (strlen(curPtr->volName) < (VOLSER_OLDMAXVOLNAME32 - 9)) { | ||
| 5389 | strcpy(cloneName, curPtr->volName); | ||
| 5390 | strcat(cloneName, "-tmpClone-"); | ||
| 5391 | } else | ||
| 5392 | strcpy(cloneName, "-tmpClone"); | ||
| 5393 | if (reuseCloneId) { | ||
| 5394 | curPtr->volCloneId = curCloneId; | ||
| 5395 | curCloneId++; | ||
| 5396 | } | ||
| 5397 | |||
| 5398 | code = | ||
| 5399 | AFSVolClone(aconn, tid, 0, readonlyVolume1, cloneName, | ||
| 5400 | &(curPtr->volCloneId)); | ||
| 5401 | if (code) { | ||
| 5402 | curPtr->volFlags &= ~CLONEVALID0x02; | ||
| 5403 | curPos++; | ||
| 5404 | fprintf(STDERR__stderrp, "Could not clone %s due to error %lu\n", | ||
| 5405 | curPtr->volName, (unsigned long)code); | ||
| 5406 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 5407 | if (code) | ||
| 5408 | fprintf(STDERR__stderrp, "WARNING: could not end transaction\n"); | ||
| 5409 | continue; | ||
| 5410 | } | ||
| 5411 | VPRINT2("********** Cloned %s temporary %u\n", cloneName,{ if (verbose) { fprintf(__stdoutp, ("********** Cloned %s temporary %u\n" ), (cloneName), (curPtr->volCloneId)); fflush(__stdoutp); } } | ||
| 5412 | curPtr->volCloneId){ if (verbose) { fprintf(__stdoutp, ("********** Cloned %s temporary %u\n" ), (cloneName), (curPtr->volCloneId)); fflush(__stdoutp); } }; | ||
| 5413 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 5414 | if (code || rcode) { | ||
| 5415 | curPtr->volFlags &= ~CLONEVALID0x02; | ||
| 5416 | curPos++; | ||
| 5417 | continue; | ||
| 5418 | } | ||
| 5419 | |||
| 5420 | curPos++; | ||
| 5421 | } | ||
| 5422 | } | ||
| 5423 | if (aconn) | ||
| 5424 | rx_DestroyConnection(aconn); | ||
| 5425 | return 0; | ||
| 5426 | } | ||
| 5427 | |||
| 5428 | |||
| 5429 | /*list all the volumes on <aserver> and <apart>. If all = 1, then all the | ||
| 5430 | * relevant fields of the volume are also returned. This is a heavy weight operation.*/ | ||
| 5431 | int | ||
| 5432 | UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all, | ||
| 5433 | struct volintInfo **resultPtr, afs_int32 * size) | ||
| 5434 | { | ||
| 5435 | struct rx_connection *aconn; | ||
| 5436 | afs_int32 code = 0; | ||
| 5437 | volEntries volumeInfo; | ||
| 5438 | |||
| 5439 | code = 0; | ||
| 5440 | *size = 0; | ||
| 5441 | *resultPtr = (volintInfo *) 0; | ||
| 5442 | volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */ | ||
| 5443 | volumeInfo.volEntries_len = 0; | ||
| 5444 | |||
| 5445 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 5446 | code = AFSVolListVolumes(aconn, apart, all, &volumeInfo); | ||
| 5447 | if (code) { | ||
| 5448 | fprintf(STDERR__stderrp, | ||
| 5449 | "Could not fetch the list of volumes from the server\n"); | ||
| 5450 | } else { | ||
| 5451 | *resultPtr = volumeInfo.volEntries_val; | ||
| 5452 | *size = volumeInfo.volEntries_len; | ||
| 5453 | } | ||
| 5454 | |||
| 5455 | if (aconn) | ||
| 5456 | rx_DestroyConnection(aconn); | ||
| 5457 | PrintError("", code); | ||
| 5458 | return code; | ||
| 5459 | } | ||
| 5460 | |||
| 5461 | /*------------------------------------------------------------------------ | ||
| 5462 | * EXPORTED UV_XListVolumes | ||
| 5463 | * | ||
| 5464 | * Description: | ||
| 5465 | * List the extended information for all the volumes on a particular | ||
| 5466 | * File Server and partition. We may either return the volume's ID | ||
| 5467 | * or all of its extended information. | ||
| 5468 | * | ||
| 5469 | * Arguments: | ||
| 5470 | * a_serverID : Address of the File Server for which we want | ||
| 5471 | * extended volume info. | ||
| 5472 | * a_partID : Partition for which we want the extended | ||
| 5473 | * volume info. | ||
| 5474 | * a_all : If non-zero, fetch ALL the volume info, | ||
| 5475 | * otherwise just the volume ID. | ||
| 5476 | * a_resultPP : Ptr to the address of the area containing | ||
| 5477 | * the returned volume info. | ||
| 5478 | * a_numEntsInResultP : Ptr for the value we set for the number of | ||
| 5479 | * entries returned. | ||
| 5480 | * | ||
| 5481 | * Returns: | ||
| 5482 | * 0 on success, | ||
| 5483 | * Otherise, the return value of AFSVolXListVolumes. | ||
| 5484 | * | ||
| 5485 | * Environment: | ||
| 5486 | * This routine is closely related to UV_ListVolumes, which returns | ||
| 5487 | * only the standard level of detail on AFS volumes. It is a | ||
| 5488 | * heavyweight operation, zipping through all the volume entries for | ||
| 5489 | * a given server/partition. | ||
| 5490 | * | ||
| 5491 | * Side Effects: | ||
| 5492 | * As advertised. | ||
| 5493 | *------------------------------------------------------------------------*/ | ||
| 5494 | |||
| 5495 | int | ||
| 5496 | UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all, | ||
| 5497 | struct volintXInfo **a_resultPP, | ||
| 5498 | afs_int32 * a_numEntsInResultP) | ||
| 5499 | { | ||
| 5500 | struct rx_connection *rxConnP; /*Ptr to the Rx connection involved */ | ||
| 5501 | afs_int32 code; /*Error code to return */ | ||
| 5502 | volXEntries volumeXInfo; /*Area for returned extended vol info */ | ||
| 5503 | |||
| 5504 | /* | ||
| 5505 | * Set up our error code and the area for returned extended volume info. | ||
| 5506 | * We set the val field to a null pointer as a hint for the stub to | ||
| 5507 | * allocate space. | ||
| 5508 | */ | ||
| 5509 | code = 0; | ||
| 5510 | *a_numEntsInResultP = 0; | ||
| 5511 | *a_resultPP = (volintXInfo *) 0; | ||
| 5512 | volumeXInfo.volXEntries_val = (volintXInfo *) 0; | ||
| 5513 | volumeXInfo.volXEntries_len = 0; | ||
| 5514 | |||
| 5515 | /* | ||
| 5516 | * Bind to the Volume Server port on the File Server machine in question, | ||
| 5517 | * then go for it. | ||
| 5518 | */ | ||
| 5519 | rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT7005); | ||
| 5520 | code = AFSVolXListVolumes(rxConnP, a_partID, a_all, &volumeXInfo); | ||
| 5521 | if (code) | ||
| 5522 | fprintf(STDERR__stderrp, "[UV_XListVolumes] Couldn't fetch volume list\n"); | ||
| 5523 | else { | ||
| 5524 | /* | ||
| 5525 | * We got the info; pull out the pointer to where the results lie | ||
| 5526 | * and how many entries are there. | ||
| 5527 | */ | ||
| 5528 | *a_resultPP = volumeXInfo.volXEntries_val; | ||
| 5529 | *a_numEntsInResultP = volumeXInfo.volXEntries_len; | ||
| 5530 | } | ||
| 5531 | |||
| 5532 | /* | ||
| 5533 | * If we got an Rx connection, throw it away. | ||
| 5534 | */ | ||
| 5535 | if (rxConnP) | ||
| 5536 | rx_DestroyConnection(rxConnP); | ||
| 5537 | |||
| 5538 | PrintError("", code); | ||
| 5539 | return (code); | ||
| 5540 | } /*UV_XListVolumes */ | ||
| 5541 | |||
| 5542 | /* get all the information about volume <volid> on <aserver> and <apart> */ | ||
| 5543 | int | ||
| 5544 | UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid, | ||
| 5545 | struct volintInfo **resultPtr) | ||
| 5546 | { | ||
| 5547 | struct rx_connection *aconn; | ||
| 5548 | afs_int32 code = 0; | ||
| 5549 | volEntries volumeInfo; | ||
| 5550 | |||
| 5551 | code = 0; | ||
| 5552 | |||
| 5553 | *resultPtr = (volintInfo *) 0; | ||
| 5554 | volumeInfo.volEntries_val = (volintInfo *) 0; /*this hints the stub to allocate space */ | ||
| 5555 | volumeInfo.volEntries_len = 0; | ||
| 5556 | |||
| 5557 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 5558 | code = AFSVolListOneVolume(aconn, apart, volid, &volumeInfo); | ||
| 5559 | if (code) { | ||
| 5560 | fprintf(STDERR__stderrp, | ||
| 5561 | "Could not fetch the information about volume %lu from the server\n", | ||
| 5562 | (unsigned long)volid); | ||
| 5563 | } else { | ||
| 5564 | *resultPtr = volumeInfo.volEntries_val; | ||
| 5565 | |||
| 5566 | } | ||
| 5567 | |||
| 5568 | if (aconn) | ||
| 5569 | rx_DestroyConnection(aconn); | ||
| 5570 | PrintError("", code); | ||
| 5571 | return code; | ||
| 5572 | } | ||
| 5573 | |||
| 5574 | /*------------------------------------------------------------------------ | ||
| 5575 | * EXPORTED UV_XListOneVolume | ||
| 5576 | * | ||
| 5577 | * Description: | ||
| 5578 | * List the extended information for a volume on a particular File | ||
| 5579 | * Server and partition. | ||
| 5580 | * | ||
| 5581 | * Arguments: | ||
| 5582 | * a_serverID : Address of the File Server for which we want | ||
| 5583 | * extended volume info. | ||
| 5584 | * a_partID : Partition for which we want the extended | ||
| 5585 | * volume info. | ||
| 5586 | * a_volID : Volume ID for which we want the info. | ||
| 5587 | * a_resultPP : Ptr to the address of the area containing | ||
| 5588 | * the returned volume info. | ||
| 5589 | * | ||
| 5590 | * Returns: | ||
| 5591 | * 0 on success, | ||
| 5592 | * Otherise, the return value of AFSVolXListOneVolume. | ||
| 5593 | * | ||
| 5594 | * Environment: | ||
| 5595 | * This routine is closely related to UV_ListOneVolume, which returns | ||
| 5596 | * only the standard level of detail on the chosen AFS volume. | ||
| 5597 | * | ||
| 5598 | * Side Effects: | ||
| 5599 | * As advertised. | ||
| 5600 | *------------------------------------------------------------------------*/ | ||
| 5601 | |||
| 5602 | int | ||
| 5603 | UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID, | ||
| 5604 | struct volintXInfo **a_resultPP) | ||
| 5605 | { | ||
| 5606 | struct rx_connection *rxConnP; /*Rx connection to Volume Server */ | ||
| 5607 | afs_int32 code; /*Error code */ | ||
| 5608 | volXEntries volumeXInfo; /*Area for returned info */ | ||
| 5609 | |||
| 5610 | /* | ||
| 5611 | * Set up our error code, and the area we're in which we are returning | ||
| 5612 | * the info. Setting the val field to a null pointer tells the stub | ||
| 5613 | * to allocate space for us. | ||
| 5614 | */ | ||
| 5615 | code = 0; | ||
| 5616 | *a_resultPP = (volintXInfo *) 0; | ||
| 5617 | volumeXInfo.volXEntries_val = (volintXInfo *) 0; | ||
| 5618 | volumeXInfo.volXEntries_len = 0; | ||
| 5619 | |||
| 5620 | /* | ||
| 5621 | * Bind to the Volume Server port on the File Server machine in question, | ||
| 5622 | * then go for it. | ||
| 5623 | */ | ||
| 5624 | rxConnP = UV_Bind(a_serverID, AFSCONF_VOLUMEPORT7005); | ||
| 5625 | code = AFSVolXListOneVolume(rxConnP, a_partID, a_volID, &volumeXInfo); | ||
| 5626 | if (code) | ||
| 5627 | fprintf(STDERR__stderrp, | ||
| 5628 | "[UV_XListOneVolume] Couldn't fetch the volume information\n"); | ||
| 5629 | else | ||
| 5630 | /* | ||
| 5631 | * We got the info; pull out the pointer to where the results lie. | ||
| 5632 | */ | ||
| 5633 | *a_resultPP = volumeXInfo.volXEntries_val; | ||
| 5634 | |||
| 5635 | /* | ||
| 5636 | * If we got an Rx connection, throw it away. | ||
| 5637 | */ | ||
| 5638 | if (rxConnP) | ||
| 5639 | rx_DestroyConnection(rxConnP); | ||
| 5640 | |||
| 5641 | PrintError("", code); | ||
| 5642 | return code; | ||
| 5643 | } | ||
| 5644 | |||
| 5645 | /* CheckVolume() | ||
| 5646 | * Given a volume we read from a partition, check if it is | ||
| 5647 | * represented in the VLDB correctly. | ||
| 5648 | * | ||
| 5649 | * The VLDB is looked up by the RW volume id (not its name). | ||
| 5650 | * The RW contains the true name of the volume (BK and RO set | ||
| 5651 | * the name in the VLDB only on creation of the VLDB entry). | ||
| 5652 | * We want rules strict enough that when we check all volumes | ||
| 5653 | * on one partition, it does not need to be done again. IE: | ||
| 5654 | * two volumes on different partitions won't constantly | ||
| 5655 | * change a VLDB entry away from what the other set. | ||
| 5656 | * For RW and BK volumes, we will always check the VLDB to see | ||
| 5657 | * if the two exist on the server/partition. May seem redundant, | ||
| 5658 | * but this is an easy check of the VLDB. IE: if the VLDB entry | ||
| 5659 | * says the BK exists but no BK volume is there, we will detect | ||
| 5660 | * this when we check the RW volume. | ||
| 5661 | * VLDB entries are locked only when a change needs to be done. | ||
| 5662 | * Output changed to look a lot like the "vos syncserv" otuput. | ||
| 5663 | */ | ||
| 5664 | static afs_int32 | ||
| 5665 | CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart, | ||
| 5666 | afs_int32 * modentry, afs_uint32 * maxvolid, | ||
| 5667 | struct nvldbentry *aentry) | ||
| 5668 | { | ||
| 5669 | int idx = 0; | ||
| 5670 | int j; | ||
| 5671 | afs_int32 code, error = 0; | ||
| 5672 | struct nvldbentry entry, storeEntry; | ||
| 5673 | char pname[10]; | ||
| 5674 | int pass = 0, createentry, addvolume, modified, mod, doit = 1; | ||
| 5675 | afs_uint32 rwvolid; | ||
| 5676 | char hoststr[16]; | ||
| 5677 | |||
| 5678 | if (modentry) { | ||
| 5679 | if (*modentry == 1) | ||
| 5680 | doit = 0; | ||
| 5681 | *modentry = 0; | ||
| 5682 | } | ||
| 5683 | rwvolid = | ||
| 5684 | ((volumeinfo->type == | ||
| 5685 | RWVOL0) ? volumeinfo->volid : volumeinfo->parentID); | ||
| 5686 | |||
| 5687 | retry: | ||
| 5688 | /* Check to see if the VLDB is ok without locking it (pass 1). | ||
| 5689 | * If it will change, then lock the VLDB entry, read it again, | ||
| 5690 | * then make the changes to it (pass 2). | ||
| 5691 | */ | ||
| 5692 | if (++pass == 2) { | ||
| 5693 | code = ubik_VL_SetLock(cstruct, 0, rwvolid, RWVOL0, VLOP_DELETE0x80); | ||
| 5694 | if (code) { | ||
| 5695 | fprintf(STDERR__stderrp, "Could not lock VLDB entry for %lu\n", | ||
| 5696 | (unsigned long)rwvolid); | ||
| 5697 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 5698 | } | ||
| 5699 | } | ||
| 5700 | |||
| 5701 | createentry = 0; /* Do we need to create a VLDB entry */ | ||
| 5702 | addvolume = 0; /* Add this volume to the VLDB entry */ | ||
| 5703 | modified = 0; /* The VLDB entry was modified */ | ||
| 5704 | |||
| 5705 | if (aentry) { | ||
| 5706 | memcpy(&entry, aentry, sizeof(entry)); | ||
| 5707 | } else { | ||
| 5708 | /* Read the entry from VLDB by its RW volume id */ | ||
| 5709 | code = VLDB_GetEntryByID(rwvolid, RWVOL0, &entry); | ||
| 5710 | if (code) { | ||
| 5711 | if (code != VL_NOENT(363524L)) { | ||
| 5712 | fprintf(STDOUT__stdoutp, | ||
| 5713 | "Could not retreive the VLDB entry for volume %lu \n", | ||
| 5714 | (unsigned long)rwvolid); | ||
| 5715 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 5716 | } | ||
| 5717 | |||
| 5718 | memset(&entry, 0, sizeof(entry)); | ||
| 5719 | vsu_ExtractName(entry.name, volumeinfo->name); /* Store name of RW */ | ||
| 5720 | |||
| 5721 | createentry = 1; | ||
| 5722 | } else { | ||
| 5723 | MapHostToNetwork(&entry); | ||
| 5724 | } | ||
| 5725 | } | ||
| 5726 | |||
| 5727 | if (verbose && (pass == 1)) { | ||
| 5728 | fprintf(STDOUT__stdoutp, "_______________________________\n"); | ||
| 5729 | fprintf(STDOUT__stdoutp, "\n-- status before -- \n"); | ||
| 5730 | if (createentry) { | ||
| 5731 | fprintf(STDOUT__stdoutp, "\n**does not exist**\n"); | ||
| 5732 | } else { | ||
| 5733 | if ((entry.flags & RW_EXISTS0x1000) || (entry.flags & RO_EXISTS0x2000) | ||
| 5734 | || (entry.flags & BACK_EXISTS0x4000)) | ||
| 5735 | EnumerateEntry(&entry); | ||
| 5736 | } | ||
| 5737 | fprintf(STDOUT__stdoutp, "\n"); | ||
| 5738 | } | ||
| 5739 | |||
| 5740 | if (volumeinfo->type == RWVOL0) { /* RW volume exists */ | ||
| 5741 | if (createentry) { | ||
| 5742 | idx = 0; | ||
| 5743 | entry.nServers = 1; | ||
| 5744 | addvolume++; | ||
| 5745 | } else { | ||
| 5746 | /* Check existence of RW and BK volumes */ | ||
| 5747 | code = CheckVldbRWBK(&entry, &mod); | ||
| 5748 | if (code) | ||
| 5749 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 5750 | if (mod) | ||
| 5751 | modified++; | ||
| 5752 | |||
| 5753 | idx = Lp_GetRwIndex(&entry); | ||
| 5754 | if (idx == -1) { /* RW index not found in the VLDB entry */ | ||
| 5755 | idx = entry.nServers; /* put it into next index */ | ||
| 5756 | entry.nServers++; | ||
| 5757 | addvolume++; | ||
| 5758 | } else { /* RW index found in the VLDB entry. */ | ||
| 5759 | /* Verify if this volume's location matches where the VLDB says it is */ | ||
| 5760 | if (!Lp_Match(aserver, apart, &entry)) { | ||
| 5761 | if (entry.flags & RW_EXISTS0x1000) { | ||
| 5762 | /* The RW volume exists elsewhere - report this one a duplicate */ | ||
| 5763 | if (pass == 1) { | ||
| 5764 | MapPartIdIntoName(apart, pname); | ||
| 5765 | fprintf(STDERR__stderrp, | ||
| 5766 | "*** Warning: Orphaned RW volume %lu exists on %s %s\n", | ||
| 5767 | (unsigned long)rwvolid, | ||
| 5768 | noresolve ? | ||
| 5769 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 5770 | hostutil_GetNameByINet(aserver), pname); | ||
| 5771 | MapPartIdIntoName(entry.serverPartition[idx], | ||
| 5772 | pname); | ||
| 5773 | fprintf(STDERR__stderrp, | ||
| 5774 | " VLDB reports RW volume %lu exists on %s %s\n", | ||
| 5775 | (unsigned long)rwvolid, | ||
| 5776 | noresolve ? | ||
| 5777 | afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) : | ||
| 5778 | hostutil_GetNameByINet(entry. | ||
| 5779 | serverNumber[idx]), | ||
| 5780 | pname); | ||
| 5781 | } | ||
| 5782 | } else { | ||
| 5783 | /* The RW volume does not exist - have VLDB point to this one */ | ||
| 5784 | addvolume++; | ||
| 5785 | |||
| 5786 | /* Check for orphaned BK volume on old partition */ | ||
| 5787 | if (entry.flags & BACK_EXISTS0x4000) { | ||
| 5788 | if (pass == 1) { | ||
| 5789 | MapPartIdIntoName(entry.serverPartition[idx], | ||
| 5790 | pname); | ||
| 5791 | fprintf(STDERR__stderrp, | ||
| 5792 | "*** Warning: Orphaned BK volume %u exists on %s %s\n", | ||
| 5793 | entry.volumeId[BACKVOL2], | ||
| 5794 | noresolve ? | ||
| 5795 | afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) : | ||
| 5796 | hostutil_GetNameByINet(entry. | ||
| 5797 | serverNumber | ||
| 5798 | [idx]), pname); | ||
| 5799 | MapPartIdIntoName(apart, pname); | ||
| 5800 | fprintf(STDERR__stderrp, | ||
| 5801 | " VLDB reports its RW volume %lu exists on %s %s\n", | ||
| 5802 | (unsigned long)rwvolid, | ||
| 5803 | noresolve ? | ||
| 5804 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 5805 | hostutil_GetNameByINet(aserver), | ||
| 5806 | pname); | ||
| 5807 | } | ||
| 5808 | } | ||
| 5809 | } | ||
| 5810 | } else { | ||
| 5811 | /* Volume location matches the VLDB location */ | ||
| 5812 | if ((volumeinfo->backupID && !entry.volumeId[BACKVOL2]) | ||
| 5813 | || (volumeinfo->cloneID && !entry.volumeId[ROVOL1]) | ||
| 5814 | || | ||
| 5815 | (strncmp | ||
| 5816 | (entry.name, volumeinfo->name, | ||
| 5817 | VOLSER_OLDMAXVOLNAME32) != 0)) { | ||
| 5818 | addvolume++; | ||
| 5819 | } | ||
| 5820 | } | ||
| 5821 | } | ||
| 5822 | } | ||
| 5823 | |||
| 5824 | if (addvolume) { | ||
| 5825 | entry.flags |= RW_EXISTS0x1000; | ||
| 5826 | entry.volumeId[RWVOL0] = rwvolid; | ||
| 5827 | if (!entry.volumeId[BACKVOL2]) | ||
| 5828 | entry.volumeId[BACKVOL2] = volumeinfo->backupID; | ||
| 5829 | if (!entry.volumeId[ROVOL1]) | ||
| 5830 | entry.volumeId[ROVOL1] = volumeinfo->cloneID; | ||
| 5831 | |||
| 5832 | entry.serverFlags[idx] = ITSRWVOL0x04; | ||
| 5833 | entry.serverNumber[idx] = aserver; | ||
| 5834 | entry.serverPartition[idx] = apart; | ||
| 5835 | strncpy(entry.name, volumeinfo->name, VOLSER_OLDMAXVOLNAME32); | ||
| 5836 | |||
| 5837 | modified++; | ||
| 5838 | |||
| 5839 | /* One last check - to update BK if need to */ | ||
| 5840 | code = CheckVldbRWBK(&entry, &mod); | ||
| 5841 | if (code) | ||
| 5842 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 5843 | if (mod) | ||
| 5844 | modified++; | ||
| 5845 | } | ||
| 5846 | } | ||
| 5847 | |||
| 5848 | else if (volumeinfo->type == BACKVOL2) { /* A BK volume */ | ||
| 5849 | if (createentry) { | ||
| 5850 | idx = 0; | ||
| 5851 | entry.nServers = 1; | ||
| 5852 | addvolume++; | ||
| 5853 | } else { | ||
| 5854 | /* Check existence of RW and BK volumes */ | ||
| 5855 | code = CheckVldbRWBK(&entry, &mod); | ||
| 5856 | if (code) | ||
| 5857 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 5858 | if (mod) | ||
| 5859 | modified++; | ||
| 5860 | |||
| 5861 | idx = Lp_GetRwIndex(&entry); | ||
| 5862 | if (idx == -1) { /* RW index not found in the VLDB entry */ | ||
| 5863 | idx = entry.nServers; /* Put it into next index */ | ||
| 5864 | entry.nServers++; | ||
| 5865 | addvolume++; | ||
| 5866 | } else { /* RW index found in the VLDB entry */ | ||
| 5867 | /* Verify if this volume's location matches where the VLDB says it is */ | ||
| 5868 | if (!Lp_Match(aserver, apart, &entry)) { | ||
| 5869 | /* VLDB says RW and/or BK is elsewhere - report this BK volume orphaned */ | ||
| 5870 | if (pass == 1) { | ||
| 5871 | MapPartIdIntoName(apart, pname); | ||
| 5872 | fprintf(STDERR__stderrp, | ||
| 5873 | "*** Warning: Orphaned BK volume %lu exists on %s %s\n", | ||
| 5874 | (unsigned long)volumeinfo->volid, | ||
| 5875 | noresolve ? | ||
| 5876 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 5877 | hostutil_GetNameByINet(aserver), pname); | ||
| 5878 | MapPartIdIntoName(entry.serverPartition[idx], pname); | ||
| 5879 | fprintf(STDERR__stderrp, | ||
| 5880 | " VLDB reports its RW/BK volume %lu exists on %s %s\n", | ||
| 5881 | (unsigned long)rwvolid, | ||
| 5882 | noresolve ? | ||
| 5883 | afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) : | ||
| 5884 | hostutil_GetNameByINet(entry. | ||
| 5885 | serverNumber[idx]), | ||
| 5886 | pname); | ||
| 5887 | } | ||
| 5888 | } else { | ||
| 5889 | if (volumeinfo->volid != entry.volumeId[BACKVOL2]) { | ||
| 5890 | if (!(entry.flags & BACK_EXISTS0x4000)) { | ||
| 5891 | addvolume++; | ||
| 5892 | } else if (volumeinfo->volid > | ||
| 5893 | entry.volumeId[BACKVOL2]) { | ||
| 5894 | addvolume++; | ||
| 5895 | |||
| 5896 | if (pass == 1) { | ||
| 5897 | MapPartIdIntoName(entry.serverPartition[idx], | ||
| 5898 | pname); | ||
| 5899 | fprintf(STDERR__stderrp, | ||
| 5900 | "*** Warning: Orphaned BK volume %u exists on %s %s\n", | ||
| 5901 | entry.volumeId[BACKVOL2], | ||
| 5902 | noresolve ? | ||
| 5903 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 5904 | hostutil_GetNameByINet(aserver), | ||
| 5905 | pname); | ||
| 5906 | fprintf(STDERR__stderrp, | ||
| 5907 | " VLDB reports its BK volume ID is %lu\n", | ||
| 5908 | (unsigned long)volumeinfo->volid); | ||
| 5909 | } | ||
| 5910 | } else { | ||
| 5911 | if (pass == 1) { | ||
| 5912 | MapPartIdIntoName(entry.serverPartition[idx], | ||
| 5913 | pname); | ||
| 5914 | fprintf(STDERR__stderrp, | ||
| 5915 | "*** Warning: Orphaned BK volume %lu exists on %s %s\n", | ||
| 5916 | (unsigned long)volumeinfo->volid, | ||
| 5917 | noresolve ? | ||
| 5918 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 5919 | hostutil_GetNameByINet(aserver), | ||
| 5920 | pname); | ||
| 5921 | fprintf(STDERR__stderrp, | ||
| 5922 | " VLDB reports its BK volume ID is %u\n", | ||
| 5923 | entry.volumeId[BACKVOL2]); | ||
| 5924 | } | ||
| 5925 | } | ||
| 5926 | } else if (!entry.volumeId[BACKVOL2]) { | ||
| 5927 | addvolume++; | ||
| 5928 | } | ||
| 5929 | } | ||
| 5930 | } | ||
| 5931 | } | ||
| 5932 | if (addvolume) { | ||
| 5933 | entry.flags |= BACK_EXISTS0x4000; | ||
| 5934 | entry.volumeId[RWVOL0] = rwvolid; | ||
| 5935 | entry.volumeId[BACKVOL2] = volumeinfo->volid; | ||
| 5936 | |||
| 5937 | entry.serverNumber[idx] = aserver; | ||
| 5938 | entry.serverPartition[idx] = apart; | ||
| 5939 | entry.serverFlags[idx] = ITSBACKVOL0x08; | ||
| 5940 | |||
| 5941 | modified++; | ||
| 5942 | } | ||
| 5943 | } | ||
| 5944 | |||
| 5945 | else if (volumeinfo->type == ROVOL1) { /* A RO volume */ | ||
| 5946 | if (volumeinfo->volid == entry.volumeId[ROVOL1]) { | ||
| 5947 | /* This is a quick check to see if the RO entry exists in the | ||
| 5948 | * VLDB so we avoid the CheckVldbRO() call (which checks if each | ||
| 5949 | * RO volume listed in the VLDB exists). | ||
| 5950 | */ | ||
| 5951 | idx = Lp_ROMatch(aserver, apart, &entry) - 1; | ||
| 5952 | if (idx == -1) { | ||
| 5953 | idx = entry.nServers; | ||
| 5954 | entry.nServers++; | ||
| 5955 | addvolume++; | ||
| 5956 | } else { | ||
| 5957 | if (!(entry.flags & RO_EXISTS0x2000)) { | ||
| 5958 | addvolume++; | ||
| 5959 | } | ||
| 5960 | } | ||
| 5961 | } else { | ||
| 5962 | /* Before we correct the VLDB entry, make sure all the | ||
| 5963 | * ROs listed in the VLDB exist. | ||
| 5964 | */ | ||
| 5965 | code = CheckVldbRO(&entry, &mod); | ||
| 5966 | if (code) | ||
| 5967 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 5968 | if (mod) | ||
| 5969 | modified++; | ||
| 5970 | |||
| 5971 | if (!(entry.flags & RO_EXISTS0x2000)) { | ||
| 5972 | /* No RO exists in the VLDB entry - add this one */ | ||
| 5973 | idx = entry.nServers; | ||
| 5974 | entry.nServers++; | ||
| 5975 | addvolume++; | ||
| 5976 | } else if (volumeinfo->volid > entry.volumeId[ROVOL1]) { | ||
| 5977 | /* The volume headers's RO ID does not match that in the VLDB entry, | ||
| 5978 | * and the vol hdr's ID is greater (implies more recent). So delete | ||
| 5979 | * all the RO volumes listed in VLDB entry and add this volume. | ||
| 5980 | */ | ||
| 5981 | for (j = 0; j < entry.nServers; j++) { | ||
| 5982 | if (entry.serverFlags[j] & ITSROVOL0x02) { | ||
| 5983 | /* Verify this volume exists and print message we are orphaning it */ | ||
| 5984 | if (pass == 1) { | ||
| 5985 | MapPartIdIntoName(apart, pname); | ||
| 5986 | fprintf(STDERR__stderrp, | ||
| 5987 | "*** Warning: Orphaned RO volume %u exists on %s %s\n", | ||
| 5988 | entry.volumeId[ROVOL1], | ||
| 5989 | noresolve ? | ||
| 5990 | afs_inet_ntoa_r(entry.serverNumber[j], hoststr) : | ||
| 5991 | hostutil_GetNameByINet(entry. | ||
| 5992 | serverNumber[j]), | ||
| 5993 | pname); | ||
| 5994 | fprintf(STDERR__stderrp, | ||
| 5995 | " VLDB reports its RO volume ID is %lu\n", | ||
| 5996 | (unsigned long)volumeinfo->volid); | ||
| 5997 | } | ||
| 5998 | |||
| 5999 | Lp_SetRWValue(&entry, entry.serverNumber[idx], | ||
| 6000 | entry.serverPartition[idx], 0L, 0L); | ||
| 6001 | entry.nServers--; | ||
| 6002 | modified++; | ||
| 6003 | j--; | ||
| 6004 | } | ||
| 6005 | } | ||
| 6006 | |||
| 6007 | idx = entry.nServers; | ||
| 6008 | entry.nServers++; | ||
| 6009 | addvolume++; | ||
| 6010 | } else if (volumeinfo->volid < entry.volumeId[ROVOL1]) { | ||
| 6011 | /* The volume headers's RO ID does not match that in the VLDB entry, | ||
| 6012 | * and the vol hdr's ID is lower (implies its older). So orphan it. | ||
| 6013 | */ | ||
| 6014 | if (pass == 1) { | ||
| 6015 | MapPartIdIntoName(apart, pname); | ||
| 6016 | fprintf(STDERR__stderrp, | ||
| 6017 | "*** Warning: Orphaned RO volume %lu exists on %s %s\n", | ||
| 6018 | (unsigned long)volumeinfo->volid, | ||
| 6019 | noresolve ? | ||
| 6020 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 6021 | hostutil_GetNameByINet(aserver), pname); | ||
| 6022 | fprintf(STDERR__stderrp, | ||
| 6023 | " VLDB reports its RO volume ID is %u\n", | ||
| 6024 | entry.volumeId[ROVOL1]); | ||
| 6025 | } | ||
| 6026 | } else { | ||
| 6027 | /* The RO volume ID in the volume header match that in the VLDB entry, | ||
| 6028 | * and there exist RO volumes in the VLDB entry. See if any of them | ||
| 6029 | * are this one. If not, then we add it. | ||
| 6030 | */ | ||
| 6031 | idx = Lp_ROMatch(aserver, apart, &entry) - 1; | ||
| 6032 | if (idx == -1) { | ||
| 6033 | idx = entry.nServers; | ||
| 6034 | entry.nServers++; | ||
| 6035 | addvolume++; | ||
| 6036 | } | ||
| 6037 | } | ||
| 6038 | } | ||
| 6039 | |||
| 6040 | if (addvolume) { | ||
| 6041 | entry.flags |= RO_EXISTS0x2000; | ||
| 6042 | entry.volumeId[RWVOL0] = rwvolid; | ||
| 6043 | entry.volumeId[ROVOL1] = volumeinfo->volid; | ||
| 6044 | |||
| 6045 | entry.serverNumber[idx] = aserver; | ||
| 6046 | entry.serverPartition[idx] = apart; | ||
| 6047 | entry.serverFlags[idx] = ITSROVOL0x02; | ||
| 6048 | |||
| 6049 | modified++; | ||
| 6050 | } | ||
| 6051 | } | ||
| 6052 | |||
| 6053 | /* Remember largest volume id */ | ||
| 6054 | if (entry.volumeId[ROVOL1] > *maxvolid) | ||
| 6055 | *maxvolid = entry.volumeId[ROVOL1]; | ||
| 6056 | if (entry.volumeId[BACKVOL2] > *maxvolid) | ||
| 6057 | *maxvolid = entry.volumeId[BACKVOL2]; | ||
| 6058 | if (entry.volumeId[RWVOL0] > *maxvolid) | ||
| 6059 | *maxvolid = entry.volumeId[RWVOL0]; | ||
| 6060 | |||
| 6061 | if (modified && doit) { | ||
| 6062 | MapNetworkToHost(&entry, &storeEntry); | ||
| 6063 | |||
| 6064 | if (createentry) { | ||
| 6065 | code = VLDB_CreateEntry(&storeEntry); | ||
| 6066 | if (code) { | ||
| 6067 | fprintf(STDOUT__stdoutp, | ||
| 6068 | "Could not create a VLDB entry for the volume %lu\n", | ||
| 6069 | (unsigned long)rwvolid); | ||
| 6070 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6071 | } | ||
| 6072 | } else { | ||
| 6073 | if (pass == 1) | ||
| 6074 | goto retry; | ||
| 6075 | code = | ||
| 6076 | VLDB_ReplaceEntry(rwvolid, RWVOL0, &storeEntry, | ||
| 6077 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 6078 | LOCKREL_TIMESTAMP1); | ||
| 6079 | if (code) { | ||
| 6080 | fprintf(STDERR__stderrp, "Could not update entry for %lu\n", | ||
| 6081 | (unsigned long)rwvolid); | ||
| 6082 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6083 | } | ||
| 6084 | } | ||
| 6085 | } else if (pass == 2) { | ||
| 6086 | code = | ||
| 6087 | ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL0, | ||
| 6088 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 6089 | if (code) { | ||
| 6090 | PrintError("Could not unlock VLDB entry ", code); | ||
| 6091 | } | ||
| 6092 | } | ||
| 6093 | |||
| 6094 | if (modified && modentry) { | ||
| 6095 | *modentry = 1; | ||
| 6096 | } | ||
| 6097 | |||
| 6098 | if (aentry) { | ||
| 6099 | memcpy(aentry, &entry, sizeof(entry)); | ||
| 6100 | } | ||
| 6101 | |||
| 6102 | if (verbose) { | ||
| 6103 | fprintf(STDOUT__stdoutp, "-- status after --\n"); | ||
| 6104 | if (modified) | ||
| 6105 | EnumerateEntry(&entry); | ||
| 6106 | else | ||
| 6107 | fprintf(STDOUT__stdoutp, "\n**no change**\n"); | ||
| 6108 | } | ||
| 6109 | |||
| 6110 | error_exit: | ||
| 6111 | VPRINT("\n_______________________________\n"){ if (verbose) { fprintf(__stdoutp, ("\n_______________________________\n" )); fflush(__stdoutp); } }; | ||
| 6112 | return (error); | ||
| 6113 | } | ||
| 6114 | |||
| 6115 | static int | ||
| 6116 | sortVolumes(const void *a, const void *b) | ||
| 6117 | { | ||
| 6118 | volintInfo *v1 = (volintInfo *) a; | ||
| 6119 | volintInfo *v2 = (volintInfo *) b; | ||
| 6120 | afs_uint32 rwvolid1, rwvolid2; | ||
| 6121 | |||
| 6122 | rwvolid1 = ((v1->type == RWVOL0) ? v1->volid : v1->parentID); | ||
| 6123 | rwvolid2 = ((v2->type == RWVOL0) ? v2->volid : v2->parentID); | ||
| 6124 | |||
| 6125 | if (rwvolid1 > rwvolid2) | ||
| 6126 | return -1; /* lower RW id goes first */ | ||
| 6127 | if (rwvolid1 < rwvolid2) | ||
| 6128 | return 1; | ||
| 6129 | |||
| 6130 | if (v1->type == RWVOL0) | ||
| 6131 | return -1; /* RW vols go first */ | ||
| 6132 | if (v2->type == RWVOL0) | ||
| 6133 | return 1; | ||
| 6134 | |||
| 6135 | if ((v1->type == BACKVOL2) && (v2->type == ROVOL1)) | ||
| 6136 | return -1; /* BK vols next */ | ||
| 6137 | if ((v1->type == ROVOL1) && (v2->type == BACKVOL2)) | ||
| 6138 | return 1; | ||
| 6139 | |||
| 6140 | if (v1->volid < v2->volid) | ||
| 6141 | return 1; /* larger volids first */ | ||
| 6142 | if (v1->volid > v2->volid) | ||
| 6143 | return -1; | ||
| 6144 | return 0; | ||
| 6145 | } | ||
| 6146 | |||
| 6147 | /* UV_SyncVolume() | ||
| 6148 | * Synchronise <aserver> <apart>(if flags = 1) <avolid>. | ||
| 6149 | * Synchronize an individual volume against a sever and partition. | ||
| 6150 | * Checks the VLDB entry (similar to syncserv) as well as checks | ||
| 6151 | * if the volume exists on specified servers (similar to syncvldb). | ||
| 6152 | */ | ||
| 6153 | int | ||
| 6154 | UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags) | ||
| 6155 | { | ||
| 6156 | struct rx_connection *aconn = 0; | ||
| 6157 | afs_int32 j, k, code, vcode, error = 0; | ||
| 6158 | afs_int32 tverbose; | ||
| 6159 | afs_int32 mod, modified = 0, deleted = 0; | ||
| 6160 | struct nvldbentry vldbentry; | ||
| 6161 | afs_uint32 volumeid = 0; | ||
| 6162 | volEntries volumeInfo; | ||
| 6163 | struct partList PartList; | ||
| 6164 | afs_int32 pcnt; | ||
| 6165 | afs_uint32 maxvolid = 0; | ||
| 6166 | |||
| 6167 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6168 | volumeInfo.volEntries_len = 0; | ||
| 6169 | |||
| 6170 | /* Turn verbose logging off and do our own verbose logging */ | ||
| 6171 | /* tverbose must be set before we call ERROR_EXIT() */ | ||
| 6172 | |||
| 6173 | tverbose = verbose; | ||
| 6174 | if (flags & 2) | ||
| 6175 | tverbose = 1; | ||
| 6176 | verbose = 0; | ||
| 6177 | |||
| 6178 | if (!aserver && (flags & 1)) { | ||
| 6179 | /* fprintf(STDERR,"Partition option requires a server option\n"); */ | ||
| 6180 | ERROR_EXIT(EINVAL)do { error = (22); goto error_exit; } while (0); | ||
| 6181 | } | ||
| 6182 | |||
| 6183 | /* Read the VLDB entry */ | ||
| 6184 | vcode = VLDB_GetEntryByName(avolname, &vldbentry); | ||
| 6185 | if (vcode && (vcode != VL_NOENT(363524L))) { | ||
| 6186 | fprintf(STDERR__stderrp, "Could not access the VLDB for volume %s\n", | ||
| 6187 | avolname); | ||
| 6188 | ERROR_EXIT(vcode)do { error = (vcode); goto error_exit; } while (0); | ||
| 6189 | } else if (!vcode) { | ||
| 6190 | MapHostToNetwork(&vldbentry); | ||
| 6191 | } | ||
| 6192 | |||
| 6193 | if (tverbose) { | ||
| 6194 | fprintf(STDOUT__stdoutp, "Processing VLDB entry %s ...\n", avolname); | ||
| 6195 | fprintf(STDOUT__stdoutp, "_______________________________\n"); | ||
| 6196 | fprintf(STDOUT__stdoutp, "\n-- status before -- \n"); | ||
| 6197 | if (vcode) { | ||
| 6198 | fprintf(STDOUT__stdoutp, "\n**does not exist**\n"); | ||
| 6199 | } else { | ||
| 6200 | if ((vldbentry.flags & RW_EXISTS0x1000) || (vldbentry.flags & RO_EXISTS0x2000) | ||
| 6201 | || (vldbentry.flags & BACK_EXISTS0x4000)) | ||
| 6202 | EnumerateEntry(&vldbentry); | ||
| 6203 | } | ||
| 6204 | fprintf(STDOUT__stdoutp, "\n"); | ||
| 6205 | } | ||
| 6206 | |||
| 6207 | /* Verify that all of the VLDB entries exist on the repective servers | ||
| 6208 | * and partitions (this does not require that avolname be a volume ID). | ||
| 6209 | * Equivalent to a syncserv. | ||
| 6210 | */ | ||
| 6211 | if (!vcode) { | ||
| 6212 | /* Tell CheckVldb not to update if appropriate */ | ||
| 6213 | if (flags & 2) | ||
| 6214 | mod = 1; | ||
| 6215 | else | ||
| 6216 | mod = 0; | ||
| 6217 | code = CheckVldb(&vldbentry, &mod, &deleted); | ||
| 6218 | if (code) { | ||
| 6219 | fprintf(STDERR__stderrp, "Could not process VLDB entry for volume %s\n", | ||
| 6220 | vldbentry.name); | ||
| 6221 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6222 | } | ||
| 6223 | if (mod) | ||
| 6224 | modified++; | ||
| 6225 | } | ||
| 6226 | |||
| 6227 | /* If aserver is given, we will search for the desired volume on it */ | ||
| 6228 | if (aserver) { | ||
| 6229 | /* Generate array of partitions on the server that we will check */ | ||
| 6230 | if (!(flags & 1)) { | ||
| 6231 | code = UV_ListPartitions(aserver, &PartList, &pcnt); | ||
| 6232 | if (code) { | ||
| 6233 | fprintf(STDERR__stderrp, | ||
| 6234 | "Could not fetch the list of partitions from the server\n"); | ||
| 6235 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6236 | } | ||
| 6237 | } else { | ||
| 6238 | PartList.partId[0] = apart; | ||
| 6239 | pcnt = 1; | ||
| 6240 | } | ||
| 6241 | |||
| 6242 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 6243 | |||
| 6244 | /* If a volume ID were given, search for it on each partition */ | ||
| 6245 | if ((volumeid = atol(avolname))) { | ||
| 6246 | for (j = 0; j < pcnt; j++) { | ||
| 6247 | code = | ||
| 6248 | AFSVolListOneVolume(aconn, PartList.partId[j], volumeid, | ||
| 6249 | &volumeInfo); | ||
| 6250 | if (code) { | ||
| 6251 | if (code != ENODEV19) { | ||
| 6252 | fprintf(STDERR__stderrp, "Could not query server\n"); | ||
| 6253 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6254 | } | ||
| 6255 | } else { | ||
| 6256 | if (flags & 2) | ||
| 6257 | mod = 1; | ||
| 6258 | else | ||
| 6259 | mod = 0; | ||
| 6260 | /* Found one, sync it with VLDB entry */ | ||
| 6261 | code = | ||
| 6262 | CheckVolume(volumeInfo.volEntries_val, aserver, | ||
| 6263 | PartList.partId[j], &mod, &maxvolid, &vldbentry); | ||
| 6264 | if (code) | ||
| 6265 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6266 | if (mod) | ||
| 6267 | modified++; | ||
| 6268 | } | ||
| 6269 | |||
| 6270 | if (volumeInfo.volEntries_val) | ||
| 6271 | free(volumeInfo.volEntries_val); | ||
| 6272 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6273 | volumeInfo.volEntries_len = 0; | ||
| 6274 | } | ||
| 6275 | } | ||
| 6276 | |||
| 6277 | /* Check to see if the RW, BK, and RO IDs exist on any | ||
| 6278 | * partitions. We get the volume IDs from the VLDB. | ||
| 6279 | */ | ||
| 6280 | for (j = 0; j < MAXTYPES3; j++) { /* for RW, RO, and BK IDs */ | ||
| 6281 | if (vldbentry.volumeId[j] == 0) | ||
| 6282 | continue; | ||
| 6283 | |||
| 6284 | for (k = 0; k < pcnt; k++) { /* For each partition */ | ||
| 6285 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6286 | volumeInfo.volEntries_len = 0; | ||
| 6287 | code = | ||
| 6288 | AFSVolListOneVolume(aconn, PartList.partId[k], | ||
| 6289 | vldbentry.volumeId[j], &volumeInfo); | ||
| 6290 | if (code) { | ||
| 6291 | if (code != ENODEV19) { | ||
| 6292 | fprintf(STDERR__stderrp, "Could not query server\n"); | ||
| 6293 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6294 | } | ||
| 6295 | } else { | ||
| 6296 | if (flags & 2) | ||
| 6297 | mod = 1; | ||
| 6298 | else | ||
| 6299 | mod = 0; | ||
| 6300 | /* Found one, sync it with VLDB entry */ | ||
| 6301 | code = | ||
| 6302 | CheckVolume(volumeInfo.volEntries_val, aserver, | ||
| 6303 | PartList.partId[k], &mod, &maxvolid, &vldbentry); | ||
| 6304 | if (code) | ||
| 6305 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6306 | if (mod) | ||
| 6307 | modified++; | ||
| 6308 | } | ||
| 6309 | |||
| 6310 | if (volumeInfo.volEntries_val) | ||
| 6311 | free(volumeInfo.volEntries_val); | ||
| 6312 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6313 | volumeInfo.volEntries_len = 0; | ||
| 6314 | } | ||
| 6315 | } | ||
| 6316 | } | ||
| 6317 | |||
| 6318 | /* if (aserver) */ | ||
| 6319 | /* If verbose output, print a summary of what changed */ | ||
| 6320 | if (tverbose) { | ||
| 6321 | fprintf(STDOUT__stdoutp, "-- status after --\n"); | ||
| 6322 | if (deleted) { | ||
| 6323 | fprintf(STDOUT__stdoutp, "\n**entry deleted**\n"); | ||
| 6324 | } else if (modified) { | ||
| 6325 | EnumerateEntry(&vldbentry); | ||
| 6326 | } else { | ||
| 6327 | fprintf(STDOUT__stdoutp, "\n**no change**\n"); | ||
| 6328 | } | ||
| 6329 | fprintf(STDOUT__stdoutp, "\n_______________________________\n"); | ||
| 6330 | } | ||
| 6331 | |||
| 6332 | error_exit: | ||
| 6333 | /* Now check if the maxvolid is larger than that stored in the VLDB */ | ||
| 6334 | if (maxvolid) { | ||
| 6335 | afs_uint32 maxvldbid = 0; | ||
| 6336 | code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid); | ||
| 6337 | if (code) { | ||
| 6338 | fprintf(STDERR__stderrp, | ||
| 6339 | "Could not get the highest allocated volume id from the VLDB\n"); | ||
| 6340 | if (!error) | ||
| 6341 | error = code; | ||
| 6342 | } else if (maxvolid > maxvldbid) { | ||
| 6343 | afs_uint32 id, nid; | ||
| 6344 | id = maxvolid - maxvldbid + 1; | ||
| 6345 | code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid); | ||
| 6346 | if (code) { | ||
| 6347 | fprintf(STDERR__stderrp, | ||
| 6348 | "Error in increasing highest allocated volume id in VLDB\n"); | ||
| 6349 | if (!error) | ||
| 6350 | error = code; | ||
| 6351 | } | ||
| 6352 | } | ||
| 6353 | } | ||
| 6354 | |||
| 6355 | verbose = tverbose; | ||
| 6356 | if (verbose) { | ||
| 6357 | if (error) | ||
| 6358 | fprintf(STDOUT__stdoutp, "...error encountered"); | ||
| 6359 | else | ||
| 6360 | fprintf(STDOUT__stdoutp, "...done entry\n"); | ||
| 6361 | } | ||
| 6362 | if (aconn) | ||
| 6363 | rx_DestroyConnection(aconn); | ||
| 6364 | if (volumeInfo.volEntries_val) | ||
| 6365 | free(volumeInfo.volEntries_val); | ||
| 6366 | |||
| 6367 | PrintError("", error); | ||
| 6368 | return error; | ||
| 6369 | } | ||
| 6370 | |||
| 6371 | /* UV_SyncVldb() | ||
| 6372 | * Synchronise vldb with the file server <aserver> and, | ||
| 6373 | * optionally, <apart>. | ||
| 6374 | */ | ||
| 6375 | int | ||
| 6376 | UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force) | ||
| 6377 | { | ||
| 6378 | struct rx_connection *aconn; | ||
| 6379 | afs_int32 code, error = 0; | ||
| 6380 | int i, pfail; | ||
| 6381 | unsigned int j; | ||
| 6382 | volEntries volumeInfo; | ||
| 6383 | struct partList PartList; | ||
| 6384 | afs_int32 pcnt; | ||
| 6385 | char pname[10]; | ||
| 6386 | volintInfo *vi; | ||
| 6387 | afs_int32 failures = 0, modifications = 0, tentries = 0; | ||
| 6388 | afs_int32 modified; | ||
| 6389 | afs_uint32 maxvolid = 0; | ||
| 6390 | char hoststr[16]; | ||
| 6391 | |||
| 6392 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6393 | volumeInfo.volEntries_len = 0; | ||
| 6394 | |||
| 6395 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 6396 | |||
| 6397 | /* Generate array of partitions to check */ | ||
| 6398 | if (!(flags & 1)) { | ||
| 6399 | code = UV_ListPartitions(aserver, &PartList, &pcnt); | ||
| 6400 | if (code) { | ||
| 6401 | fprintf(STDERR__stderrp, | ||
| 6402 | "Could not fetch the list of partitions from the server\n"); | ||
| 6403 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6404 | } | ||
| 6405 | } else { | ||
| 6406 | PartList.partId[0] = apart; | ||
| 6407 | pcnt = 1; | ||
| 6408 | } | ||
| 6409 | |||
| 6410 | VPRINT("Processing volume entries ...\n"){ if (verbose) { fprintf(__stdoutp, ("Processing volume entries ...\n" )); fflush(__stdoutp); } }; | ||
| 6411 | |||
| 6412 | /* Step through the array of partitions */ | ||
| 6413 | for (i = 0; i < pcnt; i++) { | ||
| 6414 | apart = PartList.partId[i]; | ||
| 6415 | MapPartIdIntoName(apart, pname); | ||
| 6416 | |||
| 6417 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6418 | volumeInfo.volEntries_len = 0; | ||
| 6419 | code = AFSVolListVolumes(aconn, apart, 1, &volumeInfo); | ||
| 6420 | if (code) { | ||
| 6421 | fprintf(STDERR__stderrp, | ||
| 6422 | "Could not fetch the list of volumes from the server\n"); | ||
| 6423 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6424 | } | ||
| 6425 | |||
| 6426 | /* May want to sort the entries: RW, BK (high to low), RO (high to low) */ | ||
| 6427 | qsort((char *)volumeInfo.volEntries_val, volumeInfo.volEntries_len, | ||
| 6428 | sizeof(volintInfo), sortVolumes); | ||
| 6429 | |||
| 6430 | pfail = 0; | ||
| 6431 | for (vi = volumeInfo.volEntries_val, j = 0; | ||
| 6432 | j < volumeInfo.volEntries_len; j++, vi++) { | ||
| 6433 | if (!vi->status) | ||
| 6434 | continue; | ||
| 6435 | |||
| 6436 | tentries++; | ||
| 6437 | |||
| 6438 | if (verbose) { | ||
| 6439 | fprintf(STDOUT__stdoutp, | ||
| 6440 | "Processing volume entry %d: %s (%lu) on server %s %s...\n", | ||
| 6441 | j + 1, vi->name, (unsigned long)vi->volid, | ||
| 6442 | noresolve ? | ||
| 6443 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 6444 | hostutil_GetNameByINet(aserver), pname); | ||
| 6445 | fflush(STDOUT__stdoutp); | ||
| 6446 | } | ||
| 6447 | |||
| 6448 | if (flags & 2) | ||
| 6449 | modified = 1; | ||
| 6450 | else | ||
| 6451 | modified = 0; | ||
| 6452 | code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL((void *)0)); | ||
| 6453 | if (code) { | ||
| 6454 | PrintError("", code); | ||
| 6455 | failures++; | ||
| 6456 | pfail++; | ||
| 6457 | } else if (modified) { | ||
| 6458 | modifications++; | ||
| 6459 | } | ||
| 6460 | |||
| 6461 | if (verbose) { | ||
| 6462 | if (code) { | ||
| 6463 | fprintf(STDOUT__stdoutp, "...error encountered\n\n"); | ||
| 6464 | } else { | ||
| 6465 | fprintf(STDOUT__stdoutp, "...done entry %d\n\n", j + 1); | ||
| 6466 | } | ||
| 6467 | } | ||
| 6468 | } | ||
| 6469 | |||
| 6470 | if (pfail) { | ||
| 6471 | fprintf(STDERR__stderrp, | ||
| 6472 | "Could not process entries on server %s partition %s\n", | ||
| 6473 | noresolve ? | ||
| 6474 | afs_inet_ntoa_r(aserver, hoststr) : | ||
| 6475 | hostutil_GetNameByINet(aserver), pname); | ||
| 6476 | } | ||
| 6477 | if (volumeInfo.volEntries_val) { | ||
| 6478 | free(volumeInfo.volEntries_val); | ||
| 6479 | volumeInfo.volEntries_val = 0; | ||
| 6480 | } | ||
| 6481 | |||
| 6482 | } /* thru all partitions */ | ||
| 6483 | |||
| 6484 | if (flags & 2) { | ||
| 6485 | VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",{ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Would change %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } } | ||
| 6486 | tentries, failures, modifications){ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Would change %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } }; | ||
| 6487 | } else { | ||
| 6488 | VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",{ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Changed %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } } | ||
| 6489 | tentries, failures, modifications){ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Changed %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } }; | ||
| 6490 | } | ||
| 6491 | |||
| 6492 | error_exit: | ||
| 6493 | /* Now check if the maxvolid is larger than that stored in the VLDB */ | ||
| 6494 | if (maxvolid) { | ||
| 6495 | afs_uint32 maxvldbid = 0; | ||
| 6496 | code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid); | ||
| 6497 | if (code) { | ||
| 6498 | fprintf(STDERR__stderrp, | ||
| 6499 | "Could not get the highest allocated volume id from the VLDB\n"); | ||
| 6500 | if (!error) | ||
| 6501 | error = code; | ||
| 6502 | } else if (maxvolid > maxvldbid) { | ||
| 6503 | afs_uint32 id, nid; | ||
| 6504 | id = maxvolid - maxvldbid + 1; | ||
| 6505 | code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid); | ||
| 6506 | if (code) { | ||
| 6507 | fprintf(STDERR__stderrp, | ||
| 6508 | "Error in increasing highest allocated volume id in VLDB\n"); | ||
| 6509 | if (!error) | ||
| 6510 | error = code; | ||
| 6511 | } | ||
| 6512 | } | ||
| 6513 | } | ||
| 6514 | |||
| 6515 | if (aconn) | ||
| 6516 | rx_DestroyConnection(aconn); | ||
| 6517 | if (volumeInfo.volEntries_val) | ||
| 6518 | free(volumeInfo.volEntries_val); | ||
| 6519 | PrintError("", error); | ||
| 6520 | return (error); | ||
| 6521 | } | ||
| 6522 | |||
| 6523 | /* VolumeExists() | ||
| 6524 | * Determine if a volume exists on a server and partition. | ||
| 6525 | * Try creating a transaction on the volume. If we can, | ||
| 6526 | * the volume exists, if not, then return the error code. | ||
| 6527 | * Some error codes mean the volume is unavailable but | ||
| 6528 | * still exists - so we catch these error codes. | ||
| 6529 | */ | ||
| 6530 | static afs_int32 | ||
| 6531 | VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid) | ||
| 6532 | { | ||
| 6533 | struct rx_connection *conn = (struct rx_connection *)0; | ||
| 6534 | afs_int32 code = -1; | ||
| 6535 | volEntries volumeInfo; | ||
| 6536 | |||
| 6537 | conn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 6538 | if (conn) { | ||
| 6539 | volumeInfo.volEntries_val = (volintInfo *) 0; | ||
| 6540 | volumeInfo.volEntries_len = 0; | ||
| 6541 | code = AFSVolListOneVolume(conn, partition, volumeid, &volumeInfo); | ||
| 6542 | if (volumeInfo.volEntries_val) | ||
| 6543 | free(volumeInfo.volEntries_val); | ||
| 6544 | if (code == VOLSERILLEGAL_PARTITION(1492325125L)) | ||
| 6545 | code = ENODEV19; | ||
| 6546 | rx_DestroyConnection(conn); | ||
| 6547 | } | ||
| 6548 | return code; | ||
| 6549 | } | ||
| 6550 | |||
| 6551 | /* CheckVldbRWBK() | ||
| 6552 | * | ||
| 6553 | */ | ||
| 6554 | static afs_int32 | ||
| 6555 | CheckVldbRWBK(struct nvldbentry * entry, afs_int32 * modified) | ||
| 6556 | { | ||
| 6557 | int modentry = 0; | ||
| 6558 | int idx; | ||
| 6559 | afs_int32 code, error = 0; | ||
| 6560 | char pname[10]; | ||
| 6561 | char hoststr[16]; | ||
| 6562 | |||
| 6563 | if (modified) | ||
| 6564 | *modified = 0; | ||
| 6565 | idx = Lp_GetRwIndex(entry); | ||
| 6566 | |||
| 6567 | /* Check to see if the RW volume exists and set the RW_EXISTS | ||
| 6568 | * flag accordingly. | ||
| 6569 | */ | ||
| 6570 | if (idx == -1) { /* Did not find a RW entry */ | ||
| 6571 | if (entry->flags & RW_EXISTS0x1000) { /* ... yet entry says RW exists */ | ||
| 6572 | entry->flags &= ~RW_EXISTS0x1000; /* ... so say RW does not exist */ | ||
| 6573 | modentry++; | ||
| 6574 | } | ||
| 6575 | } else { | ||
| 6576 | code = | ||
| 6577 | VolumeExists(entry->serverNumber[idx], | ||
| 6578 | entry->serverPartition[idx], entry->volumeId[RWVOL0]); | ||
| 6579 | if (code == 0) { /* RW volume exists */ | ||
| 6580 | if (!(entry->flags & RW_EXISTS0x1000)) { /* ... yet entry says RW does not exist */ | ||
| 6581 | entry->flags |= RW_EXISTS0x1000; /* ... so say RW does exist */ | ||
| 6582 | modentry++; | ||
| 6583 | } | ||
| 6584 | } else if (code == ENODEV19) { /* RW volume does not exist */ | ||
| 6585 | if (entry->flags & RW_EXISTS0x1000) { /* ... yet entry says RW exists */ | ||
| 6586 | entry->flags &= ~RW_EXISTS0x1000; /* ... so say RW does not exist */ | ||
| 6587 | modentry++; | ||
| 6588 | } | ||
| 6589 | } else { | ||
| 6590 | /* If VLDB says it didn't exist, then ignore error */ | ||
| 6591 | if (entry->flags & RW_EXISTS0x1000) { | ||
| 6592 | MapPartIdIntoName(entry->serverPartition[idx], pname); | ||
| 6593 | fprintf(STDERR__stderrp, | ||
| 6594 | "Transaction call failed for RW volume %u on server %s %s\n", | ||
| 6595 | entry->volumeId[RWVOL0], | ||
| 6596 | noresolve ? | ||
| 6597 | afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) : | ||
| 6598 | hostutil_GetNameByINet(entry->serverNumber[idx]), | ||
| 6599 | pname); | ||
| 6600 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6601 | } | ||
| 6602 | } | ||
| 6603 | } | ||
| 6604 | |||
| 6605 | /* Check to see if the BK volume exists and set the BACK_EXISTS | ||
| 6606 | * flag accordingly. idx already ponts to the RW entry. | ||
| 6607 | */ | ||
| 6608 | if (idx == -1) { /* Did not find a RW entry */ | ||
| 6609 | if (entry->flags & BACK_EXISTS0x4000) { /* ... yet entry says BK exists */ | ||
| 6610 | entry->flags &= ~BACK_EXISTS0x4000; /* ... so say BK does not exist */ | ||
| 6611 | modentry++; | ||
| 6612 | } | ||
| 6613 | } else { /* Found a RW entry */ | ||
| 6614 | code = | ||
| 6615 | VolumeExists(entry->serverNumber[idx], | ||
| 6616 | entry->serverPartition[idx], | ||
| 6617 | entry->volumeId[BACKVOL2]); | ||
| 6618 | if (code == 0) { /* BK volume exists */ | ||
| 6619 | if (!(entry->flags & BACK_EXISTS0x4000)) { /* ... yet entry says BK does not exist */ | ||
| 6620 | entry->flags |= BACK_EXISTS0x4000; /* ... so say BK does exist */ | ||
| 6621 | modentry++; | ||
| 6622 | } | ||
| 6623 | } else if (code == ENODEV19) { /* BK volume does not exist */ | ||
| 6624 | if (entry->flags & BACK_EXISTS0x4000) { /* ... yet entry says BK exists */ | ||
| 6625 | entry->flags &= ~BACK_EXISTS0x4000; /* ... so say BK does not exist */ | ||
| 6626 | modentry++; | ||
| 6627 | } | ||
| 6628 | } else { | ||
| 6629 | /* If VLDB says it didn't exist, then ignore error */ | ||
| 6630 | if (entry->flags & BACK_EXISTS0x4000) { | ||
| 6631 | MapPartIdIntoName(entry->serverPartition[idx], pname); | ||
| 6632 | fprintf(STDERR__stderrp, | ||
| 6633 | "Transaction call failed for BK volume %u on server %s %s\n", | ||
| 6634 | entry->volumeId[BACKVOL2], | ||
| 6635 | noresolve ? | ||
| 6636 | afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) : | ||
| 6637 | hostutil_GetNameByINet(entry->serverNumber[idx]), | ||
| 6638 | pname); | ||
| 6639 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6640 | } | ||
| 6641 | } | ||
| 6642 | } | ||
| 6643 | |||
| 6644 | /* If there is an idx but the BK and RW volumes no | ||
| 6645 | * longer exist, then remove the RW entry. | ||
| 6646 | */ | ||
| 6647 | if ((idx != -1) && !(entry->flags & RW_EXISTS0x1000) | ||
| 6648 | && !(entry->flags & BACK_EXISTS0x4000)) { | ||
| 6649 | Lp_SetRWValue(entry, entry->serverNumber[idx], | ||
| 6650 | entry->serverPartition[idx], 0L, 0L); | ||
| 6651 | entry->nServers--; | ||
| 6652 | modentry++; | ||
| 6653 | } | ||
| 6654 | |||
| 6655 | error_exit: | ||
| 6656 | if (modified) | ||
| 6657 | *modified = modentry; | ||
| 6658 | return (error); | ||
| 6659 | } | ||
| 6660 | |||
| 6661 | static afs_int32 | ||
| 6662 | CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified) | ||
| 6663 | { | ||
| 6664 | int idx; | ||
| 6665 | int foundro = 0, modentry = 0; | ||
| 6666 | afs_int32 code, error = 0; | ||
| 6667 | char pname[10]; | ||
| 6668 | char hoststr[16]; | ||
| 6669 | |||
| 6670 | if (modified) | ||
| 6671 | *modified = 0; | ||
| 6672 | |||
| 6673 | /* Check to see if the RO volumes exist and set the RO_EXISTS | ||
| 6674 | * flag accordingly. | ||
| 6675 | */ | ||
| 6676 | for (idx = 0; idx < entry->nServers; idx++) { | ||
| 6677 | if (!(entry->serverFlags[idx] & ITSROVOL0x02)) { | ||
| 6678 | continue; /* not a RO */ | ||
| 6679 | } | ||
| 6680 | |||
| 6681 | code = | ||
| 6682 | VolumeExists(entry->serverNumber[idx], | ||
| 6683 | entry->serverPartition[idx], entry->volumeId[ROVOL1]); | ||
| 6684 | if (code == 0) { /* RO volume exists */ | ||
| 6685 | foundro++; | ||
| 6686 | } else if (code == ENODEV19) { /* RW volume does not exist */ | ||
| 6687 | Lp_SetROValue(entry, entry->serverNumber[idx], | ||
| 6688 | entry->serverPartition[idx], 0L, 0L); | ||
| 6689 | entry->nServers--; | ||
| 6690 | idx--; | ||
| 6691 | modentry++; | ||
| 6692 | } else { | ||
| 6693 | MapPartIdIntoName(entry->serverPartition[idx], pname); | ||
| 6694 | fprintf(STDERR__stderrp, | ||
| 6695 | "Transaction call failed for RO %u on server %s %s\n", | ||
| 6696 | entry->volumeId[ROVOL1], | ||
| 6697 | noresolve ? | ||
| 6698 | afs_inet_ntoa_r(entry->serverNumber[idx], hoststr) : | ||
| 6699 | hostutil_GetNameByINet(entry->serverNumber[idx]), pname); | ||
| 6700 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6701 | } | ||
| 6702 | } | ||
| 6703 | |||
| 6704 | if (foundro) { /* A RO volume exists */ | ||
| 6705 | if (!(entry->flags & RO_EXISTS0x2000)) { /* ... yet entry says RW does not exist */ | ||
| 6706 | entry->flags |= RO_EXISTS0x2000; /* ... so say RW does exist */ | ||
| 6707 | modentry++; | ||
| 6708 | } | ||
| 6709 | } else { /* A RO volume does not exist */ | ||
| 6710 | if (entry->flags & RO_EXISTS0x2000) { /* ... yet entry says RO exists */ | ||
| 6711 | entry->flags &= ~RO_EXISTS0x2000; /* ... so say RO does not exist */ | ||
| 6712 | modentry++; | ||
| 6713 | } | ||
| 6714 | } | ||
| 6715 | |||
| 6716 | error_exit: | ||
| 6717 | if (modified) | ||
| 6718 | *modified = modentry; | ||
| 6719 | return (error); | ||
| 6720 | } | ||
| 6721 | |||
| 6722 | /* CheckVldb() | ||
| 6723 | * Ensure that <entry> matches with the info on file servers | ||
| 6724 | */ | ||
| 6725 | static afs_int32 | ||
| 6726 | CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted) | ||
| 6727 | { | ||
| 6728 | afs_int32 code, error = 0; | ||
| 6729 | struct nvldbentry storeEntry; | ||
| 6730 | int islocked = 0, mod, modentry, delentry = 0; | ||
| 6731 | int pass = 0, doit=1; | ||
| 6732 | |||
| 6733 | if (modified) { | ||
| 6734 | if (*modified == 1) | ||
| 6735 | doit = 0; | ||
| 6736 | *modified = 0; | ||
| 6737 | } | ||
| 6738 | if (verbose) { | ||
| 6739 | fprintf(STDOUT__stdoutp, "_______________________________\n"); | ||
| 6740 | fprintf(STDOUT__stdoutp, "\n-- status before -- \n"); | ||
| 6741 | if ((entry->flags & RW_EXISTS0x1000) || (entry->flags & RO_EXISTS0x2000) | ||
| 6742 | || (entry->flags & BACK_EXISTS0x4000)) | ||
| 6743 | EnumerateEntry(entry); | ||
| 6744 | fprintf(STDOUT__stdoutp, "\n"); | ||
| 6745 | } | ||
| 6746 | |||
| 6747 | if (strlen(entry->name) > (VOLSER_OLDMAXVOLNAME32 - 10)) { | ||
| 6748 | fprintf(STDERR__stderrp, "Volume name %s exceeds limit of %d characters\n", | ||
| 6749 | entry->name, VOLSER_OLDMAXVOLNAME32 - 10); | ||
| 6750 | } | ||
| 6751 | |||
| 6752 | retry: | ||
| 6753 | /* Check to see if the VLDB is ok without locking it (pass 1). | ||
| 6754 | * If it will change, then lock the VLDB entry, read it again, | ||
| 6755 | * then make the changes to it (pass 2). | ||
| 6756 | */ | ||
| 6757 | if (++pass == 2) { | ||
| 6758 | code = | ||
| 6759 | ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL0], RWVOL0, | ||
| 6760 | VLOP_DELETE0x80); | ||
| 6761 | if (code) { | ||
| 6762 | fprintf(STDERR__stderrp, "Could not lock VLDB entry for %u \n", | ||
| 6763 | entry->volumeId[RWVOL0]); | ||
| 6764 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6765 | } | ||
| 6766 | islocked = 1; | ||
| 6767 | |||
| 6768 | code = VLDB_GetEntryByID(entry->volumeId[RWVOL0], RWVOL0, entry); | ||
| 6769 | if (code) { | ||
| 6770 | fprintf(STDERR__stderrp, "Could not read VLDB entry for volume %s\n", | ||
| 6771 | entry->name); | ||
| 6772 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6773 | } else { | ||
| 6774 | MapHostToNetwork(entry); | ||
| 6775 | } | ||
| 6776 | } | ||
| 6777 | |||
| 6778 | modentry = 0; | ||
| 6779 | |||
| 6780 | /* Check if the RW and BK entries are ok */ | ||
| 6781 | code = CheckVldbRWBK(entry, &mod); | ||
| 6782 | if (code) | ||
| 6783 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6784 | if (mod && (pass == 1) && doit) | ||
| 6785 | goto retry; | ||
| 6786 | if (mod) | ||
| 6787 | modentry++; | ||
| 6788 | |||
| 6789 | /* Check if the RO volumes entries are ok */ | ||
| 6790 | code = CheckVldbRO(entry, &mod); | ||
| 6791 | if (code) | ||
| 6792 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6793 | if (mod && (pass == 1) && doit) | ||
| 6794 | goto retry; | ||
| 6795 | if (mod) | ||
| 6796 | modentry++; | ||
| 6797 | |||
| 6798 | /* The VLDB entry has been updated. If it as been modified, then | ||
| 6799 | * write the entry back out the the VLDB. | ||
| 6800 | */ | ||
| 6801 | if (modentry && doit) { | ||
| 6802 | if (pass == 1) | ||
| 6803 | goto retry; | ||
| 6804 | |||
| 6805 | if (!(entry->flags & RW_EXISTS0x1000) && !(entry->flags & BACK_EXISTS0x4000) | ||
| 6806 | && !(entry->flags & RO_EXISTS0x2000) && doit) { | ||
| 6807 | /* The RW, BK, nor RO volumes do not exist. Delete the VLDB entry */ | ||
| 6808 | code = | ||
| 6809 | ubik_VL_DeleteEntry(cstruct, 0, entry->volumeId[RWVOL0], | ||
| 6810 | RWVOL0); | ||
| 6811 | if (code) { | ||
| 6812 | fprintf(STDERR__stderrp, | ||
| 6813 | "Could not delete VLDB entry for volume %u \n", | ||
| 6814 | entry->volumeId[RWVOL0]); | ||
| 6815 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6816 | } | ||
| 6817 | delentry = 1; | ||
| 6818 | } else { | ||
| 6819 | /* Replace old entry with our new one */ | ||
| 6820 | MapNetworkToHost(entry, &storeEntry); | ||
| 6821 | code = | ||
| 6822 | VLDB_ReplaceEntry(entry->volumeId[RWVOL0], RWVOL0, &storeEntry, | ||
| 6823 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | | ||
| 6824 | LOCKREL_TIMESTAMP1)); | ||
| 6825 | if (code) { | ||
| 6826 | fprintf(STDERR__stderrp, "Could not update VLDB entry for volume %u\n", | ||
| 6827 | entry->volumeId[RWVOL0]); | ||
| 6828 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6829 | } | ||
| 6830 | } | ||
| 6831 | islocked = 0; | ||
| 6832 | } | ||
| 6833 | |||
| 6834 | if (modified && modentry) { | ||
| 6835 | *modified = 1; | ||
| 6836 | } | ||
| 6837 | if (deleted && delentry) { | ||
| 6838 | *deleted = 1; | ||
| 6839 | } | ||
| 6840 | |||
| 6841 | if (verbose) { | ||
| 6842 | fprintf(STDOUT__stdoutp, "-- status after --\n"); | ||
| 6843 | if (delentry) | ||
| 6844 | fprintf(STDOUT__stdoutp, "\n**entry deleted**\n"); | ||
| 6845 | else if (modentry) | ||
| 6846 | EnumerateEntry(entry); | ||
| 6847 | else | ||
| 6848 | fprintf(STDOUT__stdoutp, "\n**no change**\n"); | ||
| 6849 | } | ||
| 6850 | |||
| 6851 | error_exit: | ||
| 6852 | VPRINT("\n_______________________________\n"){ if (verbose) { fprintf(__stdoutp, ("\n_______________________________\n" )); fflush(__stdoutp); } }; | ||
| 6853 | |||
| 6854 | if (islocked) { | ||
| 6855 | code = | ||
| 6856 | ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL0], | ||
| 6857 | RWVOL0, | ||
| 6858 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1)); | ||
| 6859 | if (code) { | ||
| 6860 | fprintf(STDERR__stderrp, | ||
| 6861 | "Could not release lock on VLDB entry for volume %u\n", | ||
| 6862 | entry->volumeId[RWVOL0]); | ||
| 6863 | if (!error) | ||
| 6864 | error = code; | ||
| 6865 | } | ||
| 6866 | } | ||
| 6867 | return error; | ||
| 6868 | } | ||
| 6869 | |||
| 6870 | /* UV_SyncServer() | ||
| 6871 | * Synchronise <aserver> <apart>(if flags = 1) with the VLDB. | ||
| 6872 | */ | ||
| 6873 | int | ||
| 6874 | UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force) | ||
| 6875 | { | ||
| 6876 | struct rx_connection *aconn; | ||
| 6877 | afs_int32 code, error = 0; | ||
| 6878 | afs_int32 nentries, tentries = 0; | ||
| 6879 | struct VldbListByAttributes attributes; | ||
| 6880 | nbulkentries arrayEntries; | ||
| 6881 | afs_int32 failures = 0, modified, modifications = 0; | ||
| 6882 | struct nvldbentry *vlentry; | ||
| 6883 | afs_int32 si, nsi, j; | ||
| 6884 | |||
| 6885 | if (flags & 2) | ||
| 6886 | verbose = 1; | ||
| 6887 | |||
| 6888 | aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT7005); | ||
| 6889 | |||
| 6890 | /* Set up attributes to search VLDB */ | ||
| 6891 | attributes.server = ntohl(aserver)(__builtin_constant_p(aserver) ? ((((__uint32_t)(aserver)) >> 24) | ((((__uint32_t)(aserver)) & (0xff << 16)) >> 8) | ((((__uint32_t)(aserver)) & (0xff << 8)) << 8) | (((__uint32_t)(aserver)) << 24)) : __bswap32_var( aserver)); | ||
| 6892 | attributes.Mask = VLLIST_SERVER0x1; | ||
| 6893 | if ((flags & 1)) { | ||
| 6894 | attributes.partition = apart; | ||
| 6895 | attributes.Mask |= VLLIST_PARTITION0x2; | ||
| 6896 | } | ||
| 6897 | |||
| 6898 | VPRINT("Processing VLDB entries ...\n"){ if (verbose) { fprintf(__stdoutp, ("Processing VLDB entries ...\n" )); fflush(__stdoutp); } }; | ||
| 6899 | |||
| 6900 | /* While we need to collect more VLDB entries */ | ||
| 6901 | for (si = 0; si != -1; si = nsi) { | ||
| 6902 | memset(&arrayEntries, 0, sizeof(arrayEntries)); | ||
| 6903 | |||
| 6904 | /* Collect set of VLDB entries */ | ||
| 6905 | code = | ||
| 6906 | VLDB_ListAttributesN2(&attributes, 0, si, &nentries, | ||
| 6907 | &arrayEntries, &nsi); | ||
| 6908 | if (code == RXGEN_OPCODE-455) { | ||
| 6909 | code = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); | ||
| 6910 | nsi = -1; | ||
| 6911 | } | ||
| 6912 | if (code) { | ||
| 6913 | fprintf(STDERR__stderrp, "Could not access the VLDB for attributes\n"); | ||
| 6914 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 6915 | } | ||
| 6916 | tentries += nentries; | ||
| 6917 | |||
| 6918 | for (j = 0; j < nentries; j++) { | ||
| 6919 | vlentry = &arrayEntries.nbulkentries_val[j]; | ||
| 6920 | MapHostToNetwork(vlentry); | ||
| 6921 | |||
| 6922 | VPRINT1("Processing VLDB entry %d ...\n", j + 1){ if (verbose) { fprintf(__stdoutp, ("Processing VLDB entry %d ...\n" ), (j + 1)); fflush(__stdoutp); } }; | ||
| 6923 | |||
| 6924 | /* Tell CheckVldb not to update if appropriate */ | ||
| 6925 | if (flags & 2) | ||
| 6926 | modified = 1; | ||
| 6927 | else | ||
| 6928 | modified = 0; | ||
| 6929 | code = CheckVldb(vlentry, &modified, NULL((void *)0)); | ||
| 6930 | if (code) { | ||
| 6931 | PrintError("", code); | ||
| 6932 | fprintf(STDERR__stderrp, | ||
| 6933 | "Could not process VLDB entry for volume %s\n", | ||
| 6934 | vlentry->name); | ||
| 6935 | failures++; | ||
| 6936 | } else if (modified) { | ||
| 6937 | modifications++; | ||
| 6938 | } | ||
| 6939 | |||
| 6940 | if (verbose) { | ||
| 6941 | if (code) { | ||
| 6942 | fprintf(STDOUT__stdoutp, "...error encountered\n\n"); | ||
| 6943 | } else { | ||
| 6944 | fprintf(STDOUT__stdoutp, "...done entry %d\n\n", j + 1); | ||
| 6945 | } | ||
| 6946 | } | ||
| 6947 | } | ||
| 6948 | |||
| 6949 | if (arrayEntries.nbulkentries_val) { | ||
| 6950 | free(arrayEntries.nbulkentries_val); | ||
| 6951 | arrayEntries.nbulkentries_val = 0; | ||
| 6952 | } | ||
| 6953 | } | ||
| 6954 | |||
| 6955 | if (flags & 2) { | ||
| 6956 | VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",{ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Would change %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } } | ||
| 6957 | tentries, failures, modifications){ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Would change %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } }; | ||
| 6958 | } else { | ||
| 6959 | VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",{ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Changed %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } } | ||
| 6960 | tentries, failures, modifications){ if (verbose) { fprintf(__stdoutp, ("Total entries: %u, Failed to process %d, Changed %d\n" ), (tentries), (failures), (modifications)); fflush(__stdoutp ); } }; | ||
| 6961 | } | ||
| 6962 | |||
| 6963 | error_exit: | ||
| 6964 | if (aconn) | ||
| 6965 | rx_DestroyConnection(aconn); | ||
| 6966 | if (arrayEntries.nbulkentries_val) | ||
| 6967 | free(arrayEntries.nbulkentries_val); | ||
| 6968 | |||
| 6969 | if (failures) | ||
| 6970 | error = VOLSERFAILEDOP(1492325137L); | ||
| 6971 | return error; | ||
| 6972 | } | ||
| 6973 | |||
| 6974 | /*rename volume <oldname> to <newname>, changing the names of the related | ||
| 6975 | *readonly and backup volumes. This operation is also idempotent. | ||
| 6976 | *salvager is capable of recovering from rename operation stopping halfway. | ||
| 6977 | *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */ | ||
| 6978 | int | ||
| 6979 | UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[]) | ||
| 6980 | { | ||
| 6981 | struct nvldbentry storeEntry; | ||
| 6982 | afs_int32 vcode, code, rcode, error; | ||
| 6983 | int i, index; | ||
| 6984 | char nameBuffer[256]; | ||
| 6985 | afs_int32 tid; | ||
| 6986 | struct rx_connection *aconn; | ||
| 6987 | int islocked; | ||
| 6988 | char hoststr[16]; | ||
| 6989 | |||
| 6990 | error = 0; | ||
| 6991 | aconn = (struct rx_connection *)0; | ||
| 6992 | tid = 0; | ||
| 6993 | islocked = 0; | ||
| 6994 | |||
| 6995 | vcode = ubik_VL_SetLock(cstruct, 0, entry->volumeId[RWVOL0], RWVOL0, VLOP_ADDSITE0x80); /*last param is dummy */ | ||
| 6996 | if (vcode) { | ||
| 6997 | fprintf(STDERR__stderrp, | ||
| 6998 | " Could not lock the VLDB entry for the volume %u \n", | ||
| 6999 | entry->volumeId[RWVOL0]); | ||
| 7000 | error = vcode; | ||
| 7001 | goto rvfail; | ||
| 7002 | } | ||
| 7003 | islocked = 1; | ||
| 7004 | strncpy(entry->name, newname, VOLSER_OLDMAXVOLNAME32); | ||
| 7005 | MapNetworkToHost(entry, &storeEntry); | ||
| 7006 | vcode = VLDB_ReplaceEntry(entry->volumeId[RWVOL0], RWVOL0, &storeEntry, 0); | ||
| 7007 | if (vcode) { | ||
| 7008 | fprintf(STDERR__stderrp, "Could not update VLDB entry for %u\n", | ||
| 7009 | entry->volumeId[RWVOL0]); | ||
| 7010 | error = vcode; | ||
| 7011 | goto rvfail; | ||
| 7012 | } | ||
| 7013 | VPRINT1("Recorded the new name %s in VLDB\n", newname){ if (verbose) { fprintf(__stdoutp, ("Recorded the new name %s in VLDB\n" ), (newname)); fflush(__stdoutp); } }; | ||
| 7014 | /*at this stage the intent to rename is recorded in the vldb, as far as the vldb | ||
| 7015 | * is concerned, oldname is lost */ | ||
| 7016 | if (entry->flags & RW_EXISTS0x1000) { | ||
| 7017 | index = Lp_GetRwIndex(entry); | ||
| 7018 | if (index == -1) { /* there is a serious discrepancy */ | ||
| 7019 | fprintf(STDERR__stderrp, | ||
| 7020 | "There is a serious discrepancy in VLDB entry for volume %u\n", | ||
| 7021 | entry->volumeId[RWVOL0]); | ||
| 7022 | fprintf(STDERR__stderrp, "try building VLDB from scratch\n"); | ||
| 7023 | error = VOLSERVLDB_ERROR(1492325128L); | ||
| 7024 | goto rvfail; | ||
| 7025 | } | ||
| 7026 | aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT7005); | ||
| 7027 | code = | ||
| 7028 | AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL0], | ||
| 7029 | entry->serverPartition[index], ITOffline1, &tid); | ||
| 7030 | if (code) { /*volume doesnot exist */ | ||
| 7031 | fprintf(STDERR__stderrp, | ||
| 7032 | "Could not start transaction on the rw volume %u\n", | ||
| 7033 | entry->volumeId[RWVOL0]); | ||
| 7034 | error = code; | ||
| 7035 | goto rvfail; | ||
| 7036 | } else { /*volume exists, process it */ | ||
| 7037 | |||
| 7038 | code = | ||
| 7039 | AFSVolSetIdsTypes(aconn, tid, newname, RWVOL0, | ||
| 7040 | entry->volumeId[RWVOL0], | ||
| 7041 | entry->volumeId[ROVOL1], | ||
| 7042 | entry->volumeId[BACKVOL2]); | ||
| 7043 | if (!code) { | ||
| 7044 | VPRINT2("Renamed rw volume %s to %s\n", oldname, newname){ if (verbose) { fprintf(__stdoutp, ("Renamed rw volume %s to %s\n" ), (oldname), (newname)); fflush(__stdoutp); } }; | ||
| 7045 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 7046 | tid = 0; | ||
| 7047 | if (code) { | ||
| 7048 | fprintf(STDERR__stderrp, | ||
| 7049 | "Could not end transaction on volume %s %u\n", | ||
| 7050 | entry->name, entry->volumeId[RWVOL0]); | ||
| 7051 | error = code; | ||
| 7052 | goto rvfail; | ||
| 7053 | } | ||
| 7054 | } else { | ||
| 7055 | fprintf(STDERR__stderrp, "Could not set parameters on volume %s %u\n", | ||
| 7056 | entry->name, entry->volumeId[RWVOL0]); | ||
| 7057 | error = code; | ||
| 7058 | goto rvfail; | ||
| 7059 | } | ||
| 7060 | } | ||
| 7061 | if (aconn) | ||
| 7062 | rx_DestroyConnection(aconn); | ||
| 7063 | aconn = (struct rx_connection *)0; | ||
| 7064 | } | ||
| 7065 | /*end rw volume processing */ | ||
| 7066 | if (entry->flags & BACK_EXISTS0x4000) { /*process the backup volume */ | ||
| 7067 | index = Lp_GetRwIndex(entry); | ||
| 7068 | if (index == -1) { /* there is a serious discrepancy */ | ||
| 7069 | fprintf(STDERR__stderrp, | ||
| 7070 | "There is a serious discrepancy in the VLDB entry for the backup volume %u\n", | ||
| 7071 | entry->volumeId[BACKVOL2]); | ||
| 7072 | fprintf(STDERR__stderrp, "try building VLDB from scratch\n"); | ||
| 7073 | error = VOLSERVLDB_ERROR(1492325128L); | ||
| 7074 | goto rvfail; | ||
| 7075 | } | ||
| 7076 | aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT7005); | ||
| 7077 | code = | ||
| 7078 | AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL2], | ||
| 7079 | entry->serverPartition[index], ITOffline1, &tid); | ||
| 7080 | if (code) { /*volume doesnot exist */ | ||
| 7081 | fprintf(STDERR__stderrp, | ||
| 7082 | "Could not start transaction on the backup volume %u\n", | ||
| 7083 | entry->volumeId[BACKVOL2]); | ||
| 7084 | error = code; | ||
| 7085 | goto rvfail; | ||
| 7086 | } else { /*volume exists, process it */ | ||
| 7087 | if (strlen(newname) > (VOLSER_OLDMAXVOLNAME32 - 8)) { | ||
| 7088 | fprintf(STDERR__stderrp, | ||
| 7089 | "Volume name %s.backup exceeds the limit of %u characters\n", | ||
| 7090 | newname, VOLSER_OLDMAXVOLNAME32); | ||
| 7091 | error = code; | ||
| 7092 | goto rvfail; | ||
| 7093 | } | ||
| 7094 | strcpy(nameBuffer, newname); | ||
| 7095 | strcat(nameBuffer, ".backup"); | ||
| 7096 | |||
| 7097 | code = | ||
| 7098 | AFSVolSetIdsTypes(aconn, tid, nameBuffer, BACKVOL2, | ||
| 7099 | entry->volumeId[RWVOL0], 0, 0); | ||
| 7100 | if (!code) { | ||
| 7101 | VPRINT1("Renamed backup volume to %s \n", nameBuffer){ if (verbose) { fprintf(__stdoutp, ("Renamed backup volume to %s \n" ), (nameBuffer)); fflush(__stdoutp); } }; | ||
| 7102 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 7103 | tid = 0; | ||
| 7104 | if (code) { | ||
| 7105 | fprintf(STDERR__stderrp, | ||
| 7106 | "Could not end transaction on the backup volume %u\n", | ||
| 7107 | entry->volumeId[BACKVOL2]); | ||
| 7108 | error = code; | ||
| 7109 | goto rvfail; | ||
| 7110 | } | ||
| 7111 | } else { | ||
| 7112 | fprintf(STDERR__stderrp, | ||
| 7113 | "Could not set parameters on the backup volume %u\n", | ||
| 7114 | entry->volumeId[BACKVOL2]); | ||
| 7115 | error = code; | ||
| 7116 | goto rvfail; | ||
| 7117 | } | ||
| 7118 | } | ||
| 7119 | } /* end backup processing */ | ||
| 7120 | if (aconn) | ||
| 7121 | rx_DestroyConnection(aconn); | ||
| 7122 | aconn = (struct rx_connection *)0; | ||
| 7123 | if (entry->flags & RO_EXISTS0x2000) { /*process the ro volumes */ | ||
| 7124 | for (i = 0; i < entry->nServers; i++) { | ||
| 7125 | if (entry->serverFlags[i] & ITSROVOL0x02) { | ||
| 7126 | aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT7005); | ||
| 7127 | code = | ||
| 7128 | AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL1], | ||
| 7129 | entry->serverPartition[i], ITOffline1, | ||
| 7130 | &tid); | ||
| 7131 | if (code) { /*volume doesnot exist */ | ||
| 7132 | fprintf(STDERR__stderrp, | ||
| 7133 | "Could not start transaction on the ro volume %u\n", | ||
| 7134 | entry->volumeId[ROVOL1]); | ||
| 7135 | error = code; | ||
| 7136 | goto rvfail; | ||
| 7137 | } else { /*volume exists, process it */ | ||
| 7138 | strcpy(nameBuffer, newname); | ||
| 7139 | strcat(nameBuffer, ".readonly"); | ||
| 7140 | if (strlen(nameBuffer) > (VOLSER_OLDMAXVOLNAME32 - 1)) { | ||
| 7141 | fprintf(STDERR__stderrp, | ||
| 7142 | "Volume name %s exceeds the limit of %u characters\n", | ||
| 7143 | nameBuffer, VOLSER_OLDMAXVOLNAME32); | ||
| 7144 | error = code; | ||
| 7145 | goto rvfail; | ||
| 7146 | } | ||
| 7147 | code = | ||
| 7148 | AFSVolSetIdsTypes(aconn, tid, nameBuffer, ROVOL1, | ||
| 7149 | entry->volumeId[RWVOL0], 0, 0); | ||
| 7150 | if (!code) { | ||
| 7151 | VPRINT2("Renamed RO volume %s on host %s\n",{ if (verbose) { fprintf(__stdoutp, ("Renamed RO volume %s on host %s\n" ), (nameBuffer), (noresolve ? afs_inet_ntoa_r(entry->serverNumber [i], hoststr) : hostutil_GetNameByINet(entry-> serverNumber [i]))); fflush(__stdoutp); } } | ||
| 7152 | nameBuffer,{ if (verbose) { fprintf(__stdoutp, ("Renamed RO volume %s on host %s\n" ), (nameBuffer), (noresolve ? afs_inet_ntoa_r(entry->serverNumber [i], hoststr) : hostutil_GetNameByINet(entry-> serverNumber [i]))); fflush(__stdoutp); } } | ||
| 7153 | noresolve ?{ if (verbose) { fprintf(__stdoutp, ("Renamed RO volume %s on host %s\n" ), (nameBuffer), (noresolve ? afs_inet_ntoa_r(entry->serverNumber [i], hoststr) : hostutil_GetNameByINet(entry-> serverNumber [i]))); fflush(__stdoutp); } } | ||
| 7154 | afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :{ if (verbose) { fprintf(__stdoutp, ("Renamed RO volume %s on host %s\n" ), (nameBuffer), (noresolve ? afs_inet_ntoa_r(entry->serverNumber [i], hoststr) : hostutil_GetNameByINet(entry-> serverNumber [i]))); fflush(__stdoutp); } } | ||
| 7155 | hostutil_GetNameByINet(entry->{ if (verbose) { fprintf(__stdoutp, ("Renamed RO volume %s on host %s\n" ), (nameBuffer), (noresolve ? afs_inet_ntoa_r(entry->serverNumber [i], hoststr) : hostutil_GetNameByINet(entry-> serverNumber [i]))); fflush(__stdoutp); } } | ||
| 7156 | serverNumber[i])){ if (verbose) { fprintf(__stdoutp, ("Renamed RO volume %s on host %s\n" ), (nameBuffer), (noresolve ? afs_inet_ntoa_r(entry->serverNumber [i], hoststr) : hostutil_GetNameByINet(entry-> serverNumber [i]))); fflush(__stdoutp); } }; | ||
| 7157 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 7158 | tid = 0; | ||
| 7159 | if (code) { | ||
| 7160 | fprintf(STDERR__stderrp, | ||
| 7161 | "Could not end transaction on volume %u\n", | ||
| 7162 | entry->volumeId[ROVOL1]); | ||
| 7163 | error = code; | ||
| 7164 | goto rvfail; | ||
| 7165 | } | ||
| 7166 | } else { | ||
| 7167 | fprintf(STDERR__stderrp, | ||
| 7168 | "Could not set parameters on the ro volume %u\n", | ||
| 7169 | entry->volumeId[ROVOL1]); | ||
| 7170 | error = code; | ||
| 7171 | goto rvfail; | ||
| 7172 | } | ||
| 7173 | } | ||
| 7174 | if (aconn) | ||
| 7175 | rx_DestroyConnection(aconn); | ||
| 7176 | aconn = (struct rx_connection *)0; | ||
| 7177 | } | ||
| 7178 | } | ||
| 7179 | } | ||
| 7180 | rvfail: | ||
| 7181 | if (islocked) { | ||
| 7182 | vcode = | ||
| 7183 | ubik_VL_ReleaseLock(cstruct, 0, entry->volumeId[RWVOL0], | ||
| 7184 | RWVOL0, | ||
| 7185 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | LOCKREL_TIMESTAMP1); | ||
| 7186 | if (vcode) { | ||
| 7187 | fprintf(STDERR__stderrp, | ||
| 7188 | "Could not unlock the VLDB entry for the volume %s %u\n", | ||
| 7189 | entry->name, entry->volumeId[RWVOL0]); | ||
| 7190 | if (!error) | ||
| 7191 | error = vcode; | ||
| 7192 | } | ||
| 7193 | } | ||
| 7194 | if (tid) { | ||
| 7195 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 7196 | if (!code) | ||
| 7197 | code = rcode; | ||
| 7198 | if (code) { | ||
| 7199 | fprintf(STDERR__stderrp, "Failed to end transaction on a volume \n"); | ||
| 7200 | if (!error) | ||
| 7201 | error = code; | ||
| 7202 | } | ||
| 7203 | } | ||
| 7204 | if (aconn) | ||
| 7205 | rx_DestroyConnection(aconn); | ||
| 7206 | PrintError("", error); | ||
| 7207 | return error; | ||
| 7208 | |||
| 7209 | } | ||
| 7210 | |||
| 7211 | /*report on all the active transactions on volser */ | ||
| 7212 | int | ||
| 7213 | UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount) | ||
| 7214 | { | ||
| 7215 | struct rx_connection *aconn; | ||
| 7216 | transDebugEntries transInfo; | ||
| 7217 | afs_int32 code = 0; | ||
| 7218 | |||
| 7219 | aconn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 7220 | transInfo.transDebugEntries_val = (transDebugInfo *) 0; | ||
| 7221 | transInfo.transDebugEntries_len = 0; | ||
| 7222 | code = AFSVolMonitor(aconn, &transInfo); | ||
| 7223 | if (code) { | ||
| 7224 | fprintf(STDERR__stderrp, | ||
| 7225 | "Could not access status information about the server\n"); | ||
| 7226 | PrintError("", code); | ||
| 7227 | if (transInfo.transDebugEntries_val) | ||
| 7228 | free(transInfo.transDebugEntries_val); | ||
| 7229 | if (aconn) | ||
| 7230 | rx_DestroyConnection(aconn); | ||
| 7231 | return code; | ||
| 7232 | } else { | ||
| 7233 | *rcount = transInfo.transDebugEntries_len; | ||
| 7234 | *rpntr = transInfo.transDebugEntries_val; | ||
| 7235 | if (aconn) | ||
| 7236 | rx_DestroyConnection(aconn); | ||
| 7237 | return 0; | ||
| 7238 | } | ||
| 7239 | |||
| 7240 | |||
| 7241 | } | ||
| 7242 | |||
| 7243 | /*delete the volume without interacting with the vldb */ | ||
| 7244 | int | ||
| 7245 | UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid) | ||
| 7246 | { | ||
| 7247 | afs_int32 rcode, ttid, error, code; | ||
| 7248 | struct rx_connection *aconn; | ||
| 7249 | |||
| 7250 | code = 0; | ||
| 7251 | error = 0; | ||
| 7252 | ttid = 0; | ||
| 7253 | |||
| 7254 | aconn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 7255 | code = AFSVolTransCreate_retry(aconn, volid, part, ITOffline1, &ttid); | ||
| 7256 | if (code) { | ||
| 7257 | fprintf(STDERR__stderrp, "Could not start transaction on volume %lu\n", | ||
| 7258 | (unsigned long)volid); | ||
| 7259 | error = code; | ||
| 7260 | goto zfail; | ||
| 7261 | } | ||
| 7262 | code = AFSVolDeleteVolume(aconn, ttid); | ||
| 7263 | if (code) { | ||
| 7264 | fprintf(STDERR__stderrp, "Could not delete volume %lu\n", | ||
| 7265 | (unsigned long)volid); | ||
| 7266 | error = code; | ||
| 7267 | goto zfail; | ||
| 7268 | } | ||
| 7269 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 7270 | ttid = 0; | ||
| 7271 | if (!code) | ||
| 7272 | code = rcode; | ||
| 7273 | if (code) { | ||
| 7274 | fprintf(STDERR__stderrp, "Could not end transaction on volume %lu\n", | ||
| 7275 | (unsigned long)volid); | ||
| 7276 | error = code; | ||
| 7277 | goto zfail; | ||
| 7278 | } | ||
| 7279 | zfail: | ||
| 7280 | if (ttid) { | ||
| 7281 | code = AFSVolEndTrans(aconn, ttid, &rcode); | ||
| 7282 | if (!code) | ||
| 7283 | code = rcode; | ||
| 7284 | if (!error) | ||
| 7285 | error = code; | ||
| 7286 | } | ||
| 7287 | PrintError("", error); | ||
| 7288 | if (aconn) | ||
| 7289 | rx_DestroyConnection(aconn); | ||
| 7290 | return error; | ||
| 7291 | } | ||
| 7292 | |||
| 7293 | int | ||
| 7294 | UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid, | ||
| 7295 | afs_int32 transflag, afs_int32 setflag, int sleeptime) | ||
| 7296 | { | ||
| 7297 | struct rx_connection *conn = 0; | ||
| 7298 | afs_int32 tid = 0; | ||
| 7299 | afs_int32 code, error = 0, rcode; | ||
| 7300 | |||
| 7301 | conn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 7302 | if (!conn) { | ||
| 7303 | fprintf(STDERR__stderrp, "SetVolumeStatus: Bind Failed"); | ||
| 7304 | ERROR_EXIT(-1)do { error = (-1); goto error_exit; } while (0); | ||
| 7305 | } | ||
| 7306 | |||
| 7307 | code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid); | ||
| 7308 | if (code) { | ||
| 7309 | fprintf(STDERR__stderrp, "SetVolumeStatus: TransCreate Failed\n"); | ||
| 7310 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 7311 | } | ||
| 7312 | |||
| 7313 | code = AFSVolSetFlags(conn, tid, setflag); | ||
| 7314 | if (code) { | ||
| 7315 | fprintf(STDERR__stderrp, "SetVolumeStatus: SetFlags Failed\n"); | ||
| 7316 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 7317 | } | ||
| 7318 | |||
| 7319 | if (sleeptime) { | ||
| 7320 | #ifdef AFS_PTHREAD_ENV | ||
| 7321 | sleep(sleeptime); | ||
| 7322 | #else | ||
| 7323 | IOMGR_Sleep(sleeptime); | ||
| 7324 | #endif | ||
| 7325 | } | ||
| 7326 | |||
| 7327 | error_exit: | ||
| 7328 | if (tid) { | ||
| 7329 | rcode = 0; | ||
| 7330 | code = AFSVolEndTrans(conn, tid, &rcode); | ||
| 7331 | if (code || rcode) { | ||
| 7332 | fprintf(STDERR__stderrp, "SetVolumeStatus: EndTrans Failed\n"); | ||
| 7333 | if (!error) | ||
| 7334 | error = (code ? code : rcode); | ||
| 7335 | } | ||
| 7336 | } | ||
| 7337 | |||
| 7338 | if (conn) | ||
| 7339 | rx_DestroyConnection(conn); | ||
| 7340 | return (error); | ||
| 7341 | } | ||
| 7342 | |||
| 7343 | int | ||
| 7344 | UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid, | ||
| 7345 | volintInfo * infop) | ||
| 7346 | { | ||
| 7347 | struct rx_connection *conn = 0; | ||
| 7348 | afs_int32 tid = 0; | ||
| 7349 | afs_int32 code, error = 0, rcode; | ||
| 7350 | |||
| 7351 | conn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); | ||
| 7352 | if (!conn) { | ||
| 7353 | fprintf(STDERR__stderrp, "SetVolumeInfo: Bind Failed"); | ||
| 7354 | ERROR_EXIT(-1)do { error = (-1); goto error_exit; } while (0); | ||
| 7355 | } | ||
| 7356 | |||
| 7357 | code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline1, &tid); | ||
| 7358 | if (code) { | ||
| 7359 | fprintf(STDERR__stderrp, "SetVolumeInfo: TransCreate Failed\n"); | ||
| 7360 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 7361 | } | ||
| 7362 | |||
| 7363 | code = AFSVolSetInfo(conn, tid, infop); | ||
| 7364 | if (code) { | ||
| 7365 | fprintf(STDERR__stderrp, "SetVolumeInfo: SetInfo Failed\n"); | ||
| 7366 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); | ||
| 7367 | } | ||
| 7368 | |||
| 7369 | error_exit: | ||
| 7370 | if (tid) { | ||
| 7371 | rcode = 0; | ||
| 7372 | code = AFSVolEndTrans(conn, tid, &rcode); | ||
| 7373 | if (code || rcode) { | ||
| 7374 | fprintf(STDERR__stderrp, "SetVolumeInfo: EndTrans Failed\n"); | ||
| 7375 | if (!error) | ||
| 7376 | error = (code ? code : rcode); | ||
| 7377 | } | ||
| 7378 | } | ||
| 7379 | |||
| 7380 | if (conn) | ||
| 7381 | rx_DestroyConnection(conn); | ||
| 7382 | return (error); | ||
| 7383 | } | ||
| 7384 | |||
| 7385 | int | ||
| 7386 | UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart, | ||
| 7387 | afs_int32 fromdate, struct volintSize *vol_size) | ||
| 7388 | { | ||
| 7389 | struct rx_connection *aconn = (struct rx_connection *)0; | ||
| 7390 | afs_int32 tid = 0, rcode = 0; | ||
| 7391 | afs_int32 code, error = 0; | ||
| 7392 | |||
| 7393 | |||
| 7394 | /* get connections to the servers */ | ||
| 7395 | aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT7005); | ||
| 7396 | |||
| 7397 | VPRINT1("Starting transaction on volume %u...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Starting transaction on volume %u..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 7398 | code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy2, &tid); | ||
| 7399 | EGOTO1(error_exit, code,do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be measured\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 7400 | "Could not start transaction on the volume %u to be measured\n",do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be measured\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0) | ||
| 7401 | afromvol)do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start transaction on the volume %u to be measured\n" )), ((afromvol))); PrintError(" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 7402 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 7403 | |||
| 7404 | VPRINT1("Getting size of volume on volume %u...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Getting size of volume on volume %u..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 7405 | code = AFSVolGetSize(aconn, tid, fromdate, vol_size); | ||
| 7406 | EGOTO(error_exit, code, "Could not start the measurement process \n")do { if (code) { do { fprintf(__stderrp, "\n"); fprintf(__stderrp , (("Could not start the measurement process \n"))); PrintError (" ",(code)); } while (0); error = (code); goto error_exit; } } while (0); | ||
| 7407 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 7408 | |||
| 7409 | error_exit: | ||
| 7410 | if (tid) { | ||
| 7411 | VPRINT1("Ending transaction on volume %u...", afromvol){ if (verbose) { fprintf(__stdoutp, ("Ending transaction on volume %u..." ), (afromvol)); fflush(__stdoutp); } }; | ||
| 7412 | code = AFSVolEndTrans(aconn, tid, &rcode); | ||
| 7413 | if (code || rcode) { | ||
| 7414 | fprintf(STDERR__stderrp, "Could not end transaction on the volume %u\n", | ||
| 7415 | afromvol); | ||
| 7416 | fprintf(STDERR__stderrp, "error codes: %d and %d\n", code, rcode); | ||
| 7417 | if (!error) | ||
| 7418 | error = (code ? code : rcode); | ||
| 7419 | } | ||
| 7420 | VDONE{ if (verbose) { fprintf(__stdoutp, " done\n"); fflush(__stdoutp ); } }; | ||
| 7421 | } | ||
| 7422 | if (aconn) | ||
| 7423 | rx_DestroyConnection(aconn); | ||
| 7424 | |||
| 7425 | PrintError("", error); | ||
| 7426 | return (error); | ||
| 7427 | } | ||
| 7428 | |||
| 7429 | /*maps the host addresses in <old > (present in network byte order) to | ||
| 7430 | that in< new> (present in host byte order )*/ | ||
| 7431 | void | ||
| 7432 | MapNetworkToHost(struct nvldbentry *old, struct nvldbentry *new) | ||
| 7433 | { | ||
| 7434 | int i, count; | ||
| 7435 | |||
| 7436 | /*copy all the fields */ | ||
| 7437 | strcpy(new->name, old->name); | ||
| 7438 | /* new->volumeType = old->volumeType;*/ | ||
| 7439 | new->nServers = old->nServers; | ||
| 7440 | count = old->nServers; | ||
| 7441 | if (count < NMAXNSERVERS13) | ||
| 7442 | count++; | ||
| 7443 | for (i = 0; i < count; i++) { | ||
| 7444 | new->serverNumber[i] = ntohl(old->serverNumber[i])(__builtin_constant_p(old->serverNumber[i]) ? ((((__uint32_t )(old->serverNumber[i])) >> 24) | ((((__uint32_t)(old ->serverNumber[i])) & (0xff << 16)) >> 8) | ((((__uint32_t)(old->serverNumber[i])) & (0xff << 8)) << 8) | (((__uint32_t)(old->serverNumber[i])) << 24)) : __bswap32_var(old->serverNumber[i])); | ||
| 7445 | new->serverPartition[i] = old->serverPartition[i]; | ||
| 7446 | new->serverFlags[i] = old->serverFlags[i]; | ||
| 7447 | } | ||
| 7448 | new->volumeId[RWVOL0] = old->volumeId[RWVOL0]; | ||
| 7449 | new->volumeId[ROVOL1] = old->volumeId[ROVOL1]; | ||
| 7450 | new->volumeId[BACKVOL2] = old->volumeId[BACKVOL2]; | ||
| 7451 | new->cloneId = old->cloneId; | ||
| 7452 | new->flags = old->flags; | ||
| 7453 | } | ||
| 7454 | |||
| 7455 | /*maps the host entries in <entry> which are present in host byte order to network byte order */ | ||
| 7456 | void | ||
| 7457 | MapHostToNetwork(struct nvldbentry *entry) | ||
| 7458 | { | ||
| 7459 | int i, count; | ||
| 7460 | |||
| 7461 | count = entry->nServers; | ||
| 7462 | if (count < NMAXNSERVERS13) | ||
| 7463 | count++; | ||
| 7464 | for (i = 0; i < count; i++) { | ||
| 7465 | entry->serverNumber[i] = htonl(entry->serverNumber[i])(__builtin_constant_p(entry->serverNumber[i]) ? ((((__uint32_t )(entry->serverNumber[i])) >> 24) | ((((__uint32_t)( entry->serverNumber[i])) & (0xff << 16)) >> 8) | ((((__uint32_t)(entry->serverNumber[i])) & (0xff << 8)) << 8) | (((__uint32_t)(entry->serverNumber [i])) << 24)) : __bswap32_var(entry->serverNumber[i] )); | ||
| 7466 | } | ||
| 7467 | } |