| File: | volser/vos.c |
| Location: | line 5600, column 5 |
| Description: | Value stored to 'vcode' is never read |
| 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 <roken.h> |
| 14 | |
| 15 | #ifdef IGNORE_SOME_GCC_WARNINGS |
| 16 | # pragma GCC diagnostic warning "-Wimplicit-function-declaration" |
| 17 | #endif |
| 18 | |
| 19 | #ifdef AFS_NT40_ENV |
| 20 | #include <WINNT/afsreg.h> |
| 21 | #endif |
| 22 | |
| 23 | #ifdef AFS_AIX_ENV |
| 24 | #include <sys/statfs.h> |
| 25 | #endif |
| 26 | |
| 27 | #include <lock.h> |
| 28 | #include <afs/stds.h> |
| 29 | #include <rx/xdr.h> |
| 30 | #include <rx/rx.h> |
| 31 | #include <rx/rx_globals.h> |
| 32 | #include <afs/nfs.h> |
| 33 | #include <afs/vlserver.h> |
| 34 | #include <afs/cellconfig.h> |
| 35 | #include <afs/keys.h> |
| 36 | #include <afs/afsutil.h> |
| 37 | #include <ubik.h> |
| 38 | #include <afs/afsint.h> |
| 39 | #include <afs/cmd.h> |
| 40 | #include <afs/usd.h> |
| 41 | #include "volser.h" |
| 42 | #include "volint.h" |
| 43 | #include <afs/ihandle.h> |
| 44 | #include <afs/vnode.h> |
| 45 | #include <afs/volume.h> |
| 46 | #include <afs/com_err.h> |
| 47 | #include "dump.h" |
| 48 | #include "lockdata.h" |
| 49 | |
| 50 | #include "volser_internal.h" |
| 51 | #include "volser_prototypes.h" |
| 52 | #include "vsutils_prototypes.h" |
| 53 | #include "lockprocs_prototypes.h" |
| 54 | |
| 55 | #ifdef HAVE_POSIX_REGEX1 |
| 56 | #include <regex.h> |
| 57 | #endif |
| 58 | |
| 59 | /* Local Prototypes */ |
| 60 | int PrintDiagnostics(char *astring, afs_int32 acode); |
| 61 | int GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, |
| 62 | afs_int32 *voltype, struct nvldbentry *rentry); |
| 63 | |
| 64 | struct tqElem { |
| 65 | afs_uint32 volid; |
| 66 | struct tqElem *next; |
| 67 | }; |
| 68 | |
| 69 | struct tqHead { |
| 70 | afs_int32 count; |
| 71 | struct tqElem *next; |
| 72 | }; |
| 73 | |
| 74 | #define COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location"); cmd_Seek(ts, 12);\ |
| 75 | cmd_AddParm(ts, "-cell", CMD_SINGLE2, CMD_OPTIONAL1, "cell name");\ |
| 76 | cmd_AddParm(ts, "-noauth", CMD_FLAG1, CMD_OPTIONAL1, "don't authenticate");\ |
| 77 | cmd_AddParm(ts, "-localauth",CMD_FLAG1,CMD_OPTIONAL1,"use server tickets");\ |
| 78 | cmd_AddParm(ts, "-verbose", CMD_FLAG1, CMD_OPTIONAL1, "verbose");\ |
| 79 | cmd_AddParm(ts, "-encrypt", CMD_FLAG1, CMD_OPTIONAL1, "encrypt commands");\ |
| 80 | cmd_AddParm(ts, "-noresolve", CMD_FLAG1, CMD_OPTIONAL1, "don't resolve addresses"); \ |
| 81 | cmd_AddParm(ts, "-config", CMD_SINGLE2, CMD_OPTIONAL1, "config location"); \ |
| 82 | |
| 83 | #define ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0) do { \ |
| 84 | error = (code); \ |
| 85 | goto error_exit; \ |
| 86 | } while (0) |
| 87 | |
| 88 | int rxInitDone = 0; |
| 89 | struct rx_connection *tconn; |
| 90 | afs_uint32 tserver; |
| 91 | extern struct ubik_client *cstruct; |
| 92 | const char *confdir; |
| 93 | |
| 94 | static struct tqHead busyHead, notokHead; |
| 95 | |
| 96 | static void |
| 97 | qInit(struct tqHead *ahead) |
| 98 | { |
| 99 | memset(ahead, 0, sizeof(struct tqHead)); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | static void |
| 105 | qPut(struct tqHead *ahead, afs_uint32 volid) |
| 106 | { |
| 107 | struct tqElem *elem; |
| 108 | |
| 109 | elem = (struct tqElem *)malloc(sizeof(struct tqElem)); |
| 110 | elem->next = ahead->next; |
| 111 | elem->volid = volid; |
| 112 | ahead->next = elem; |
| 113 | ahead->count++; |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | static void |
| 118 | qGet(struct tqHead *ahead, afs_uint32 *volid) |
| 119 | { |
| 120 | struct tqElem *tmp; |
| 121 | |
| 122 | if (ahead->count <= 0) |
| 123 | return; |
| 124 | *volid = ahead->next->volid; |
| 125 | tmp = ahead->next; |
| 126 | ahead->next = tmp->next; |
| 127 | ahead->count--; |
| 128 | free(tmp); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | /* returns 1 if <filename> exists else 0 */ |
| 133 | static int |
| 134 | FileExists(char *filename) |
| 135 | { |
| 136 | usd_handle_t ufd; |
| 137 | int code; |
| 138 | afs_int64 size; |
| 139 | |
| 140 | code = usd_Open(filename, USD_OPEN_RDONLY0, 0, &ufd); |
| 141 | if (code) { |
| 142 | return 0; |
| 143 | } |
| 144 | code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size)((*(ufd)->ioctl)(ufd, 6, &size)); |
| 145 | USD_CLOSE(ufd)((*(ufd)->close)(ufd)); |
| 146 | if (code) { |
| 147 | return 0; |
| 148 | } |
| 149 | return 1; |
| 150 | } |
| 151 | |
| 152 | /* returns 1 if <name> doesnot end in .readonly or .backup, else 0 */ |
| 153 | static int |
| 154 | VolNameOK(char *name) |
| 155 | { |
| 156 | size_t total; |
| 157 | |
| 158 | |
| 159 | total = strlen(name); |
| 160 | if (!strcmp(&name[total - 9], ".readonly")) { |
| 161 | return 0; |
| 162 | } else if (!strcmp(&name[total - 7], ".backup")) { |
| 163 | return 0; |
| 164 | } else { |
| 165 | return 1; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* return 1 if name is a number else 0 */ |
| 170 | static int |
| 171 | IsNumeric(char *name) |
| 172 | { |
| 173 | int result, i; |
| 174 | size_t len; |
| 175 | char *ptr; |
| 176 | |
| 177 | result = 1; |
| 178 | ptr = name; |
| 179 | len = strlen(name); |
| 180 | for (i = 0; i < len; i++) { |
| 181 | if (*ptr < '0' || *ptr > '9') { |
| 182 | result = 0; |
| 183 | break; |
| 184 | } |
| 185 | ptr++; |
| 186 | |
| 187 | } |
| 188 | return result; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /* |
| 193 | * Parse a server dotted address and return the address in network byte order |
| 194 | */ |
| 195 | afs_uint32 |
| 196 | GetServerNoresolve(char *aname) |
| 197 | { |
| 198 | int b1, b2, b3, b4; |
| 199 | afs_uint32 addr; |
| 200 | afs_int32 code; |
| 201 | |
| 202 | code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4); |
| 203 | if (code == 4) { |
| 204 | addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; |
| 205 | addr = htonl(addr)(__builtin_constant_p(addr) ? ((((__uint32_t)(addr)) >> 24) | ((((__uint32_t)(addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(addr)) & (0xff << 8)) << 8) | (((__uint32_t)(addr)) << 24)) : __bswap32_var(addr )); /* convert to network byte order */ |
| 206 | return addr; |
| 207 | } else |
| 208 | return 0; |
| 209 | } |
| 210 | /* |
| 211 | * Parse a server name/address and return the address in network byte order |
| 212 | */ |
| 213 | afs_uint32 |
| 214 | GetServer(char *aname) |
| 215 | { |
| 216 | struct hostent *th; |
| 217 | afs_uint32 addr; /* in network byte order */ |
| 218 | afs_int32 code; |
| 219 | char hostname[MAXHOSTCHARS64]; |
| 220 | |
| 221 | if ((addr = GetServerNoresolve(aname)) == 0) { |
| 222 | th = gethostbyname(aname); |
| 223 | if (!th) |
| 224 | return 0; |
| 225 | memcpy(&addr, th->h_addrh_addr_list[0], sizeof(addr)); |
| 226 | } |
| 227 | |
| 228 | if (rx_IsLoopbackAddr(ntohl(addr)(__builtin_constant_p(addr) ? ((((__uint32_t)(addr)) >> 24) | ((((__uint32_t)(addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(addr)) & (0xff << 8)) << 8) | (((__uint32_t)(addr)) << 24)) : __bswap32_var(addr )))) { /* local host */ |
| 229 | code = gethostname(hostname, MAXHOSTCHARS64); |
| 230 | if (code) |
| 231 | return 0; |
| 232 | th = gethostbyname(hostname); |
| 233 | if (!th) |
| 234 | return 0; |
| 235 | memcpy(&addr, th->h_addrh_addr_list[0], sizeof(addr)); |
| 236 | } |
| 237 | |
| 238 | return (addr); |
| 239 | } |
| 240 | |
| 241 | afs_int32 |
| 242 | GetVolumeType(char *aname) |
| 243 | { |
| 244 | |
| 245 | if (!strcmp(aname, "ro")) |
| 246 | return (ROVOL1); |
| 247 | else if (!strcmp(aname, "rw")) |
| 248 | return (RWVOL0); |
| 249 | else if (!strcmp(aname, "bk")) |
| 250 | return (BACKVOL2); |
| 251 | else |
| 252 | return (-1); |
| 253 | } |
| 254 | |
| 255 | int |
| 256 | IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code) |
| 257 | { |
| 258 | struct partList dummyPartList; |
| 259 | int i, success, cnt; |
| 260 | |
| 261 | success = 0; |
| 262 | *code = 0; |
| 263 | |
| 264 | *code = UV_ListPartitions(server, &dummyPartList, &cnt); |
| 265 | if (*code) |
| 266 | return success; |
| 267 | for (i = 0; i < cnt; i++) { |
| 268 | if (dummyPartList.partFlags[i] & PARTVALID0x01) |
| 269 | if (dummyPartList.partId[i] == partId) |
| 270 | success = 1; |
| 271 | } |
| 272 | return success; |
| 273 | } |
| 274 | |
| 275 | |
| 276 | |
| 277 | /*sends the contents of file associated with <fd> and <blksize> to Rx Stream |
| 278 | * associated with <call> */ |
| 279 | int |
| 280 | SendFile(usd_handle_t ufd, struct rx_call *call, long blksize) |
| 281 | { |
| 282 | char *buffer = (char *)0; |
| 283 | afs_int32 error = 0; |
| 284 | int done = 0; |
| 285 | afs_uint32 nbytes; |
| 286 | |
| 287 | buffer = (char *)malloc(blksize); |
| 288 | if (!buffer) { |
| 289 | fprintf(STDERR__stderrp, "malloc failed\n"); |
| 290 | return -1; |
| 291 | } |
| 292 | |
| 293 | while (!error && !done) { |
| 294 | #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */ |
| 295 | fd_set in; |
| 296 | FD_ZERO(&in)do { fd_set *_p; __size_t _n; _p = (&in); _n = (((1024U) + (((sizeof(__fd_mask) * 8)) - 1)) / ((sizeof(__fd_mask) * 8)) ); while (_n > 0) _p->__fds_bits[--_n] = 0; } while (0); |
| 297 | FD_SET((intptr_t)(ufd->handle), &in)((&in)->__fds_bits[((intptr_t)(ufd->handle))/(sizeof (__fd_mask) * 8)] |= ((__fd_mask)1 << (((intptr_t)(ufd-> handle)) % (sizeof(__fd_mask) * 8)))); |
| 298 | /* don't timeout if read blocks */ |
| 299 | #if defined(AFS_PTHREAD_ENV) |
| 300 | select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0); |
| 301 | #else |
| 302 | IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0); |
| 303 | #endif |
| 304 | #endif |
| 305 | error = USD_READ(ufd, buffer, blksize, &nbytes)((*(ufd)->read)(ufd, buffer, blksize, &nbytes)); |
| 306 | if (error) { |
| 307 | fprintf(STDERR__stderrp, "File system read failed: %s\n", |
| 308 | afs_error_message(error)); |
| 309 | break; |
| 310 | } |
| 311 | if (nbytes == 0) { |
| 312 | done = 1; |
| 313 | break; |
| 314 | } |
| 315 | if (rx_Write(call, buffer, nbytes)rx_WriteProc(call, buffer, nbytes) != nbytes) { |
| 316 | error = -1; |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | if (buffer) |
| 321 | free(buffer); |
| 322 | return error; |
| 323 | } |
| 324 | |
| 325 | /* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and |
| 326 | * writes it out to the volume. */ |
| 327 | afs_int32 |
| 328 | WriteData(struct rx_call *call, void *rock) |
| 329 | { |
| 330 | char *filename = (char *) rock; |
| 331 | usd_handle_t ufd; |
| 332 | long blksize; |
| 333 | afs_int32 error, code; |
| 334 | int ufdIsOpen = 0; |
| 335 | afs_int64 currOffset; |
| 336 | afs_uint32 buffer; |
| 337 | afs_uint32 got; |
| 338 | |
| 339 | error = 0; |
| 340 | |
| 341 | if (!filename || !*filename) { |
| 342 | usd_StandardInput(&ufd); |
| 343 | blksize = 4096; |
| 344 | ufdIsOpen = 1; |
| 345 | } else { |
| 346 | code = usd_Open(filename, USD_OPEN_RDONLY0, 0, &ufd); |
| 347 | if (code == 0) { |
| 348 | ufdIsOpen = 1; |
| 349 | code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize)((*(ufd)->ioctl)(ufd, 9, &blksize)); |
| 350 | } |
| 351 | if (code) { |
| 352 | fprintf(STDERR__stderrp, "Could not access file '%s': %s\n", filename, |
| 353 | afs_error_message(code)); |
| 354 | error = VOLSERBADOP(1492325131L); |
| 355 | goto wfail; |
| 356 | } |
| 357 | /* test if we have a valid dump */ |
| 358 | USD_SEEK(ufd, 0, SEEK_END, &currOffset)((*(ufd)->seek)(ufd, 0, 2, &currOffset)); |
| 359 | USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset)((*(ufd)->seek)(ufd, currOffset - sizeof(afs_uint32), 0, & currOffset)); |
| 360 | USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got)((*(ufd)->read)(ufd, (char *)&buffer, sizeof(afs_uint32 ), &got)); |
| 361 | if ((got != sizeof(afs_uint32)) || (ntohl(buffer)(__builtin_constant_p(buffer) ? ((((__uint32_t)(buffer)) >> 24) | ((((__uint32_t)(buffer)) & (0xff << 16)) >> 8) | ((((__uint32_t)(buffer)) & (0xff << 8)) << 8) | (((__uint32_t)(buffer)) << 24)) : __bswap32_var(buffer )) != DUMPENDMAGIC0x3A214B6E)) { |
| 362 | fprintf(STDERR__stderrp, "Signature missing from end of file '%s'\n", filename); |
| 363 | error = VOLSERBADOP(1492325131L); |
| 364 | goto wfail; |
| 365 | } |
| 366 | USD_SEEK(ufd, 0, SEEK_SET, &currOffset)((*(ufd)->seek)(ufd, 0, 0, &currOffset)); |
| 367 | } |
| 368 | code = SendFile(ufd, call, blksize); |
| 369 | if (code) { |
| 370 | error = code; |
| 371 | goto wfail; |
| 372 | } |
| 373 | wfail: |
| 374 | if (ufdIsOpen) { |
| 375 | code = USD_CLOSE(ufd)((*(ufd)->close)(ufd)); |
| 376 | if (code) { |
| 377 | fprintf(STDERR__stderrp, "Could not close dump file %s\n", |
| 378 | (filename && *filename) ? filename : "STDOUT"); |
| 379 | if (!error) |
| 380 | error = code; |
| 381 | } |
| 382 | } |
| 383 | return error; |
| 384 | } |
| 385 | |
| 386 | /* Receive data from <call> stream into file associated |
| 387 | * with <fd> <blksize> |
| 388 | */ |
| 389 | int |
| 390 | ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize) |
| 391 | { |
| 392 | char *buffer = NULL((void *)0); |
| 393 | afs_int32 bytesread; |
| 394 | afs_uint32 bytesleft, w; |
| 395 | afs_int32 error = 0; |
| 396 | |
| 397 | buffer = (char *)malloc(blksize); |
| 398 | if (!buffer) { |
| 399 | fprintf(STDERR__stderrp, "memory allocation failed\n"); |
| 400 | ERROR_EXIT(-1)do { error = (-1); goto error_exit; } while (0); |
| 401 | } |
| 402 | |
| 403 | while ((bytesread = rx_Read(call, buffer, blksize)rx_ReadProc(call, buffer, blksize)) > 0) { |
| 404 | for (bytesleft = bytesread; bytesleft; bytesleft -= w) { |
| 405 | #ifndef AFS_NT40_ENV /* NT csn't select on non-socket fd's */ |
| 406 | fd_set out; |
| 407 | FD_ZERO(&out)do { fd_set *_p; __size_t _n; _p = (&out); _n = (((1024U) + (((sizeof(__fd_mask) * 8)) - 1)) / ((sizeof(__fd_mask) * 8 ))); while (_n > 0) _p->__fds_bits[--_n] = 0; } while ( 0); |
| 408 | FD_SET((intptr_t)(ufd->handle), &out)((&out)->__fds_bits[((intptr_t)(ufd->handle))/(sizeof (__fd_mask) * 8)] |= ((__fd_mask)1 << (((intptr_t)(ufd-> handle)) % (sizeof(__fd_mask) * 8)))); |
| 409 | /* don't timeout if write blocks */ |
| 410 | #if defined(AFS_PTHREAD_ENV) |
| 411 | select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0); |
| 412 | #else |
| 413 | IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0); |
| 414 | #endif |
| 415 | #endif |
| 416 | error = |
| 417 | USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w)((*(ufd)->write)(ufd, &buffer[bytesread - bytesleft], bytesleft , &w)); |
| 418 | if (error) { |
| 419 | fprintf(STDERR__stderrp, "File system write failed: %s\n", |
| 420 | afs_error_message(error)); |
| 421 | ERROR_EXIT(-1)do { error = (-1); goto error_exit; } while (0); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | error_exit: |
| 427 | if (buffer) |
| 428 | free(buffer); |
| 429 | return (error); |
| 430 | } |
| 431 | |
| 432 | afs_int32 |
| 433 | DumpFunction(struct rx_call *call, void *rock) |
| 434 | { |
| 435 | char *filename = (char *)rock; |
| 436 | usd_handle_t ufd; /* default is to stdout */ |
| 437 | afs_int32 error = 0, code; |
| 438 | afs_int64 size; |
| 439 | long blksize; |
| 440 | int ufdIsOpen = 0; |
| 441 | |
| 442 | /* Open the output file */ |
| 443 | if (!filename || !*filename) { |
| 444 | usd_StandardOutput(&ufd); |
| 445 | blksize = 4096; |
| 446 | ufdIsOpen = 1; |
| 447 | } else { |
| 448 | code = |
| 449 | usd_Open(filename, USD_OPEN_CREATE0x10 | USD_OPEN_RDWR1, 0666, &ufd); |
| 450 | if (code == 0) { |
| 451 | ufdIsOpen = 1; |
| 452 | size = 0; |
| 453 | code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size)((*(ufd)->ioctl)(ufd, 7, &size)); |
| 454 | } |
| 455 | if (code == 0) { |
| 456 | code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize)((*(ufd)->ioctl)(ufd, 9, &blksize)); |
| 457 | } |
| 458 | if (code) { |
| 459 | fprintf(STDERR__stderrp, "Could not create file '%s': %s\n", filename, |
| 460 | afs_error_message(code)); |
| 461 | ERROR_EXIT(VOLSERBADOP)do { error = ((1492325131L)); goto error_exit; } while (0); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | code = ReceiveFile(ufd, call, blksize); |
| 466 | if (code) |
| 467 | ERROR_EXIT(code)do { error = (code); goto error_exit; } while (0); |
| 468 | |
| 469 | error_exit: |
| 470 | /* Close the output file */ |
| 471 | if (ufdIsOpen) { |
| 472 | code = USD_CLOSE(ufd)((*(ufd)->close)(ufd)); |
| 473 | if (code) { |
| 474 | fprintf(STDERR__stderrp, "Could not close dump file %s\n", |
| 475 | (filename && *filename) ? filename : "STDIN"); |
| 476 | if (!error) |
| 477 | error = code; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | return (error); |
| 482 | } |
| 483 | |
| 484 | static void |
| 485 | DisplayFormat(volintInfo *pntr, afs_uint32 server, afs_int32 part, |
| 486 | int *totalOK, int *totalNotOK, int *totalBusy, int fast, |
| 487 | int longlist, int disp) |
| 488 | { |
| 489 | char pname[10]; |
| 490 | time_t t; |
| 491 | |
| 492 | if (fast) { |
| 493 | fprintf(STDOUT__stdoutp, "%-10lu\n", (unsigned long)pntr->volid); |
| 494 | } else if (longlist) { |
| 495 | if (pntr->status == VOK0x02) { |
| 496 | fprintf(STDOUT__stdoutp, "%-32s ", pntr->name); |
| 497 | fprintf(STDOUT__stdoutp, "%10lu ", (unsigned long)pntr->volid); |
| 498 | if (pntr->type == 0) |
| 499 | fprintf(STDOUT__stdoutp, "RW "); |
| 500 | if (pntr->type == 1) |
| 501 | fprintf(STDOUT__stdoutp, "RO "); |
| 502 | if (pntr->type == 2) |
| 503 | fprintf(STDOUT__stdoutp, "BK "); |
| 504 | fprintf(STDOUT__stdoutp, "%10d K ", pntr->size); |
| 505 | if (pntr->inUse == 1) { |
| 506 | fprintf(STDOUT__stdoutp, "On-line"); |
| 507 | *totalOK += 1; |
| 508 | } else { |
| 509 | fprintf(STDOUT__stdoutp, "Off-line"); |
| 510 | *totalNotOK += 1; |
| 511 | } |
| 512 | if (pntr->needsSalvaged == 1) |
| 513 | fprintf(STDOUT__stdoutp, "**needs salvage**"); |
| 514 | fprintf(STDOUT__stdoutp, "\n"); |
| 515 | MapPartIdIntoName(part, pname); |
| 516 | fprintf(STDOUT__stdoutp, " %s %s \n", hostutil_GetNameByINet(server), |
| 517 | pname); |
| 518 | fprintf(STDOUT__stdoutp, " RWrite %10lu ROnly %10lu Backup %10lu \n", |
| 519 | (unsigned long)pntr->parentID, |
| 520 | (unsigned long)pntr->cloneID, |
| 521 | (unsigned long)pntr->backupID); |
| 522 | fprintf(STDOUT__stdoutp, " MaxQuota %10d K \n", pntr->maxquota); |
| 523 | t = pntr->creationDate; |
| 524 | fprintf(STDOUT__stdoutp, " Creation %s", |
| 525 | ctime(&t)); |
| 526 | t = pntr->copyDate; |
| 527 | fprintf(STDOUT__stdoutp, " Copy %s", |
| 528 | ctime(&t)); |
| 529 | |
| 530 | t = pntr->backupDate; |
| 531 | if (!t) |
| 532 | fprintf(STDOUT__stdoutp, " Backup Never\n"); |
| 533 | else |
| 534 | fprintf(STDOUT__stdoutp, " Backup %s", |
| 535 | ctime(&t)); |
| 536 | |
| 537 | t = pntr->accessDate; |
| 538 | if (t) |
| 539 | fprintf(STDOUT__stdoutp, " Last Access %s", |
| 540 | ctime(&t)); |
| 541 | |
| 542 | t = pntr->updateDate; |
| 543 | if (!t) |
| 544 | fprintf(STDOUT__stdoutp, " Last Update Never\n"); |
| 545 | else |
| 546 | fprintf(STDOUT__stdoutp, " Last Update %s", |
| 547 | ctime(&t)); |
| 548 | fprintf(STDOUT__stdoutp, |
| 549 | " %d accesses in the past day (i.e., vnode references)\n", |
| 550 | pntr->dayUse); |
| 551 | } else if (pntr->status == VBUSY110) { |
| 552 | *totalBusy += 1; |
| 553 | qPut(&busyHead, pntr->volid); |
| 554 | if (disp) |
| 555 | fprintf(STDOUT__stdoutp, "**** Volume %lu is busy ****\n", |
| 556 | (unsigned long)pntr->volid); |
| 557 | } else { |
| 558 | *totalNotOK += 1; |
| 559 | qPut(¬okHead, pntr->volid); |
| 560 | if (disp) |
| 561 | fprintf(STDOUT__stdoutp, "**** Could not attach volume %lu ****\n", |
| 562 | (unsigned long)pntr->volid); |
| 563 | } |
| 564 | fprintf(STDOUT__stdoutp, "\n"); |
| 565 | } else { /* default listing */ |
| 566 | if (pntr->status == VOK0x02) { |
| 567 | fprintf(STDOUT__stdoutp, "%-32s ", pntr->name); |
| 568 | fprintf(STDOUT__stdoutp, "%10lu ", (unsigned long)pntr->volid); |
| 569 | if (pntr->type == 0) |
| 570 | fprintf(STDOUT__stdoutp, "RW "); |
| 571 | if (pntr->type == 1) |
| 572 | fprintf(STDOUT__stdoutp, "RO "); |
| 573 | if (pntr->type == 2) |
| 574 | fprintf(STDOUT__stdoutp, "BK "); |
| 575 | fprintf(STDOUT__stdoutp, "%10d K ", pntr->size); |
| 576 | if (pntr->inUse == 1) { |
| 577 | fprintf(STDOUT__stdoutp, "On-line"); |
| 578 | *totalOK += 1; |
| 579 | } else { |
| 580 | fprintf(STDOUT__stdoutp, "Off-line"); |
| 581 | *totalNotOK += 1; |
| 582 | } |
| 583 | if (pntr->needsSalvaged == 1) |
| 584 | fprintf(STDOUT__stdoutp, "**needs salvage**"); |
| 585 | fprintf(STDOUT__stdoutp, "\n"); |
| 586 | } else if (pntr->status == VBUSY110) { |
| 587 | *totalBusy += 1; |
| 588 | qPut(&busyHead, pntr->volid); |
| 589 | if (disp) |
| 590 | fprintf(STDOUT__stdoutp, "**** Volume %lu is busy ****\n", |
| 591 | (unsigned long)pntr->volid); |
| 592 | } else { |
| 593 | *totalNotOK += 1; |
| 594 | qPut(¬okHead, pntr->volid); |
| 595 | if (disp) |
| 596 | fprintf(STDOUT__stdoutp, "**** Could not attach volume %lu ****\n", |
| 597 | (unsigned long)pntr->volid); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | /*------------------------------------------------------------------------ |
| 603 | * PRIVATE XDisplayFormat |
| 604 | * |
| 605 | * Description: |
| 606 | * Display the contents of one extended volume info structure. |
| 607 | * |
| 608 | * Arguments: |
| 609 | * a_xInfoP : Ptr to extended volume info struct to print. |
| 610 | * a_servID : Server ID to print. |
| 611 | * a_partID : Partition ID to print. |
| 612 | * a_totalOKP : Ptr to total-OK counter. |
| 613 | * a_totalNotOKP : Ptr to total-screwed counter. |
| 614 | * a_totalBusyP : Ptr to total-busy counter. |
| 615 | * a_fast : Fast listing? |
| 616 | * a_int32 : Int32 listing? |
| 617 | * a_showProblems : Show volume problems? |
| 618 | * |
| 619 | * Returns: |
| 620 | * Nothing. |
| 621 | * |
| 622 | * Environment: |
| 623 | * Nothing interesting. |
| 624 | * |
| 625 | * Side Effects: |
| 626 | * As advertised. |
| 627 | *------------------------------------------------------------------------*/ |
| 628 | |
| 629 | static void |
| 630 | XDisplayFormat(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID, |
| 631 | int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP, |
| 632 | int a_fast, int a_int32, int a_showProblems) |
| 633 | { /*XDisplayFormat */ |
| 634 | time_t t; |
| 635 | char pname[10]; |
| 636 | |
| 637 | if (a_fast) { |
| 638 | /* |
| 639 | * Short & sweet. |
| 640 | */ |
| 641 | fprintf(STDOUT__stdoutp, "%-10lu\n", (unsigned long)a_xInfoP->volid); |
| 642 | } else if (a_int32) { |
| 643 | /* |
| 644 | * Fully-detailed listing. |
| 645 | */ |
| 646 | if (a_xInfoP->status == VOK0x02) { |
| 647 | /* |
| 648 | * Volume's status is OK - all the fields are valid. |
| 649 | */ |
| 650 | fprintf(STDOUT__stdoutp, "%-32s ", a_xInfoP->name); |
| 651 | fprintf(STDOUT__stdoutp, "%10lu ", (unsigned long)a_xInfoP->volid); |
| 652 | if (a_xInfoP->type == 0) |
| 653 | fprintf(STDOUT__stdoutp, "RW "); |
| 654 | if (a_xInfoP->type == 1) |
| 655 | fprintf(STDOUT__stdoutp, "RO "); |
| 656 | if (a_xInfoP->type == 2) |
| 657 | fprintf(STDOUT__stdoutp, "BK "); |
| 658 | fprintf(STDOUT__stdoutp, "%10d K used ", a_xInfoP->size); |
| 659 | fprintf(STDOUT__stdoutp, "%d files ", a_xInfoP->filecount); |
| 660 | if (a_xInfoP->inUse == 1) { |
| 661 | fprintf(STDOUT__stdoutp, "On-line"); |
| 662 | (*a_totalOKP)++; |
| 663 | } else { |
| 664 | fprintf(STDOUT__stdoutp, "Off-line"); |
| 665 | (*a_totalNotOKP)++; |
| 666 | } |
| 667 | fprintf(STDOUT__stdoutp, "\n"); |
| 668 | MapPartIdIntoName(a_partID, pname); |
| 669 | fprintf(STDOUT__stdoutp, " %s %s \n", hostutil_GetNameByINet(a_servID), |
| 670 | pname); |
| 671 | fprintf(STDOUT__stdoutp, " RWrite %10lu ROnly %10lu Backup %10lu \n", |
| 672 | (unsigned long)a_xInfoP->parentID, |
| 673 | (unsigned long)a_xInfoP->cloneID, |
| 674 | (unsigned long)a_xInfoP->backupID); |
| 675 | fprintf(STDOUT__stdoutp, " MaxQuota %10d K \n", a_xInfoP->maxquota); |
| 676 | |
| 677 | t = a_xInfoP->creationDate; |
| 678 | fprintf(STDOUT__stdoutp, " Creation %s", |
| 679 | ctime(&t)); |
| 680 | |
| 681 | t = a_xInfoP->copyDate; |
| 682 | fprintf(STDOUT__stdoutp, " Copy %s", |
| 683 | ctime(&t)); |
| 684 | |
| 685 | t = a_xInfoP->backupDate; |
| 686 | if (!t) |
| 687 | fprintf(STDOUT__stdoutp, " Backup Never\n"); |
| 688 | else |
| 689 | fprintf(STDOUT__stdoutp, " Backup %s", |
| 690 | ctime(&t)); |
| 691 | |
| 692 | t = a_xInfoP->accessDate; |
| 693 | if (t) |
| 694 | fprintf(STDOUT__stdoutp, " Last Access %s", |
| 695 | ctime(&t)); |
| 696 | |
| 697 | t = a_xInfoP->updateDate; |
| 698 | if (!t) |
| 699 | fprintf(STDOUT__stdoutp, " Last Update Never\n"); |
| 700 | else |
| 701 | fprintf(STDOUT__stdoutp, " Last Update %s", |
| 702 | ctime(&t)); |
| 703 | fprintf(STDOUT__stdoutp, |
| 704 | " %d accesses in the past day (i.e., vnode references)\n", |
| 705 | a_xInfoP->dayUse); |
| 706 | |
| 707 | /* |
| 708 | * Print all the read/write and authorship stats. |
| 709 | */ |
| 710 | fprintf(STDOUT__stdoutp, "\n Raw Read/Write Stats\n"); |
| 711 | fprintf(STDOUT__stdoutp, |
| 712 | " |-------------------------------------------|\n"); |
| 713 | fprintf(STDOUT__stdoutp, |
| 714 | " | Same Network | Diff Network |\n"); |
| 715 | fprintf(STDOUT__stdoutp, |
| 716 | " |----------|----------|----------|----------|\n"); |
| 717 | fprintf(STDOUT__stdoutp, |
| 718 | " | Total | Auth | Total | Auth |\n"); |
| 719 | fprintf(STDOUT__stdoutp, |
| 720 | " |----------|----------|----------|----------|\n"); |
| 721 | fprintf(STDOUT__stdoutp, "Reads | %8d | %8d | %8d | %8d |\n", |
| 722 | a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET0], |
| 723 | a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH1], |
| 724 | a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET2], |
| 725 | a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH3]); |
| 726 | fprintf(STDOUT__stdoutp, "Writes | %8d | %8d | %8d | %8d |\n", |
| 727 | a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET0], |
| 728 | a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH1], |
| 729 | a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET2], |
| 730 | a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH3]); |
| 731 | fprintf(STDOUT__stdoutp, |
| 732 | " |-------------------------------------------|\n\n"); |
| 733 | |
| 734 | fprintf(STDOUT__stdoutp, |
| 735 | " Writes Affecting Authorship\n"); |
| 736 | fprintf(STDOUT__stdoutp, |
| 737 | " |-------------------------------------------|\n"); |
| 738 | fprintf(STDOUT__stdoutp, |
| 739 | " | File Authorship | Directory Authorship|\n"); |
| 740 | fprintf(STDOUT__stdoutp, |
| 741 | " |----------|----------|----------|----------|\n"); |
| 742 | fprintf(STDOUT__stdoutp, |
| 743 | " | Same | Diff | Same | Diff |\n"); |
| 744 | fprintf(STDOUT__stdoutp, |
| 745 | " |----------|----------|----------|----------|\n"); |
| 746 | fprintf(STDOUT__stdoutp, "0-60 sec | %8d | %8d | %8d | %8d |\n", |
| 747 | a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_00], |
| 748 | a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_00], |
| 749 | a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_00], |
| 750 | a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_00]); |
| 751 | fprintf(STDOUT__stdoutp, "1-10 min | %8d | %8d | %8d | %8d |\n", |
| 752 | a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_11], |
| 753 | a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_11], |
| 754 | a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_11], |
| 755 | a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_11]); |
| 756 | fprintf(STDOUT__stdoutp, "10min-1hr | %8d | %8d | %8d | %8d |\n", |
| 757 | a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_22], |
| 758 | a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_22], |
| 759 | a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_22], |
| 760 | a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_22]); |
| 761 | fprintf(STDOUT__stdoutp, "1hr-1day | %8d | %8d | %8d | %8d |\n", |
| 762 | a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_33], |
| 763 | a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_33], |
| 764 | a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_33], |
| 765 | a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_33]); |
| 766 | fprintf(STDOUT__stdoutp, "1day-1wk | %8d | %8d | %8d | %8d |\n", |
| 767 | a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_44], |
| 768 | a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_44], |
| 769 | a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_44], |
| 770 | a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_44]); |
| 771 | fprintf(STDOUT__stdoutp, "> 1wk | %8d | %8d | %8d | %8d |\n", |
| 772 | a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_55], |
| 773 | a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_55], |
| 774 | a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_55], |
| 775 | a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_55]); |
| 776 | fprintf(STDOUT__stdoutp, |
| 777 | " |-------------------------------------------|\n"); |
| 778 | } /*Volume status OK */ |
| 779 | else if (a_xInfoP->status == VBUSY110) { |
| 780 | (*a_totalBusyP)++; |
| 781 | qPut(&busyHead, a_xInfoP->volid); |
| 782 | if (a_showProblems) |
| 783 | fprintf(STDOUT__stdoutp, "**** Volume %lu is busy ****\n", |
| 784 | (unsigned long)a_xInfoP->volid); |
| 785 | } /*Busy volume */ |
| 786 | else { |
| 787 | (*a_totalNotOKP)++; |
| 788 | qPut(¬okHead, a_xInfoP->volid); |
| 789 | if (a_showProblems) |
| 790 | fprintf(STDOUT__stdoutp, "**** Could not attach volume %lu ****\n", |
| 791 | (unsigned long)a_xInfoP->volid); |
| 792 | } /*Screwed volume */ |
| 793 | fprintf(STDOUT__stdoutp, "\n"); |
| 794 | } /*Long listing */ |
| 795 | else { |
| 796 | /* |
| 797 | * Default listing. |
| 798 | */ |
| 799 | if (a_xInfoP->status == VOK0x02) { |
| 800 | fprintf(STDOUT__stdoutp, "%-32s ", a_xInfoP->name); |
| 801 | fprintf(STDOUT__stdoutp, "%10lu ", (unsigned long)a_xInfoP->volid); |
| 802 | if (a_xInfoP->type == 0) |
| 803 | fprintf(STDOUT__stdoutp, "RW "); |
| 804 | if (a_xInfoP->type == 1) |
| 805 | fprintf(STDOUT__stdoutp, "RO "); |
| 806 | if (a_xInfoP->type == 2) |
| 807 | fprintf(STDOUT__stdoutp, "BK "); |
| 808 | fprintf(STDOUT__stdoutp, "%10d K ", a_xInfoP->size); |
| 809 | if (a_xInfoP->inUse == 1) { |
| 810 | fprintf(STDOUT__stdoutp, "On-line"); |
| 811 | (*a_totalOKP)++; |
| 812 | } else { |
| 813 | fprintf(STDOUT__stdoutp, "Off-line"); |
| 814 | (*a_totalNotOKP)++; |
| 815 | } |
| 816 | fprintf(STDOUT__stdoutp, "\n"); |
| 817 | } /*Volume OK */ |
| 818 | else if (a_xInfoP->status == VBUSY110) { |
| 819 | (*a_totalBusyP)++; |
| 820 | qPut(&busyHead, a_xInfoP->volid); |
| 821 | if (a_showProblems) |
| 822 | fprintf(STDOUT__stdoutp, "**** Volume %lu is busy ****\n", |
| 823 | (unsigned long)a_xInfoP->volid); |
| 824 | } /*Busy volume */ |
| 825 | else { |
| 826 | (*a_totalNotOKP)++; |
| 827 | qPut(¬okHead, a_xInfoP->volid); |
| 828 | if (a_showProblems) |
| 829 | fprintf(STDOUT__stdoutp, "**** Could not attach volume %lu ****\n", |
| 830 | (unsigned long)a_xInfoP->volid); |
| 831 | } /*Screwed volume */ |
| 832 | } /*Default listing */ |
| 833 | } /*XDisplayFormat */ |
| 834 | |
| 835 | /*------------------------------------------------------------------------ |
| 836 | * PRIVATE XDisplayFormat2 |
| 837 | * |
| 838 | * Description: |
| 839 | * Display the formated contents of one extended volume info structure. |
| 840 | * |
| 841 | * Arguments: |
| 842 | * a_xInfoP : Ptr to extended volume info struct to print. |
| 843 | * a_servID : Server ID to print. |
| 844 | * a_partID : Partition ID to print. |
| 845 | * a_totalOKP : Ptr to total-OK counter. |
| 846 | * a_totalNotOKP : Ptr to total-screwed counter. |
| 847 | * a_totalBusyP : Ptr to total-busy counter. |
| 848 | * a_fast : Fast listing? |
| 849 | * a_int32 : Int32 listing? |
| 850 | * a_showProblems : Show volume problems? |
| 851 | * |
| 852 | * Returns: |
| 853 | * Nothing. |
| 854 | * |
| 855 | * Environment: |
| 856 | * Nothing interesting. |
| 857 | * |
| 858 | * Side Effects: |
| 859 | * As advertised. |
| 860 | *------------------------------------------------------------------------*/ |
| 861 | |
| 862 | static void |
| 863 | XDisplayFormat2(volintXInfo *a_xInfoP, afs_uint32 a_servID, afs_int32 a_partID, |
| 864 | int *a_totalOKP, int *a_totalNotOKP, int *a_totalBusyP, |
| 865 | int a_fast, int a_int32, int a_showProblems) |
| 866 | { /*XDisplayFormat */ |
| 867 | time_t t; |
| 868 | if (a_fast) { |
| 869 | /* |
| 870 | * Short & sweet. |
| 871 | */ |
| 872 | fprintf(STDOUT__stdoutp, "vold_id\t%-10lu\n", (unsigned long)a_xInfoP->volid); |
| 873 | } else if (a_int32) { |
| 874 | /* |
| 875 | * Fully-detailed listing. |
| 876 | */ |
| 877 | if (a_xInfoP->status == VOK0x02) { |
| 878 | /* |
| 879 | * Volume's status is OK - all the fields are valid. |
| 880 | */ |
| 881 | |
| 882 | static long server_cache = -1, partition_cache = -1; |
| 883 | static char hostname[256], address[32], pname[16]; |
| 884 | int i,ai[] = {VOLINT_STATS_TIME_IDX_00,VOLINT_STATS_TIME_IDX_11,VOLINT_STATS_TIME_IDX_22, |
| 885 | VOLINT_STATS_TIME_IDX_33,VOLINT_STATS_TIME_IDX_44,VOLINT_STATS_TIME_IDX_55}; |
| 886 | |
| 887 | if (a_servID != server_cache) { |
| 888 | struct in_addr s; |
| 889 | |
| 890 | s.s_addr = a_servID; |
| 891 | strcpy(hostname, hostutil_GetNameByINet(a_servID)); |
| 892 | strcpy(address, inet_ntoa__inet_ntoa(s)); |
| 893 | server_cache = a_servID; |
| 894 | } |
| 895 | if (a_partID != partition_cache) { |
| 896 | MapPartIdIntoName(a_partID, pname); |
| 897 | partition_cache = a_partID; |
| 898 | } |
| 899 | |
| 900 | fprintf(STDOUT__stdoutp, "name\t\t%s\n", a_xInfoP->name); |
| 901 | fprintf(STDOUT__stdoutp, "id\t\t%lu\n", afs_printable_uint32_lu(a_xInfoP->volid)); |
| 902 | fprintf(STDOUT__stdoutp, "serv\t\t%s\t%s\n", address, hostname); |
| 903 | fprintf(STDOUT__stdoutp, "part\t\t%s\n", pname); |
| 904 | fprintf(STDOUT__stdoutp, "status\t\tOK\n"); |
| 905 | fprintf(STDOUT__stdoutp, "backupID\t%lu\n", |
| 906 | afs_printable_uint32_lu(a_xInfoP->backupID)); |
| 907 | fprintf(STDOUT__stdoutp, "parentID\t%lu\n", |
| 908 | afs_printable_uint32_lu(a_xInfoP->parentID)); |
| 909 | fprintf(STDOUT__stdoutp, "cloneID\t\t%lu\n", |
| 910 | afs_printable_uint32_lu(a_xInfoP->cloneID)); |
| 911 | fprintf(STDOUT__stdoutp, "inUse\t\t%s\n", a_xInfoP->inUse ? "Y" : "N"); |
| 912 | switch (a_xInfoP->type) { |
| 913 | case 0: |
| 914 | fprintf(STDOUT__stdoutp, "type\t\tRW\n"); |
| 915 | break; |
| 916 | case 1: |
| 917 | fprintf(STDOUT__stdoutp, "type\t\tRO\n"); |
| 918 | break; |
| 919 | case 2: |
| 920 | fprintf(STDOUT__stdoutp, "type\t\tBK\n"); |
| 921 | break; |
| 922 | default: |
| 923 | fprintf(STDOUT__stdoutp, "type\t\t?\n"); |
| 924 | break; |
| 925 | } |
| 926 | t = a_xInfoP->creationDate; |
| 927 | fprintf(STDOUT__stdoutp, "creationDate\t%-9lu\t%s", |
| 928 | afs_printable_uint32_lu(a_xInfoP->creationDate), |
| 929 | ctime(&t)); |
| 930 | |
| 931 | t = a_xInfoP->accessDate; |
| 932 | fprintf(STDOUT__stdoutp, "accessDate\t%-9lu\t%s", |
| 933 | afs_printable_uint32_lu(a_xInfoP->accessDate), |
| 934 | ctime(&t)); |
| 935 | |
| 936 | t = a_xInfoP->updateDate; |
| 937 | fprintf(STDOUT__stdoutp, "updateDate\t%-9lu\t%s", |
| 938 | afs_printable_uint32_lu(a_xInfoP->updateDate), |
| 939 | ctime(&t)); |
| 940 | |
| 941 | t = a_xInfoP->backupDate; |
| 942 | fprintf(STDOUT__stdoutp, "backupDate\t%-9lu\t%s", |
| 943 | afs_printable_uint32_lu(a_xInfoP->backupDate), |
| 944 | ctime(&t)); |
| 945 | |
| 946 | t = a_xInfoP->copyDate; |
| 947 | fprintf(STDOUT__stdoutp, "copyDate\t%-9lu\t%s", |
| 948 | afs_printable_uint32_lu(a_xInfoP->copyDate), |
| 949 | ctime(&t)); |
| 950 | |
| 951 | fprintf(STDOUT__stdoutp, "diskused\t%u\n", a_xInfoP->size); |
| 952 | fprintf(STDOUT__stdoutp, "maxquota\t%u\n", a_xInfoP->maxquota); |
| 953 | |
| 954 | fprintf(STDOUT__stdoutp, "filecount\t%u\n", a_xInfoP->filecount); |
| 955 | fprintf(STDOUT__stdoutp, "dayUse\t\t%u\n", a_xInfoP->dayUse); |
| 956 | |
| 957 | |
| 958 | |
| 959 | fprintf(STDOUT__stdoutp,"reads_same_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET0]); |
| 960 | fprintf(STDOUT__stdoutp,"reads_same_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH1]); |
| 961 | fprintf(STDOUT__stdoutp,"reads_diff_net\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET2]); |
| 962 | fprintf(STDOUT__stdoutp,"reads_diff_net_auth\t%8d\n",a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH3]); |
| 963 | |
| 964 | fprintf(STDOUT__stdoutp,"writes_same_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET0]); |
| 965 | fprintf(STDOUT__stdoutp,"writes_same_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH1]); |
| 966 | fprintf(STDOUT__stdoutp,"writes_diff_net\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET2]); |
| 967 | fprintf(STDOUT__stdoutp,"writes_diff_net_auth\t%8d\n",a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH3]); |
| 968 | |
| 969 | for(i=0;i<5;i++) |
| 970 | { |
| 971 | fprintf(STDOUT__stdoutp,"file_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileSameAuthor[ai[i]]); |
| 972 | fprintf(STDOUT__stdoutp,"file_diff_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_fileDiffAuthor[ai[i]]); |
| 973 | fprintf(STDOUT__stdoutp,"dir_same_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirSameAuthor[ai[i]]); |
| 974 | fprintf(STDOUT__stdoutp,"dir_dif_author_idx_%d\t%8d\n",i+1,a_xInfoP->stat_dirDiffAuthor[ai[i]]); |
| 975 | } |
| 976 | |
| 977 | } /*Volume status OK */ |
| 978 | else if (a_xInfoP->status == VBUSY110) { |
| 979 | (*a_totalBusyP)++; |
| 980 | qPut(&busyHead, a_xInfoP->volid); |
| 981 | if (a_showProblems) |
| 982 | fprintf(STDOUT__stdoutp, "BUSY_VOL\t%lu\n", |
| 983 | (unsigned long)a_xInfoP->volid); |
| 984 | } /*Busy volume */ |
| 985 | else { |
| 986 | (*a_totalNotOKP)++; |
| 987 | qPut(¬okHead, a_xInfoP->volid); |
| 988 | if (a_showProblems) |
| 989 | fprintf(STDOUT__stdoutp, "COULD_NOT_ATTACH\t%lu\n", |
| 990 | (unsigned long)a_xInfoP->volid); |
| 991 | } /*Screwed volume */ |
| 992 | } /*Long listing */ |
| 993 | else { |
| 994 | /* |
| 995 | * Default listing. |
| 996 | */ |
| 997 | if (a_xInfoP->status == VOK0x02) { |
| 998 | fprintf(STDOUT__stdoutp, "name\t%-32s\n", a_xInfoP->name); |
| 999 | fprintf(STDOUT__stdoutp, "volID\t%10lu\n", (unsigned long)a_xInfoP->volid); |
| 1000 | if (a_xInfoP->type == 0) |
| 1001 | fprintf(STDOUT__stdoutp, "type\tRW\n"); |
| 1002 | if (a_xInfoP->type == 1) |
| 1003 | fprintf(STDOUT__stdoutp, "type\tRO\n"); |
| 1004 | if (a_xInfoP->type == 2) |
| 1005 | fprintf(STDOUT__stdoutp, "type\tBK\n"); |
| 1006 | fprintf(STDOUT__stdoutp, "size\t%10dK\n", a_xInfoP->size); |
| 1007 | |
| 1008 | fprintf(STDOUT__stdoutp, "inUse\t%d\n",a_xInfoP->inUse); |
| 1009 | if (a_xInfoP->inUse == 1) |
| 1010 | (*a_totalOKP)++; |
| 1011 | else |
| 1012 | (*a_totalNotOKP)++; |
| 1013 | |
| 1014 | } /*Volume OK */ |
| 1015 | else if (a_xInfoP->status == VBUSY110) { |
| 1016 | (*a_totalBusyP)++; |
| 1017 | qPut(&busyHead, a_xInfoP->volid); |
| 1018 | if (a_showProblems) |
| 1019 | fprintf(STDOUT__stdoutp, "VOLUME_BUSY\t%lu\n", |
| 1020 | (unsigned long)a_xInfoP->volid); |
| 1021 | } /*Busy volume */ |
| 1022 | else { |
| 1023 | (*a_totalNotOKP)++; |
| 1024 | qPut(¬okHead, a_xInfoP->volid); |
| 1025 | if (a_showProblems) |
| 1026 | fprintf(STDOUT__stdoutp, "COULD_NOT_ATTACH_VOLUME\t%lu\n", |
| 1027 | (unsigned long)a_xInfoP->volid); |
| 1028 | } /*Screwed volume */ |
| 1029 | } /*Default listing */ |
| 1030 | } /*XDisplayFormat */ |
| 1031 | |
| 1032 | static void |
| 1033 | DisplayFormat2(long server, long partition, volintInfo *pntr) |
| 1034 | { |
| 1035 | static long server_cache = -1, partition_cache = -1; |
| 1036 | static char hostname[256], address[32], pname[16]; |
| 1037 | time_t t; |
| 1038 | |
| 1039 | if (server != server_cache) { |
| 1040 | struct in_addr s; |
| 1041 | |
| 1042 | s.s_addr = server; |
| 1043 | strcpy(hostname, hostutil_GetNameByINet(server)); |
| 1044 | strcpy(address, inet_ntoa__inet_ntoa(s)); |
| 1045 | server_cache = server; |
| 1046 | } |
| 1047 | if (partition != partition_cache) { |
| 1048 | MapPartIdIntoName(partition, pname); |
| 1049 | partition_cache = partition; |
| 1050 | } |
| 1051 | |
| 1052 | if (pntr->status == VOK0x02) |
| 1053 | fprintf(STDOUT__stdoutp, "name\t\t%s\n", pntr->name); |
| 1054 | |
| 1055 | fprintf(STDOUT__stdoutp, "id\t\t%lu\n", |
| 1056 | afs_printable_uint32_lu(pntr->volid)); |
| 1057 | fprintf(STDOUT__stdoutp, "serv\t\t%s\t%s\n", address, hostname); |
| 1058 | fprintf(STDOUT__stdoutp, "part\t\t%s\n", pname); |
| 1059 | switch (pntr->status) { |
| 1060 | case VOK0x02: |
| 1061 | fprintf(STDOUT__stdoutp, "status\t\tOK\n"); |
| 1062 | break; |
| 1063 | case VBUSY110: |
| 1064 | fprintf(STDOUT__stdoutp, "status\t\tBUSY\n"); |
| 1065 | return; |
| 1066 | default: |
| 1067 | fprintf(STDOUT__stdoutp, "status\t\tUNATTACHABLE\n"); |
| 1068 | return; |
| 1069 | } |
| 1070 | fprintf(STDOUT__stdoutp, "backupID\t%lu\n", |
| 1071 | afs_printable_uint32_lu(pntr->backupID)); |
| 1072 | fprintf(STDOUT__stdoutp, "parentID\t%lu\n", |
| 1073 | afs_printable_uint32_lu(pntr->parentID)); |
| 1074 | fprintf(STDOUT__stdoutp, "cloneID\t\t%lu\n", |
| 1075 | afs_printable_uint32_lu(pntr->cloneID)); |
| 1076 | fprintf(STDOUT__stdoutp, "inUse\t\t%s\n", pntr->inUse ? "Y" : "N"); |
| 1077 | fprintf(STDOUT__stdoutp, "needsSalvaged\t%s\n", pntr->needsSalvaged ? "Y" : "N"); |
| 1078 | /* 0xD3 is from afs/volume.h since I had trouble including the file */ |
| 1079 | fprintf(STDOUT__stdoutp, "destroyMe\t%s\n", pntr->destroyMe == 0xD3 ? "Y" : "N"); |
| 1080 | switch (pntr->type) { |
| 1081 | case 0: |
| 1082 | fprintf(STDOUT__stdoutp, "type\t\tRW\n"); |
| 1083 | break; |
| 1084 | case 1: |
| 1085 | fprintf(STDOUT__stdoutp, "type\t\tRO\n"); |
| 1086 | break; |
| 1087 | case 2: |
| 1088 | fprintf(STDOUT__stdoutp, "type\t\tBK\n"); |
| 1089 | break; |
| 1090 | default: |
| 1091 | fprintf(STDOUT__stdoutp, "type\t\t?\n"); |
| 1092 | break; |
| 1093 | } |
| 1094 | t = pntr->creationDate; |
| 1095 | fprintf(STDOUT__stdoutp, "creationDate\t%-9lu\t%s", |
| 1096 | afs_printable_uint32_lu(pntr->creationDate), |
| 1097 | ctime(&t)); |
| 1098 | |
| 1099 | t = pntr->accessDate; |
| 1100 | fprintf(STDOUT__stdoutp, "accessDate\t%-9lu\t%s", |
| 1101 | afs_printable_uint32_lu(pntr->accessDate), |
| 1102 | ctime(&t)); |
| 1103 | |
| 1104 | t = pntr->updateDate; |
| 1105 | fprintf(STDOUT__stdoutp, "updateDate\t%-9lu\t%s", |
| 1106 | afs_printable_uint32_lu(pntr->updateDate), |
| 1107 | ctime(&t)); |
| 1108 | |
| 1109 | t = pntr->backupDate; |
| 1110 | fprintf(STDOUT__stdoutp, "backupDate\t%-9lu\t%s", |
| 1111 | afs_printable_uint32_lu(pntr->backupDate), |
| 1112 | ctime(&t)); |
| 1113 | |
| 1114 | t = pntr->copyDate; |
| 1115 | fprintf(STDOUT__stdoutp, "copyDate\t%-9lu\t%s", |
| 1116 | afs_printable_uint32_lu(pntr->copyDate), |
| 1117 | ctime(&t)); |
| 1118 | |
| 1119 | fprintf(STDOUT__stdoutp, "flags\t\t%#lx\t(Optional)\n", |
| 1120 | afs_printable_uint32_lu(pntr->flags)); |
| 1121 | fprintf(STDOUT__stdoutp, "diskused\t%u\n", pntr->size); |
| 1122 | fprintf(STDOUT__stdoutp, "maxquota\t%u\n", pntr->maxquota); |
| 1123 | fprintf(STDOUT__stdoutp, "minquota\t%lu\t(Optional)\n", |
| 1124 | afs_printable_uint32_lu(pntr->spare0)); |
| 1125 | fprintf(STDOUT__stdoutp, "filecount\t%u\n", pntr->filecount); |
| 1126 | fprintf(STDOUT__stdoutp, "dayUse\t\t%u\n", pntr->dayUse); |
| 1127 | fprintf(STDOUT__stdoutp, "weekUse\t\t%lu\t(Optional)\n", |
| 1128 | afs_printable_uint32_lu(pntr->spare1)); |
| 1129 | fprintf(STDOUT__stdoutp, "spare2\t\t%lu\t(Optional)\n", |
| 1130 | afs_printable_uint32_lu(pntr->spare2)); |
| 1131 | fprintf(STDOUT__stdoutp, "spare3\t\t%lu\t(Optional)\n", |
| 1132 | afs_printable_uint32_lu(pntr->spare3)); |
| 1133 | return; |
| 1134 | } |
| 1135 | |
| 1136 | static void |
| 1137 | DisplayVolumes2(long server, long partition, volintInfo *pntr, long count) |
| 1138 | { |
| 1139 | long i; |
| 1140 | |
| 1141 | for (i = 0; i < count; i++) { |
| 1142 | fprintf(STDOUT__stdoutp, "BEGIN_OF_ENTRY\n"); |
| 1143 | DisplayFormat2(server, partition, pntr); |
| 1144 | fprintf(STDOUT__stdoutp, "END_OF_ENTRY\n\n"); |
| 1145 | pntr++; |
| 1146 | } |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | static void |
| 1151 | DisplayVolumes(afs_uint32 server, afs_int32 part, volintInfo *pntr, |
| 1152 | afs_int32 count, afs_int32 longlist, afs_int32 fast, |
| 1153 | int quiet) |
| 1154 | { |
| 1155 | int totalOK, totalNotOK, totalBusy, i; |
| 1156 | afs_uint32 volid = 0; |
| 1157 | |
| 1158 | totalOK = 0; |
| 1159 | totalNotOK = 0; |
| 1160 | totalBusy = 0; |
| 1161 | qInit(&busyHead); |
| 1162 | qInit(¬okHead); |
| 1163 | for (i = 0; i < count; i++) { |
| 1164 | DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, |
| 1165 | fast, longlist, 0); |
| 1166 | pntr++; |
| 1167 | } |
| 1168 | if (totalBusy) { |
| 1169 | while (busyHead.count) { |
| 1170 | qGet(&busyHead, &volid); |
| 1171 | fprintf(STDOUT__stdoutp, "**** Volume %lu is busy ****\n", |
| 1172 | (unsigned long)volid); |
| 1173 | } |
| 1174 | } |
| 1175 | if (totalNotOK) { |
| 1176 | while (notokHead.count) { |
| 1177 | qGet(¬okHead, &volid); |
| 1178 | fprintf(STDOUT__stdoutp, "**** Could not attach volume %lu ****\n", |
| 1179 | (unsigned long)volid); |
| 1180 | } |
| 1181 | } |
| 1182 | if (!quiet) { |
| 1183 | fprintf(STDOUT__stdoutp, "\n"); |
| 1184 | if (!fast) { |
| 1185 | fprintf(STDOUT__stdoutp, |
| 1186 | "Total volumes onLine %d ; Total volumes offLine %d ; Total busy %d\n\n", |
| 1187 | totalOK, totalNotOK, totalBusy); |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | /*------------------------------------------------------------------------ |
| 1192 | * PRIVATE XDisplayVolumes |
| 1193 | * |
| 1194 | * Description: |
| 1195 | * Display extended volume information. |
| 1196 | * |
| 1197 | * Arguments: |
| 1198 | * a_servID : Pointer to the Rx call we're performing. |
| 1199 | * a_partID : Partition for which we want the extended list. |
| 1200 | * a_xInfoP : Ptr to extended volume info. |
| 1201 | * a_count : Number of volume records contained above. |
| 1202 | * a_int32 : Int32 listing generated? |
| 1203 | * a_fast : Fast listing generated? |
| 1204 | * a_quiet : Quiet listing generated? |
| 1205 | * |
| 1206 | * Returns: |
| 1207 | * Nothing. |
| 1208 | * |
| 1209 | * Environment: |
| 1210 | * Nothing interesting. |
| 1211 | * |
| 1212 | * Side Effects: |
| 1213 | * As advertised. |
| 1214 | *------------------------------------------------------------------------*/ |
| 1215 | |
| 1216 | static void |
| 1217 | XDisplayVolumes(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP, |
| 1218 | afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast, |
| 1219 | int a_quiet) |
| 1220 | { /*XDisplayVolumes */ |
| 1221 | |
| 1222 | int totalOK; /*Total OK volumes */ |
| 1223 | int totalNotOK; /*Total screwed volumes */ |
| 1224 | int totalBusy; /*Total busy volumes */ |
| 1225 | int i; /*Loop variable */ |
| 1226 | afs_uint32 volid = 0; /*Current volume ID */ |
| 1227 | |
| 1228 | /* |
| 1229 | * Initialize counters and (global!!) queues. |
| 1230 | */ |
| 1231 | totalOK = 0; |
| 1232 | totalNotOK = 0; |
| 1233 | totalBusy = 0; |
| 1234 | qInit(&busyHead); |
| 1235 | qInit(¬okHead); |
| 1236 | |
| 1237 | /* |
| 1238 | * Display each volume in the list. |
| 1239 | */ |
| 1240 | for (i = 0; i < a_count; i++) { |
| 1241 | XDisplayFormat(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK, |
| 1242 | &totalBusy, a_fast, a_int32, 0); |
| 1243 | a_xInfoP++; |
| 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * If any volumes were found to be busy or screwed, display them. |
| 1248 | */ |
| 1249 | if (totalBusy) { |
| 1250 | while (busyHead.count) { |
| 1251 | qGet(&busyHead, &volid); |
| 1252 | fprintf(STDOUT__stdoutp, "**** Volume %lu is busy ****\n", |
| 1253 | (unsigned long)volid); |
| 1254 | } |
| 1255 | } |
| 1256 | if (totalNotOK) { |
| 1257 | while (notokHead.count) { |
| 1258 | qGet(¬okHead, &volid); |
| 1259 | fprintf(STDOUT__stdoutp, "**** Could not attach volume %lu ****\n", |
| 1260 | (unsigned long)volid); |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | if (!a_quiet) { |
| 1265 | fprintf(STDOUT__stdoutp, "\n"); |
| 1266 | if (!a_fast) { |
| 1267 | fprintf(STDOUT__stdoutp, |
| 1268 | "Total volumes: %d on-line, %d off-line, %d busyd\n\n", |
| 1269 | totalOK, totalNotOK, totalBusy); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | } /*XDisplayVolumes */ |
| 1274 | |
| 1275 | /*------------------------------------------------------------------------ |
| 1276 | * PRIVATE XDisplayVolumes2 |
| 1277 | * |
| 1278 | * Description: |
| 1279 | * Display extended formated volume information. |
| 1280 | * |
| 1281 | * Arguments: |
| 1282 | * a_servID : Pointer to the Rx call we're performing. |
| 1283 | * a_partID : Partition for which we want the extended list. |
| 1284 | * a_xInfoP : Ptr to extended volume info. |
| 1285 | * a_count : Number of volume records contained above. |
| 1286 | * a_int32 : Int32 listing generated? |
| 1287 | * a_fast : Fast listing generated? |
| 1288 | * a_quiet : Quiet listing generated? |
| 1289 | * |
| 1290 | * Returns: |
| 1291 | * Nothing. |
| 1292 | * |
| 1293 | * Environment: |
| 1294 | * Nothing interesting. |
| 1295 | * |
| 1296 | * Side Effects: |
| 1297 | * As advertised. |
| 1298 | *------------------------------------------------------------------------*/ |
| 1299 | |
| 1300 | static void |
| 1301 | XDisplayVolumes2(afs_uint32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP, |
| 1302 | afs_int32 a_count, afs_int32 a_int32, afs_int32 a_fast, |
| 1303 | int a_quiet) |
| 1304 | { /*XDisplayVolumes */ |
| 1305 | |
| 1306 | int totalOK; /*Total OK volumes */ |
| 1307 | int totalNotOK; /*Total screwed volumes */ |
| 1308 | int totalBusy; /*Total busy volumes */ |
| 1309 | int i; /*Loop variable */ |
| 1310 | afs_uint32 volid = 0; /*Current volume ID */ |
| 1311 | |
| 1312 | /* |
| 1313 | * Initialize counters and (global!!) queues. |
| 1314 | */ |
| 1315 | totalOK = 0; |
| 1316 | totalNotOK = 0; |
| 1317 | totalBusy = 0; |
| 1318 | qInit(&busyHead); |
| 1319 | qInit(¬okHead); |
| 1320 | |
| 1321 | /* |
| 1322 | * Display each volume in the list. |
| 1323 | */ |
| 1324 | for (i = 0; i < a_count; i++) { |
| 1325 | fprintf(STDOUT__stdoutp, "BEGIN_OF_ENTRY\n"); |
| 1326 | XDisplayFormat2(a_xInfoP, a_servID, a_partID, &totalOK, &totalNotOK, |
| 1327 | &totalBusy, a_fast, a_int32, 0); |
| 1328 | fprintf(STDOUT__stdoutp, "END_OF_ENTRY\n"); |
| 1329 | a_xInfoP++; |
| 1330 | } |
| 1331 | |
| 1332 | /* |
| 1333 | * If any volumes were found to be busy or screwed, display them. |
| 1334 | */ |
| 1335 | if (totalBusy) { |
| 1336 | while (busyHead.count) { |
| 1337 | qGet(&busyHead, &volid); |
| 1338 | fprintf(STDOUT__stdoutp, "BUSY_VOL\t%lu\n", |
| 1339 | (unsigned long)volid); |
| 1340 | } |
| 1341 | } |
| 1342 | if (totalNotOK) { |
| 1343 | while (notokHead.count) { |
| 1344 | qGet(¬okHead, &volid); |
| 1345 | fprintf(STDOUT__stdoutp, "COULD_NOT_ATTACH\t%lu\n", |
| 1346 | (unsigned long)volid); |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | if (!a_quiet) { |
| 1351 | fprintf(STDOUT__stdoutp, "\n"); |
| 1352 | if (!a_fast) { |
| 1353 | fprintf(STDOUT__stdoutp, |
| 1354 | "VOLUMES_ONLINE\t%d\nVOLUMES_OFFLINE\t%d\nVOLUMES_BUSY\t%d\n", |
| 1355 | totalOK, totalNotOK, totalBusy); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | } /*XDisplayVolumes2 */ |
| 1360 | |
| 1361 | |
| 1362 | /* set <server> and <part> to the correct values depending on |
| 1363 | * <voltype> and <entry> */ |
| 1364 | static void |
| 1365 | GetServerAndPart(struct nvldbentry *entry, int voltype, afs_uint32 *server, |
| 1366 | afs_int32 *part, int *previdx) |
| 1367 | { |
| 1368 | int i, istart, vtype; |
| 1369 | |
| 1370 | *server = -1; |
| 1371 | *part = -1; |
| 1372 | |
| 1373 | /* Doesn't check for non-existance of backup volume */ |
| 1374 | if ((voltype == RWVOL0) || (voltype == BACKVOL2)) { |
| 1375 | vtype = ITSRWVOL0x04; |
| 1376 | istart = 0; /* seach the entire entry */ |
| 1377 | } else { |
| 1378 | vtype = ITSROVOL0x02; |
| 1379 | /* Seach from beginning of entry or pick up where we left off */ |
| 1380 | istart = ((*previdx < 0) ? 0 : *previdx + 1); |
| 1381 | } |
| 1382 | |
| 1383 | for (i = istart; i < entry->nServers; i++) { |
| 1384 | if (entry->serverFlags[i] & vtype) { |
| 1385 | *server = entry->serverNumber[i]; |
| 1386 | *part = entry->serverPartition[i]; |
| 1387 | *previdx = i; |
| 1388 | return; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /* Didn't find any, return -1 */ |
| 1393 | *previdx = -1; |
| 1394 | return; |
| 1395 | } |
| 1396 | |
| 1397 | static void |
| 1398 | PrintLocked(afs_int32 aflags) |
| 1399 | { |
| 1400 | afs_int32 flags = aflags & VLOP_ALLOPERS( 0x10 | 0x20 | 0x40 | 0x80 | 0x100); |
| 1401 | |
| 1402 | if (flags) { |
| 1403 | fprintf(STDOUT__stdoutp, " Volume is currently LOCKED \n"); |
| 1404 | |
| 1405 | if (flags & VLOP_MOVE0x10) { |
| 1406 | fprintf(STDOUT__stdoutp, " Volume is locked for a move operation\n"); |
| 1407 | } |
| 1408 | if (flags & VLOP_RELEASE0x20) { |
| 1409 | fprintf(STDOUT__stdoutp, " Volume is locked for a release operation\n"); |
| 1410 | } |
| 1411 | if (flags & VLOP_BACKUP0x40) { |
| 1412 | fprintf(STDOUT__stdoutp, " Volume is locked for a backup operation\n"); |
| 1413 | } |
| 1414 | if (flags & VLOP_DELETE0x80) { |
| 1415 | fprintf(STDOUT__stdoutp, " Volume is locked for a delete/misc operation\n"); |
| 1416 | } |
| 1417 | if (flags & VLOP_DUMP0x100) { |
| 1418 | fprintf(STDOUT__stdoutp, " Volume is locked for a dump/restore operation\n"); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | static void |
| 1424 | PostVolumeStats(struct nvldbentry *entry) |
| 1425 | { |
| 1426 | SubEnumerateEntry(entry); |
| 1427 | /* Check for VLOP_ALLOPERS */ |
| 1428 | PrintLocked(entry->flags); |
| 1429 | return; |
| 1430 | } |
| 1431 | |
| 1432 | /*------------------------------------------------------------------------ |
| 1433 | * PRIVATE XVolumeStats |
| 1434 | * |
| 1435 | * Description: |
| 1436 | * Display extended volume information. |
| 1437 | * |
| 1438 | * Arguments: |
| 1439 | * a_xInfoP : Ptr to extended volume info. |
| 1440 | * a_entryP : Ptr to the volume's VLDB entry. |
| 1441 | * a_srvID : Server ID. |
| 1442 | * a_partID : Partition ID. |
| 1443 | * a_volType : Type of volume to print. |
| 1444 | * |
| 1445 | * Returns: |
| 1446 | * Nothing. |
| 1447 | * |
| 1448 | * Environment: |
| 1449 | * Nothing interesting. |
| 1450 | * |
| 1451 | * Side Effects: |
| 1452 | * As advertised. |
| 1453 | *------------------------------------------------------------------------*/ |
| 1454 | |
| 1455 | static void |
| 1456 | XVolumeStats(volintXInfo *a_xInfoP, struct nvldbentry *a_entryP, |
| 1457 | afs_int32 a_srvID, afs_int32 a_partID, int a_volType) |
| 1458 | { /*XVolumeStats */ |
| 1459 | |
| 1460 | int totalOK, totalNotOK, totalBusy; /*Dummies - we don't really count here */ |
| 1461 | |
| 1462 | XDisplayFormat(a_xInfoP, /*Ptr to extended volume info */ |
| 1463 | a_srvID, /*Server ID to print */ |
| 1464 | a_partID, /*Partition ID to print */ |
| 1465 | &totalOK, /*Ptr to total-OK counter */ |
| 1466 | &totalNotOK, /*Ptr to total-screwed counter */ |
| 1467 | &totalBusy, /*Ptr to total-busy counter */ |
| 1468 | 0, /*Don't do a fast listing */ |
| 1469 | 1, /*Do a long listing */ |
| 1470 | 1); /*Show volume problems */ |
| 1471 | return; |
| 1472 | |
| 1473 | } /*XVolumeStats */ |
| 1474 | |
| 1475 | static void |
| 1476 | VolumeStats_int(volintInfo *pntr, struct nvldbentry *entry, afs_uint32 server, |
| 1477 | afs_int32 part, int voltype) |
| 1478 | { |
| 1479 | int totalOK, totalNotOK, totalBusy; |
| 1480 | |
| 1481 | DisplayFormat(pntr, server, part, &totalOK, &totalNotOK, &totalBusy, 0, 1, |
| 1482 | 1); |
| 1483 | return; |
| 1484 | } |
| 1485 | |
| 1486 | /* command to forcibly remove a volume */ |
| 1487 | static int |
| 1488 | NukeVolume(struct cmd_syndesc *as) |
| 1489 | { |
| 1490 | afs_int32 code; |
| 1491 | afs_uint32 volID; |
| 1492 | afs_int32 err; |
| 1493 | afs_int32 partID; |
| 1494 | afs_uint32 server; |
| 1495 | char *tp; |
| 1496 | |
| 1497 | server = GetServer(tp = as->parms[0].items->data); |
| 1498 | if (!server) { |
| 1499 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", tp); |
| 1500 | return 1; |
| 1501 | } |
| 1502 | |
| 1503 | partID = volutil_GetPartitionID(tp = as->parms[1].items->data); |
| 1504 | if (partID == -1) { |
| 1505 | fprintf(STDERR__stderrp, "vos: could not parse '%s' as a partition name", tp); |
| 1506 | return 1; |
| 1507 | } |
| 1508 | |
| 1509 | volID = vsu_GetVolumeID(tp = as->parms[2].items->data, cstruct, &err); |
| 1510 | if (volID == 0) { |
| 1511 | if (err) |
| 1512 | PrintError("", err); |
| 1513 | else |
| 1514 | fprintf(STDERR__stderrp, |
| 1515 | "vos: could not parse '%s' as a numeric volume ID", tp); |
| 1516 | return 1; |
| 1517 | } |
| 1518 | |
| 1519 | fprintf(STDOUT__stdoutp, |
| 1520 | "vos: forcibly removing all traces of volume %d, please wait...", |
| 1521 | volID); |
| 1522 | fflush(STDOUT__stdoutp); |
| 1523 | code = UV_NukeVolume(server, partID, volID); |
| 1524 | if (code == 0) |
| 1525 | fprintf(STDOUT__stdoutp, "done.\n"); |
| 1526 | else |
| 1527 | fprintf(STDOUT__stdoutp, "failed with code %d.\n", code); |
| 1528 | return code; |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | /*------------------------------------------------------------------------ |
| 1533 | * PRIVATE ExamineVolume |
| 1534 | * |
| 1535 | * Description: |
| 1536 | * Routine used to examine a single volume, contacting the VLDB as |
| 1537 | * well as the Volume Server. |
| 1538 | * |
| 1539 | * Arguments: |
| 1540 | * as : Ptr to parsed command line arguments. |
| 1541 | * |
| 1542 | * Returns: |
| 1543 | * 0 for a successful operation, |
| 1544 | * Otherwise, one of the ubik or VolServer error values. |
| 1545 | * |
| 1546 | * Environment: |
| 1547 | * Nothing interesting. |
| 1548 | * |
| 1549 | * Side Effects: |
| 1550 | * As advertised. |
| 1551 | *------------------------------------------------------------------------ |
| 1552 | */ |
| 1553 | static int |
| 1554 | ExamineVolume(struct cmd_syndesc *as, void *arock) |
| 1555 | { |
| 1556 | struct nvldbentry entry; |
| 1557 | afs_int32 vcode = 0; |
| 1558 | volintInfo *pntr = (volintInfo *) 0; |
| 1559 | volintXInfo *xInfoP = (volintXInfo *) 0; |
| 1560 | afs_uint32 volid; |
| 1561 | afs_int32 code, err, error = 0; |
| 1562 | int voltype, foundserv = 0, foundentry = 0; |
| 1563 | afs_uint32 aserver; |
| 1564 | afs_int32 apart; |
| 1565 | int previdx = -1; |
| 1566 | int wantExtendedInfo; /*Do we want extended vol info? */ |
| 1567 | int isSubEnum=0; /* Keep track whether sub enumerate called. */ |
| 1568 | wantExtendedInfo = (as->parms[1].items ? 1 : 0); /* -extended */ |
| 1569 | |
| 1570 | volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */ |
| 1571 | if (volid == 0) { |
| 1572 | if (err) |
| 1573 | PrintError("", err); |
| 1574 | else |
| 1575 | fprintf(STDERR__stderrp, "Unknown volume ID or name '%s'\n", |
| 1576 | as->parms[0].items->data); |
| 1577 | return -1; |
| 1578 | } |
| 1579 | |
| 1580 | if (verbose) { |
| 1581 | fprintf(STDOUT__stdoutp, "Fetching VLDB entry for %lu .. ", |
| 1582 | (unsigned long)volid); |
| 1583 | fflush(STDOUT__stdoutp); |
| 1584 | } |
| 1585 | vcode = VLDB_GetEntryByID(volid, -1, &entry); |
| 1586 | if (vcode) { |
| 1587 | fprintf(STDERR__stderrp, |
| 1588 | "Could not fetch the entry for volume number %lu from VLDB \n", |
| 1589 | (unsigned long)volid); |
| 1590 | return (vcode); |
| 1591 | } |
| 1592 | if (verbose) |
| 1593 | fprintf(STDOUT__stdoutp, "done\n"); |
| 1594 | MapHostToNetwork(&entry); |
| 1595 | |
| 1596 | if (entry.volumeId[RWVOL0] == volid) |
| 1597 | voltype = RWVOL0; |
| 1598 | else if (entry.volumeId[BACKVOL2] == volid) |
| 1599 | voltype = BACKVOL2; |
| 1600 | else /* (entry.volumeId[ROVOL] == volid) */ |
| 1601 | voltype = ROVOL1; |
| 1602 | |
| 1603 | do { /* do {...} while (voltype == ROVOL) */ |
| 1604 | /* Get the entry for the volume. If its a RW vol, get the RW entry. |
| 1605 | * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist). |
| 1606 | * If its a RO vol, get the next RO entry. |
| 1607 | */ |
| 1608 | GetServerAndPart(&entry, ((voltype == ROVOL1) ? ROVOL1 : RWVOL0), |
| 1609 | &aserver, &apart, &previdx); |
| 1610 | if (previdx == -1) { /* searched all entries */ |
| 1611 | if (!foundentry) { |
| 1612 | fprintf(STDERR__stderrp, "Volume %s does not exist in VLDB\n\n", |
| 1613 | as->parms[0].items->data); |
| 1614 | error = ENOENT2; |
| 1615 | } |
| 1616 | break; |
| 1617 | } |
| 1618 | foundentry = 1; |
| 1619 | |
| 1620 | /* Get information about the volume from the server */ |
| 1621 | if (verbose) { |
| 1622 | fprintf(STDOUT__stdoutp, "Getting volume listing from the server %s .. ", |
| 1623 | hostutil_GetNameByINet(aserver)); |
| 1624 | fflush(STDOUT__stdoutp); |
| 1625 | } |
| 1626 | if (wantExtendedInfo) |
| 1627 | code = UV_XListOneVolume(aserver, apart, volid, &xInfoP); |
| 1628 | else |
| 1629 | code = UV_ListOneVolume(aserver, apart, volid, &pntr); |
| 1630 | if (verbose) |
| 1631 | fprintf(STDOUT__stdoutp, "done\n"); |
| 1632 | |
| 1633 | if (code) { |
| 1634 | error = code; |
| 1635 | if (code == ENODEV19) { |
| 1636 | if ((voltype == BACKVOL2) && !(entry.flags & BACK_EXISTS0x4000)) { |
| 1637 | /* The VLDB says there is no backup volume and its not on disk */ |
| 1638 | fprintf(STDERR__stderrp, "Volume %s does not exist\n", |
| 1639 | as->parms[0].items->data); |
| 1640 | error = ENOENT2; |
| 1641 | } else { |
| 1642 | fprintf(STDERR__stderrp, |
| 1643 | "Volume does not exist on server %s as indicated by the VLDB\n", |
| 1644 | hostutil_GetNameByINet(aserver)); |
| 1645 | } |
| 1646 | } else { |
| 1647 | PrintDiagnostics("examine", code); |
| 1648 | } |
| 1649 | fprintf(STDOUT__stdoutp, "\n"); |
| 1650 | } else { |
| 1651 | foundserv = 1; |
| 1652 | if (wantExtendedInfo) |
| 1653 | XVolumeStats(xInfoP, &entry, aserver, apart, voltype); |
| 1654 | else if (as->parms[2].items) { |
| 1655 | DisplayFormat2(aserver, apart, pntr); |
| 1656 | EnumerateEntry(&entry); |
| 1657 | isSubEnum = 1; |
| 1658 | } else |
| 1659 | VolumeStats_int(pntr, &entry, aserver, apart, voltype); |
| 1660 | |
| 1661 | if ((voltype == BACKVOL2) && !(entry.flags & BACK_EXISTS0x4000)) { |
| 1662 | /* The VLDB says there is no backup volume yet we found one on disk */ |
| 1663 | fprintf(STDERR__stderrp, "Volume %s does not exist in VLDB\n", |
| 1664 | as->parms[0].items->data); |
| 1665 | error = ENOENT2; |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | if (pntr) |
| 1670 | free(pntr); |
| 1671 | if (xInfoP) |
| 1672 | free(xInfoP); |
| 1673 | } while (voltype == ROVOL1); |
| 1674 | |
| 1675 | if (!foundserv) { |
| 1676 | fprintf(STDERR__stderrp, "Dump only information from VLDB\n\n"); |
| 1677 | fprintf(STDOUT__stdoutp, "%s \n", entry.name); /* PostVolumeStats doesn't print name */ |
| 1678 | } |
| 1679 | |
| 1680 | if (!isSubEnum) |
| 1681 | PostVolumeStats(&entry); |
| 1682 | |
| 1683 | return (error); |
| 1684 | } |
| 1685 | |
| 1686 | /*------------------------------------------------------------------------ |
| 1687 | * PRIVATE SetFields |
| 1688 | * |
| 1689 | * Description: |
| 1690 | * Routine used to change the status of a single volume. |
| 1691 | * |
| 1692 | * Arguments: |
| 1693 | * as : Ptr to parsed command line arguments. |
| 1694 | * |
| 1695 | * Returns: |
| 1696 | * 0 for a successful operation, |
| 1697 | * Otherwise, one of the ubik or VolServer error values. |
| 1698 | * |
| 1699 | * Environment: |
| 1700 | * Nothing interesting. |
| 1701 | * |
| 1702 | * Side Effects: |
| 1703 | * As advertised. |
| 1704 | *------------------------------------------------------------------------ |
| 1705 | */ |
| 1706 | static int |
| 1707 | SetFields(struct cmd_syndesc *as, void *arock) |
| 1708 | { |
| 1709 | struct nvldbentry entry; |
| 1710 | volintInfo info; |
| 1711 | afs_uint32 volid; |
| 1712 | afs_int32 code, err; |
| 1713 | afs_uint32 aserver; |
| 1714 | afs_int32 apart; |
| 1715 | int previdx = -1; |
| 1716 | |
| 1717 | volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); /* -id */ |
| 1718 | if (volid == 0) { |
| 1719 | if (err) |
| 1720 | PrintError("", err); |
| 1721 | else |
| 1722 | fprintf(STDERR__stderrp, "Unknown volume ID or name '%s'\n", |
| 1723 | as->parms[0].items->data); |
| 1724 | return -1; |
| 1725 | } |
| 1726 | |
| 1727 | code = VLDB_GetEntryByID(volid, RWVOL0, &entry); |
| 1728 | if (code) { |
| 1729 | fprintf(STDERR__stderrp, |
| 1730 | "Could not fetch the entry for volume number %lu from VLDB \n", |
| 1731 | (unsigned long)volid); |
| 1732 | return (code); |
| 1733 | } |
| 1734 | MapHostToNetwork(&entry); |
| 1735 | |
| 1736 | GetServerAndPart(&entry, RWVOL0, &aserver, &apart, &previdx); |
| 1737 | if (previdx == -1) { |
| 1738 | fprintf(STDERR__stderrp, "Volume %s does not exist in VLDB\n\n", |
| 1739 | as->parms[0].items->data); |
| 1740 | return (ENOENT2); |
| 1741 | } |
| 1742 | |
| 1743 | init_volintInfo(&info); |
| 1744 | info.volid = volid; |
| 1745 | info.type = RWVOL0; |
| 1746 | |
| 1747 | if (as->parms[1].items) { |
| 1748 | /* -max <quota> */ |
| 1749 | code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota); |
| 1750 | if (code) { |
| 1751 | fprintf(STDERR__stderrp, "invalid quota value\n"); |
| 1752 | return code; |
| 1753 | } |
| 1754 | } |
| 1755 | if (as->parms[2].items) { |
| 1756 | /* -clearuse */ |
| 1757 | info.dayUse = 0; |
| 1758 | } |
| 1759 | if (as->parms[3].items) { |
| 1760 | /* -clearVolUpCounter */ |
| 1761 | info.spare2 = 0; |
| 1762 | } |
| 1763 | code = UV_SetVolumeInfo(aserver, apart, volid, &info); |
| 1764 | if (code) |
| 1765 | fprintf(STDERR__stderrp, |
| 1766 | "Could not update volume info fields for volume number %lu\n", |
| 1767 | (unsigned long)volid); |
| 1768 | return (code); |
| 1769 | } |
| 1770 | |
| 1771 | /*------------------------------------------------------------------------ |
| 1772 | * PRIVATE volOnline |
| 1773 | * |
| 1774 | * Description: |
| 1775 | * Brings a volume online. |
| 1776 | * |
| 1777 | * Arguments: |
| 1778 | * as : Ptr to parsed command line arguments. |
| 1779 | * |
| 1780 | * Returns: |
| 1781 | * 0 for a successful operation, |
| 1782 | * |
| 1783 | * Environment: |
| 1784 | * Nothing interesting. |
| 1785 | * |
| 1786 | * Side Effects: |
| 1787 | * As advertised. |
| 1788 | *------------------------------------------------------------------------ |
| 1789 | */ |
| 1790 | static int |
| 1791 | volOnline(struct cmd_syndesc *as, void *arock) |
| 1792 | { |
| 1793 | afs_uint32 server; |
| 1794 | afs_int32 partition; |
| 1795 | afs_uint32 volid; |
| 1796 | afs_int32 code, err = 0; |
| 1797 | |
| 1798 | server = GetServer(as->parms[0].items->data); |
| 1799 | if (server == 0) { |
| 1800 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 1801 | as->parms[0].items->data); |
| 1802 | return -1; |
| 1803 | } |
| 1804 | |
| 1805 | partition = volutil_GetPartitionID(as->parms[1].items->data); |
| 1806 | if (partition < 0) { |
| 1807 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 1808 | as->parms[1].items->data); |
| 1809 | return ENOENT2; |
| 1810 | } |
| 1811 | |
| 1812 | volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */ |
| 1813 | if (!volid) { |
| 1814 | if (err) |
| 1815 | PrintError("", err); |
| 1816 | else |
| 1817 | fprintf(STDERR__stderrp, "Unknown volume ID or name '%s'\n", |
| 1818 | as->parms[0].items->data); |
| 1819 | return -1; |
| 1820 | } |
| 1821 | |
| 1822 | code = UV_SetVolume(server, partition, volid, ITOffline1, 0 /*online */ , |
| 1823 | 0 /*sleep */ ); |
| 1824 | if (code) { |
| 1825 | fprintf(STDERR__stderrp, "Failed to set volume. Code = %d\n", code); |
| 1826 | return -1; |
| 1827 | } |
| 1828 | |
| 1829 | return 0; |
| 1830 | } |
| 1831 | |
| 1832 | /*------------------------------------------------------------------------ |
| 1833 | * PRIVATE volOffline |
| 1834 | * |
| 1835 | * Description: |
| 1836 | * Brings a volume offline. |
| 1837 | * |
| 1838 | * Arguments: |
| 1839 | * as : Ptr to parsed command line arguments. |
| 1840 | * |
| 1841 | * Returns: |
| 1842 | * 0 for a successful operation, |
| 1843 | * |
| 1844 | * Environment: |
| 1845 | * Nothing interesting. |
| 1846 | * |
| 1847 | * Side Effects: |
| 1848 | * As advertised. |
| 1849 | *------------------------------------------------------------------------ |
| 1850 | */ |
| 1851 | static int |
| 1852 | volOffline(struct cmd_syndesc *as, void *arock) |
| 1853 | { |
| 1854 | afs_uint32 server; |
| 1855 | afs_int32 partition; |
| 1856 | afs_uint32 volid; |
| 1857 | afs_int32 code, err = 0; |
| 1858 | afs_int32 transflag, sleeptime, transdone; |
| 1859 | |
| 1860 | server = GetServer(as->parms[0].items->data); |
| 1861 | if (server == 0) { |
| 1862 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 1863 | as->parms[0].items->data); |
| 1864 | return -1; |
| 1865 | } |
| 1866 | |
| 1867 | partition = volutil_GetPartitionID(as->parms[1].items->data); |
| 1868 | if (partition < 0) { |
| 1869 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 1870 | as->parms[1].items->data); |
| 1871 | return ENOENT2; |
| 1872 | } |
| 1873 | |
| 1874 | volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); /* -id */ |
| 1875 | if (!volid) { |
| 1876 | if (err) |
| 1877 | PrintError("", err); |
| 1878 | else |
| 1879 | fprintf(STDERR__stderrp, "Unknown volume ID or name '%s'\n", |
| 1880 | as->parms[0].items->data); |
| 1881 | return -1; |
| 1882 | } |
| 1883 | |
| 1884 | transflag = (as->parms[4].items ? ITBusy2 : ITOffline1); |
| 1885 | sleeptime = (as->parms[3].items ? atol(as->parms[3].items->data) : 0); |
| 1886 | transdone = (sleeptime ? 0 /*online */ : VTOutOfService2); |
| 1887 | if (as->parms[4].items && !as->parms[3].items) { |
| 1888 | fprintf(STDERR__stderrp, "-sleep option must be used with -busy flag\n"); |
| 1889 | return -1; |
| 1890 | } |
| 1891 | |
| 1892 | code = |
| 1893 | UV_SetVolume(server, partition, volid, transflag, transdone, |
| 1894 | sleeptime); |
| 1895 | if (code) { |
| 1896 | fprintf(STDERR__stderrp, "Failed to set volume. Code = %d\n", code); |
| 1897 | return -1; |
| 1898 | } |
| 1899 | |
| 1900 | return 0; |
| 1901 | } |
| 1902 | |
| 1903 | static int |
| 1904 | CreateVolume(struct cmd_syndesc *as, void *arock) |
| 1905 | { |
| 1906 | afs_int32 pnum; |
| 1907 | char part[10]; |
| 1908 | afs_uint32 volid = 0, rovolid = 0, bkvolid = 0; |
| 1909 | afs_uint32 *arovolid; |
| 1910 | afs_int32 code; |
| 1911 | struct nvldbentry entry; |
| 1912 | afs_int32 vcode; |
| 1913 | afs_int32 quota; |
| 1914 | |
| 1915 | arovolid = &rovolid; |
| 1916 | |
| 1917 | quota = 5000; |
| 1918 | tserver = GetServer(as->parms[0].items->data); |
| 1919 | if (!tserver) { |
| 1920 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 1921 | as->parms[0].items->data); |
| 1922 | return ENOENT2; |
| 1923 | } |
| 1924 | pnum = volutil_GetPartitionID(as->parms[1].items->data); |
| 1925 | if (pnum < 0) { |
| 1926 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 1927 | as->parms[1].items->data); |
| 1928 | return ENOENT2; |
| 1929 | } |
| 1930 | if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */ |
| 1931 | if (code) |
| 1932 | PrintError("", code); |
| 1933 | else |
| 1934 | fprintf(STDERR__stderrp, |
| 1935 | "vos : partition %s does not exist on the server\n", |
| 1936 | as->parms[1].items->data); |
| 1937 | return ENOENT2; |
| 1938 | } |
| 1939 | if (!ISNAMEVALID(as->parms[2].items->data)(strlen(as->parms[2].items->data) < (32 - 9))) { |
| 1940 | fprintf(STDERR__stderrp, |
| 1941 | "vos: the name of the root volume %s exceeds the size limit of %d\n", |
| 1942 | as->parms[2].items->data, VOLSER_OLDMAXVOLNAME32 - 10); |
| 1943 | return E2BIG7; |
| 1944 | } |
| 1945 | if (!VolNameOK(as->parms[2].items->data)) { |
| 1946 | fprintf(STDERR__stderrp, |
| 1947 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 1948 | as->parms[2].items->data); |
| 1949 | return EINVAL22; |
| 1950 | } |
| 1951 | if (IsNumeric(as->parms[2].items->data)) { |
| 1952 | fprintf(STDERR__stderrp, "Illegal volume name %s, should not be a number\n", |
| 1953 | as->parms[2].items->data); |
| 1954 | return EINVAL22; |
| 1955 | } |
| 1956 | vcode = VLDB_GetEntryByName(as->parms[2].items->data, &entry); |
| 1957 | if (!vcode) { |
| 1958 | fprintf(STDERR__stderrp, "Volume %s already exists\n", |
| 1959 | as->parms[2].items->data); |
| 1960 | PrintDiagnostics("create", code); |
| 1961 | return EEXIST17; |
| 1962 | } |
| 1963 | |
| 1964 | if (as->parms[3].items) { |
| 1965 | code = util_GetHumanInt32(as->parms[3].items->data, "a); |
| 1966 | if (code) { |
| 1967 | fprintf(STDERR__stderrp, "vos: bad integer specified for quota.\n"); |
| 1968 | return code; |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | if (as->parms[4].items) { |
| 1973 | if (!IsNumeric(as->parms[4].items->data)) { |
| 1974 | fprintf(STDERR__stderrp, "vos: Given volume ID %s should be numeric.\n", |
| 1975 | as->parms[4].items->data); |
| 1976 | return EINVAL22; |
| 1977 | } |
| 1978 | |
| 1979 | code = util_GetUInt32(as->parms[4].items->data, &volid); |
| 1980 | if (code) { |
| 1981 | fprintf(STDERR__stderrp, "vos: bad integer specified for volume ID.\n"); |
| 1982 | return code; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | if (as->parms[5].items) { |
| 1987 | if (!IsNumeric(as->parms[5].items->data)) { |
| 1988 | fprintf(STDERR__stderrp, "vos: Given RO volume ID %s should be numeric.\n", |
| 1989 | as->parms[5].items->data); |
| 1990 | return EINVAL22; |
| 1991 | } |
| 1992 | |
| 1993 | code = util_GetUInt32(as->parms[5].items->data, &rovolid); |
| 1994 | if (code) { |
| 1995 | fprintf(STDERR__stderrp, "vos: bad integer specified for volume ID.\n"); |
| 1996 | return code; |
| 1997 | } |
| 1998 | |
| 1999 | if (rovolid == 0) { |
| 2000 | arovolid = NULL((void *)0); |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | code = |
| 2005 | UV_CreateVolume3(tserver, pnum, as->parms[2].items->data, quota, 0, |
| 2006 | 0, 0, 0, &volid, arovolid, &bkvolid); |
| 2007 | if (code) { |
| 2008 | PrintDiagnostics("create", code); |
| 2009 | return code; |
| 2010 | } |
| 2011 | MapPartIdIntoName(pnum, part); |
| 2012 | fprintf(STDOUT__stdoutp, "Volume %lu created on partition %s of %s\n", |
| 2013 | (unsigned long)volid, part, as->parms[0].items->data); |
| 2014 | |
| 2015 | return 0; |
| 2016 | } |
| 2017 | |
| 2018 | #if 0 |
| 2019 | static afs_int32 |
| 2020 | DeleteAll(struct nvldbentry *entry) |
| 2021 | { |
| 2022 | int i; |
| 2023 | afs_int32 error, code, curserver, curpart; |
| 2024 | afs_uint32 volid; |
| 2025 | |
| 2026 | MapHostToNetwork(entry); |
| 2027 | error = 0; |
| 2028 | for (i = 0; i < entry->nServers; i++) { |
| 2029 | curserver = entry->serverNumber[i]; |
| 2030 | curpart = entry->serverPartition[i]; |
| 2031 | if (entry->serverFlags[i] & ITSROVOL0x02) { |
| 2032 | volid = entry->volumeId[ROVOL1]; |
| 2033 | } else { |
| 2034 | volid = entry->volumeId[RWVOL0]; |
| 2035 | } |
| 2036 | code = UV_DeleteVolume(curserver, curpart, volid); |
| 2037 | if (code && !error) |
| 2038 | error = code; |
| 2039 | } |
| 2040 | return error; |
| 2041 | } |
| 2042 | #endif |
| 2043 | |
| 2044 | static int |
| 2045 | DeleteVolume(struct cmd_syndesc *as, void *arock) |
| 2046 | { |
| 2047 | afs_int32 err, code = 0; |
| 2048 | afs_uint32 server = 0; |
| 2049 | afs_int32 partition = -1; |
| 2050 | afs_uint32 volid; |
| 2051 | char pname[10]; |
| 2052 | afs_int32 idx, j; |
| 2053 | |
| 2054 | if (as->parms[0].items) { |
| 2055 | server = GetServer(as->parms[0].items->data); |
| 2056 | if (!server) { |
| 2057 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2058 | as->parms[0].items->data); |
| 2059 | return ENOENT2; |
| 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | if (as->parms[1].items) { |
| 2064 | partition = volutil_GetPartitionID(as->parms[1].items->data); |
| 2065 | if (partition < 0) { |
| 2066 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2067 | as->parms[1].items->data); |
| 2068 | return EINVAL22; |
| 2069 | } |
| 2070 | |
| 2071 | /* Check for validity of the partition */ |
| 2072 | if (!IsPartValid(partition, server, &code)) { |
| 2073 | if (code) { |
| 2074 | PrintError("", code); |
| 2075 | } else { |
| 2076 | fprintf(STDERR__stderrp, |
| 2077 | "vos : partition %s does not exist on the server\n", |
| 2078 | as->parms[1].items->data); |
| 2079 | } |
| 2080 | return ENOENT2; |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); |
| 2085 | if (volid == 0) { |
| 2086 | fprintf(STDERR__stderrp, "Can't find volume name '%s' in VLDB\n", |
| 2087 | as->parms[2].items->data); |
| 2088 | if (err) |
| 2089 | PrintError("", err); |
| 2090 | return ENOENT2; |
| 2091 | } |
| 2092 | |
| 2093 | /* If the server or partition option are not complete, try to fill |
| 2094 | * them in from the VLDB entry. |
| 2095 | */ |
| 2096 | if ((partition == -1) || !server) { |
| 2097 | struct nvldbentry entry; |
| 2098 | |
| 2099 | code = VLDB_GetEntryByID(volid, -1, &entry); |
| 2100 | if (code) { |
| 2101 | fprintf(STDERR__stderrp, |
| 2102 | "Could not fetch the entry for volume %lu from VLDB\n", |
| 2103 | (unsigned long)volid); |
| 2104 | PrintError("", code); |
| 2105 | return (code); |
| 2106 | } |
| 2107 | |
| 2108 | if (((volid == entry.volumeId[RWVOL0]) && (entry.flags & RW_EXISTS0x1000)) |
| 2109 | || ((volid == entry.volumeId[BACKVOL2]) |
| 2110 | && (entry.flags & BACK_EXISTS0x4000))) { |
| 2111 | idx = Lp_GetRwIndex(&entry); |
| 2112 | if ((idx == -1) || (server && (server != entry.serverNumber[idx])) |
| 2113 | || ((partition != -1) |
| 2114 | && (partition != entry.serverPartition[idx]))) { |
| 2115 | fprintf(STDERR__stderrp, "VLDB: Volume '%s' no match\n", |
| 2116 | as->parms[2].items->data); |
| 2117 | return ENOENT2; |
| 2118 | } |
| 2119 | } else if ((volid == entry.volumeId[ROVOL1]) |
| 2120 | && (entry.flags & RO_EXISTS0x2000)) { |
| 2121 | for (idx = -1, j = 0; j < entry.nServers; j++) { |
| 2122 | if (entry.serverFlags[j] != ITSROVOL0x02) |
| 2123 | continue; |
| 2124 | |
| 2125 | if (((server == 0) || (server == entry.serverNumber[j])) |
| 2126 | && ((partition == -1) |
| 2127 | || (partition == entry.serverPartition[j]))) { |
| 2128 | if (idx != -1) { |
| 2129 | fprintf(STDERR__stderrp, |
| 2130 | "VLDB: Volume '%s' matches more than one RO\n", |
| 2131 | as->parms[2].items->data); |
| 2132 | return ENOENT2; |
| 2133 | } |
| 2134 | idx = j; |
| 2135 | } |
| 2136 | } |
| 2137 | if (idx == -1) { |
| 2138 | fprintf(STDERR__stderrp, "VLDB: Volume '%s' no match\n", |
| 2139 | as->parms[2].items->data); |
| 2140 | return ENOENT2; |
| 2141 | } |
| 2142 | } else { |
| 2143 | fprintf(STDERR__stderrp, "VLDB: Volume '%s' no match\n", |
| 2144 | as->parms[2].items->data); |
| 2145 | return ENOENT2; |
| 2146 | } |
| 2147 | |
| 2148 | server = htonl(entry.serverNumber[idx])(__builtin_constant_p(entry.serverNumber[idx]) ? ((((__uint32_t )(entry.serverNumber[idx])) >> 24) | ((((__uint32_t)(entry .serverNumber[idx])) & (0xff << 16)) >> 8) | ( (((__uint32_t)(entry.serverNumber[idx])) & (0xff << 8)) << 8) | (((__uint32_t)(entry.serverNumber[idx])) << 24)) : __bswap32_var(entry.serverNumber[idx])); |
| 2149 | partition = entry.serverPartition[idx]; |
| 2150 | } |
| 2151 | |
| 2152 | |
| 2153 | code = UV_DeleteVolume(server, partition, volid); |
| 2154 | if (code) { |
| 2155 | PrintDiagnostics("remove", code); |
| 2156 | return code; |
| 2157 | } |
| 2158 | |
| 2159 | MapPartIdIntoName(partition, pname); |
| 2160 | fprintf(STDOUT__stdoutp, "Volume %lu on partition %s server %s deleted\n", |
| 2161 | (unsigned long)volid, pname, hostutil_GetNameByINet(server)); |
| 2162 | return 0; |
| 2163 | } |
| 2164 | |
| 2165 | #define TESTM0 0 /* set for move space tests, clear for production */ |
| 2166 | static int |
| 2167 | MoveVolume(struct cmd_syndesc *as, void *arock) |
| 2168 | { |
| 2169 | |
| 2170 | afs_uint32 volid; |
| 2171 | afs_uint32 fromserver, toserver; |
| 2172 | afs_int32 frompart, topart; |
| 2173 | afs_int32 flags, code, err; |
| 2174 | char fromPartName[10], toPartName[10]; |
| 2175 | |
| 2176 | struct diskPartition64 partition; /* for space check */ |
| 2177 | volintInfo *p; |
| 2178 | |
| 2179 | volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2180 | if (volid == 0) { |
| 2181 | if (err) |
| 2182 | PrintError("", err); |
| 2183 | else |
| 2184 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2185 | as->parms[0].items->data); |
| 2186 | return ENOENT2; |
| 2187 | } |
| 2188 | fromserver = GetServer(as->parms[1].items->data); |
| 2189 | if (fromserver == 0) { |
| 2190 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2191 | as->parms[1].items->data); |
| 2192 | return ENOENT2; |
| 2193 | } |
| 2194 | toserver = GetServer(as->parms[3].items->data); |
| 2195 | if (toserver == 0) { |
| 2196 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2197 | as->parms[3].items->data); |
| 2198 | return ENOENT2; |
| 2199 | } |
| 2200 | frompart = volutil_GetPartitionID(as->parms[2].items->data); |
| 2201 | if (frompart < 0) { |
| 2202 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2203 | as->parms[2].items->data); |
| 2204 | return EINVAL22; |
| 2205 | } |
| 2206 | if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */ |
| 2207 | if (code) |
| 2208 | PrintError("", code); |
| 2209 | else |
| 2210 | fprintf(STDERR__stderrp, |
| 2211 | "vos : partition %s does not exist on the server\n", |
| 2212 | as->parms[2].items->data); |
| 2213 | return ENOENT2; |
| 2214 | } |
| 2215 | topart = volutil_GetPartitionID(as->parms[4].items->data); |
| 2216 | if (topart < 0) { |
| 2217 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2218 | as->parms[4].items->data); |
| 2219 | return EINVAL22; |
| 2220 | } |
| 2221 | if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */ |
| 2222 | if (code) |
| 2223 | PrintError("", code); |
| 2224 | else |
| 2225 | fprintf(STDERR__stderrp, |
| 2226 | "vos : partition %s does not exist on the server\n", |
| 2227 | as->parms[4].items->data); |
| 2228 | return ENOENT2; |
| 2229 | } |
| 2230 | |
| 2231 | flags = 0; |
| 2232 | if (as->parms[5].items) flags |= RV_NOCLONE0x080000; |
| 2233 | |
| 2234 | /* |
| 2235 | * check source partition for space to clone volume |
| 2236 | */ |
| 2237 | |
| 2238 | MapPartIdIntoName(topart, toPartName); |
| 2239 | MapPartIdIntoName(frompart, fromPartName); |
| 2240 | |
| 2241 | /* |
| 2242 | * check target partition for space to move volume |
| 2243 | */ |
| 2244 | |
| 2245 | code = UV_PartitionInfo64(toserver, toPartName, &partition); |
| 2246 | if (code) { |
| 2247 | fprintf(STDERR__stderrp, "vos: cannot access partition %s\n", toPartName); |
| 2248 | exit(1); |
| 2249 | } |
| 2250 | if (TESTM0) |
| 2251 | fprintf(STDOUT__stdoutp, "target partition %s free space %" AFS_INT64_FMT"lld" "\n", toPartName, |
| 2252 | partition.free); |
| 2253 | |
| 2254 | p = (volintInfo *) 0; |
| 2255 | code = UV_ListOneVolume(fromserver, frompart, volid, &p); |
| 2256 | if (code) { |
| 2257 | fprintf(STDERR__stderrp, "vos:cannot access volume %lu\n", |
| 2258 | (unsigned long)volid); |
| 2259 | exit(1); |
| 2260 | } |
| 2261 | if (TESTM0) |
| 2262 | fprintf(STDOUT__stdoutp, "volume %lu size %d\n", (unsigned long)volid, |
| 2263 | p->size); |
| 2264 | if (partition.free <= p->size) { |
| 2265 | fprintf(STDERR__stderrp, |
| 2266 | "vos: no space on target partition %s to move volume %lu\n", |
| 2267 | toPartName, (unsigned long)volid); |
| 2268 | free(p); |
| 2269 | exit(1); |
| 2270 | } |
| 2271 | free(p); |
| 2272 | |
| 2273 | if (TESTM0) { |
| 2274 | fprintf(STDOUT__stdoutp, "size test - don't do move\n"); |
| 2275 | exit(0); |
| 2276 | } |
| 2277 | |
| 2278 | /* successful move still not guaranteed but shoot for it */ |
| 2279 | |
| 2280 | code = |
| 2281 | UV_MoveVolume2(volid, fromserver, frompart, toserver, topart, flags); |
| 2282 | if (code) { |
| 2283 | PrintDiagnostics("move", code); |
| 2284 | return code; |
| 2285 | } |
| 2286 | MapPartIdIntoName(topart, toPartName); |
| 2287 | MapPartIdIntoName(frompart, fromPartName); |
| 2288 | fprintf(STDOUT__stdoutp, "Volume %lu moved from %s %s to %s %s \n", |
| 2289 | (unsigned long)volid, as->parms[1].items->data, fromPartName, |
| 2290 | as->parms[3].items->data, toPartName); |
| 2291 | |
| 2292 | return 0; |
| 2293 | } |
| 2294 | |
| 2295 | static int |
| 2296 | CopyVolume(struct cmd_syndesc *as, void *arock) |
| 2297 | { |
| 2298 | afs_uint32 volid; |
| 2299 | afs_uint32 fromserver, toserver; |
| 2300 | afs_int32 frompart, topart, code, err, flags; |
| 2301 | char fromPartName[10], toPartName[10], *tovolume; |
| 2302 | struct nvldbentry entry; |
| 2303 | struct diskPartition64 partition; /* for space check */ |
| 2304 | volintInfo *p; |
| 2305 | |
| 2306 | volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2307 | if (volid == 0) { |
| 2308 | if (err) |
| 2309 | PrintError("", err); |
| 2310 | else |
| 2311 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2312 | as->parms[0].items->data); |
| 2313 | return ENOENT2; |
| 2314 | } |
| 2315 | fromserver = GetServer(as->parms[1].items->data); |
| 2316 | if (fromserver == 0) { |
| 2317 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2318 | as->parms[1].items->data); |
| 2319 | return ENOENT2; |
| 2320 | } |
| 2321 | |
| 2322 | toserver = GetServer(as->parms[4].items->data); |
| 2323 | if (toserver == 0) { |
| 2324 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2325 | as->parms[4].items->data); |
| 2326 | return ENOENT2; |
| 2327 | } |
| 2328 | |
| 2329 | tovolume = as->parms[3].items->data; |
| 2330 | if (!ISNAMEVALID(tovolume)(strlen(tovolume) < (32 - 9))) { |
| 2331 | fprintf(STDERR__stderrp, |
| 2332 | "vos: the name of the root volume %s exceeds the size limit of %d\n", |
| 2333 | tovolume, VOLSER_OLDMAXVOLNAME32 - 10); |
| 2334 | return E2BIG7; |
| 2335 | } |
| 2336 | if (!VolNameOK(tovolume)) { |
| 2337 | fprintf(STDERR__stderrp, |
| 2338 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 2339 | tovolume); |
| 2340 | return EINVAL22; |
| 2341 | } |
| 2342 | if (IsNumeric(tovolume)) { |
| 2343 | fprintf(STDERR__stderrp, "Illegal volume name %s, should not be a number\n", |
| 2344 | tovolume); |
| 2345 | return EINVAL22; |
| 2346 | } |
| 2347 | code = VLDB_GetEntryByName(tovolume, &entry); |
| 2348 | if (!code) { |
| 2349 | fprintf(STDERR__stderrp, "Volume %s already exists\n", tovolume); |
| 2350 | PrintDiagnostics("copy", code); |
| 2351 | return EEXIST17; |
| 2352 | } |
| 2353 | |
| 2354 | frompart = volutil_GetPartitionID(as->parms[2].items->data); |
| 2355 | if (frompart < 0) { |
| 2356 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2357 | as->parms[2].items->data); |
| 2358 | return EINVAL22; |
| 2359 | } |
| 2360 | if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */ |
| 2361 | if (code) |
| 2362 | PrintError("", code); |
| 2363 | else |
| 2364 | fprintf(STDERR__stderrp, |
| 2365 | "vos : partition %s does not exist on the server\n", |
| 2366 | as->parms[2].items->data); |
| 2367 | return ENOENT2; |
| 2368 | } |
| 2369 | |
| 2370 | topart = volutil_GetPartitionID(as->parms[5].items->data); |
| 2371 | if (topart < 0) { |
| 2372 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2373 | as->parms[5].items->data); |
| 2374 | return EINVAL22; |
| 2375 | } |
| 2376 | if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */ |
| 2377 | if (code) |
| 2378 | PrintError("", code); |
| 2379 | else |
| 2380 | fprintf(STDERR__stderrp, |
| 2381 | "vos : partition %s does not exist on the server\n", |
| 2382 | as->parms[5].items->data); |
| 2383 | return ENOENT2; |
| 2384 | } |
| 2385 | |
| 2386 | flags = 0; |
| 2387 | if (as->parms[6].items) flags |= RV_OFFLINE0x000002; |
| 2388 | if (as->parms[7].items) flags |= RV_RDONLY0x010000; |
| 2389 | if (as->parms[8].items) flags |= RV_NOCLONE0x080000; |
| 2390 | |
| 2391 | MapPartIdIntoName(topart, toPartName); |
| 2392 | MapPartIdIntoName(frompart, fromPartName); |
| 2393 | |
| 2394 | /* |
| 2395 | * check target partition for space to move volume |
| 2396 | */ |
| 2397 | |
| 2398 | code = UV_PartitionInfo64(toserver, toPartName, &partition); |
| 2399 | if (code) { |
| 2400 | fprintf(STDERR__stderrp, "vos: cannot access partition %s\n", toPartName); |
| 2401 | exit(1); |
| 2402 | } |
| 2403 | if (TESTM0) |
| 2404 | fprintf(STDOUT__stdoutp, "target partition %s free space %" AFS_INT64_FMT"lld" "\n", toPartName, |
| 2405 | partition.free); |
| 2406 | |
| 2407 | p = (volintInfo *) 0; |
| 2408 | code = UV_ListOneVolume(fromserver, frompart, volid, &p); |
| 2409 | if (code) { |
| 2410 | fprintf(STDERR__stderrp, "vos:cannot access volume %lu\n", |
| 2411 | (unsigned long)volid); |
| 2412 | exit(1); |
| 2413 | } |
| 2414 | |
| 2415 | if (partition.free <= p->size) { |
| 2416 | fprintf(STDERR__stderrp, |
| 2417 | "vos: no space on target partition %s to copy volume %lu\n", |
| 2418 | toPartName, (unsigned long)volid); |
| 2419 | free(p); |
| 2420 | exit(1); |
| 2421 | } |
| 2422 | free(p); |
| 2423 | |
| 2424 | /* successful copy still not guaranteed but shoot for it */ |
| 2425 | |
| 2426 | code = |
| 2427 | UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver, |
| 2428 | topart, 0, flags); |
| 2429 | if (code) { |
| 2430 | PrintDiagnostics("copy", code); |
| 2431 | return code; |
| 2432 | } |
| 2433 | MapPartIdIntoName(topart, toPartName); |
| 2434 | MapPartIdIntoName(frompart, fromPartName); |
| 2435 | fprintf(STDOUT__stdoutp, "Volume %lu copied from %s %s to %s on %s %s \n", |
| 2436 | (unsigned long)volid, as->parms[1].items->data, fromPartName, |
| 2437 | tovolume, as->parms[4].items->data, toPartName); |
| 2438 | |
| 2439 | return 0; |
| 2440 | } |
| 2441 | |
| 2442 | |
| 2443 | static int |
| 2444 | ShadowVolume(struct cmd_syndesc *as, void *arock) |
| 2445 | { |
| 2446 | afs_uint32 volid, tovolid; |
| 2447 | afs_uint32 fromserver, toserver; |
| 2448 | afs_int32 frompart, topart; |
| 2449 | afs_int32 code, err, flags; |
| 2450 | char fromPartName[10], toPartName[10], toVolName[32], *tovolume; |
| 2451 | struct diskPartition64 partition; /* for space check */ |
| 2452 | volintInfo *p, *q; |
| 2453 | |
| 2454 | p = (volintInfo *) 0; |
| 2455 | q = (volintInfo *) 0; |
| 2456 | |
| 2457 | volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2458 | if (volid == 0) { |
| 2459 | if (err) |
| 2460 | PrintError("", err); |
| 2461 | else |
| 2462 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2463 | as->parms[0].items->data); |
| 2464 | return ENOENT2; |
| 2465 | } |
| 2466 | fromserver = GetServer(as->parms[1].items->data); |
| 2467 | if (fromserver == 0) { |
| 2468 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2469 | as->parms[1].items->data); |
| 2470 | return ENOENT2; |
| 2471 | } |
| 2472 | |
| 2473 | toserver = GetServer(as->parms[3].items->data); |
| 2474 | if (toserver == 0) { |
| 2475 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2476 | as->parms[3].items->data); |
| 2477 | return ENOENT2; |
| 2478 | } |
| 2479 | |
| 2480 | frompart = volutil_GetPartitionID(as->parms[2].items->data); |
| 2481 | if (frompart < 0) { |
| 2482 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2483 | as->parms[2].items->data); |
| 2484 | return EINVAL22; |
| 2485 | } |
| 2486 | if (!IsPartValid(frompart, fromserver, &code)) { /*check for validity of the partition */ |
| 2487 | if (code) |
| 2488 | PrintError("", code); |
| 2489 | else |
| 2490 | fprintf(STDERR__stderrp, |
| 2491 | "vos : partition %s does not exist on the server\n", |
| 2492 | as->parms[2].items->data); |
| 2493 | return ENOENT2; |
| 2494 | } |
| 2495 | |
| 2496 | topart = volutil_GetPartitionID(as->parms[4].items->data); |
| 2497 | if (topart < 0) { |
| 2498 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2499 | as->parms[4].items->data); |
| 2500 | return EINVAL22; |
| 2501 | } |
| 2502 | if (!IsPartValid(topart, toserver, &code)) { /*check for validity of the partition */ |
| 2503 | if (code) |
| 2504 | PrintError("", code); |
| 2505 | else |
| 2506 | fprintf(STDERR__stderrp, |
| 2507 | "vos : partition %s does not exist on the server\n", |
| 2508 | as->parms[4].items->data); |
| 2509 | return ENOENT2; |
| 2510 | } |
| 2511 | |
| 2512 | if (as->parms[5].items) { |
| 2513 | tovolume = as->parms[5].items->data; |
| 2514 | if (!ISNAMEVALID(tovolume)(strlen(tovolume) < (32 - 9))) { |
| 2515 | fprintf(STDERR__stderrp, |
| 2516 | "vos: the name of the root volume %s exceeds the size limit of %d\n", |
| 2517 | tovolume, VOLSER_OLDMAXVOLNAME32 - 10); |
| 2518 | return E2BIG7; |
| 2519 | } |
| 2520 | if (!VolNameOK(tovolume)) { |
| 2521 | fprintf(STDERR__stderrp, |
| 2522 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 2523 | tovolume); |
| 2524 | return EINVAL22; |
| 2525 | } |
| 2526 | if (IsNumeric(tovolume)) { |
| 2527 | fprintf(STDERR__stderrp, |
| 2528 | "Illegal volume name %s, should not be a number\n", |
| 2529 | tovolume); |
| 2530 | return EINVAL22; |
| 2531 | } |
| 2532 | } else { |
| 2533 | /* use actual name of source volume */ |
| 2534 | code = UV_ListOneVolume(fromserver, frompart, volid, &p); |
| 2535 | if (code) { |
| 2536 | fprintf(STDERR__stderrp, "vos:cannot access volume %lu\n", |
| 2537 | (unsigned long)volid); |
| 2538 | exit(1); |
| 2539 | } |
| 2540 | strcpy(toVolName, p->name); |
| 2541 | tovolume = toVolName; |
| 2542 | /* save p for size checks later */ |
| 2543 | } |
| 2544 | |
| 2545 | if (as->parms[6].items) { |
| 2546 | tovolid = vsu_GetVolumeID(as->parms[6].items->data, cstruct, &err); |
| 2547 | if (tovolid == 0) { |
| 2548 | if (err) |
| 2549 | PrintError("", err); |
| 2550 | else |
| 2551 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2552 | as->parms[6].items->data); |
| 2553 | if (p) |
| 2554 | free(p); |
| 2555 | return ENOENT2; |
| 2556 | } |
| 2557 | } else { |
| 2558 | tovolid = vsu_GetVolumeID(tovolume, cstruct, &err); |
| 2559 | if (tovolid == 0) { |
| 2560 | if (err) |
| 2561 | PrintError("", err); |
| 2562 | else |
| 2563 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2564 | tovolume); |
| 2565 | if (p) |
| 2566 | free(p); |
| 2567 | return ENOENT2; |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | flags = RV_NOVLDB0x040000; |
| 2572 | if (as->parms[7].items) flags |= RV_OFFLINE0x000002; |
| 2573 | if (as->parms[8].items) flags |= RV_RDONLY0x010000; |
| 2574 | if (as->parms[9].items) flags |= RV_NOCLONE0x080000; |
| 2575 | if (as->parms[10].items) flags |= RV_CPINCR0x020000; |
| 2576 | |
| 2577 | MapPartIdIntoName(topart, toPartName); |
| 2578 | MapPartIdIntoName(frompart, fromPartName); |
| 2579 | |
| 2580 | /* |
| 2581 | * check target partition for space to move volume |
| 2582 | */ |
| 2583 | |
| 2584 | code = UV_PartitionInfo64(toserver, toPartName, &partition); |
| 2585 | if (code) { |
| 2586 | fprintf(STDERR__stderrp, "vos: cannot access partition %s\n", toPartName); |
| 2587 | exit(1); |
| 2588 | } |
| 2589 | if (TESTM0) |
| 2590 | fprintf(STDOUT__stdoutp, "target partition %s free space %" AFS_INT64_FMT"lld" "\n", toPartName, |
| 2591 | partition.free); |
| 2592 | |
| 2593 | /* Don't do this again if we did it above */ |
| 2594 | if (!p) { |
| 2595 | code = UV_ListOneVolume(fromserver, frompart, volid, &p); |
| 2596 | if (code) { |
| 2597 | fprintf(STDERR__stderrp, "vos:cannot access volume %lu\n", |
| 2598 | (unsigned long)volid); |
| 2599 | exit(1); |
| 2600 | } |
| 2601 | } |
| 2602 | |
| 2603 | /* OK if this fails */ |
| 2604 | code = UV_ListOneVolume(toserver, topart, tovolid, &q); |
| 2605 | |
| 2606 | /* Treat existing volume size as "free" */ |
| 2607 | if (q) |
| 2608 | p->size = (q->size < p->size) ? p->size - q->size : 0; |
| 2609 | |
| 2610 | if (partition.free <= p->size) { |
| 2611 | fprintf(STDERR__stderrp, |
| 2612 | "vos: no space on target partition %s to copy volume %lu\n", |
| 2613 | toPartName, (unsigned long)volid); |
| 2614 | free(p); |
| 2615 | if (q) free(q); |
| 2616 | exit(1); |
| 2617 | } |
| 2618 | free(p); |
| 2619 | if (q) free(q); |
| 2620 | |
| 2621 | /* successful copy still not guaranteed but shoot for it */ |
| 2622 | |
| 2623 | code = |
| 2624 | UV_CopyVolume2(volid, fromserver, frompart, tovolume, toserver, |
| 2625 | topart, tovolid, flags); |
| 2626 | if (code) { |
| 2627 | PrintDiagnostics("shadow", code); |
| 2628 | return code; |
| 2629 | } |
| 2630 | MapPartIdIntoName(topart, toPartName); |
| 2631 | MapPartIdIntoName(frompart, fromPartName); |
| 2632 | fprintf(STDOUT__stdoutp, "Volume %lu shadowed from %s %s to %s %s \n", |
| 2633 | (unsigned long)volid, as->parms[1].items->data, fromPartName, |
| 2634 | as->parms[3].items->data, toPartName); |
| 2635 | |
| 2636 | return 0; |
| 2637 | } |
| 2638 | |
| 2639 | |
| 2640 | static int |
| 2641 | CloneVolume(struct cmd_syndesc *as, void *arock) |
| 2642 | { |
| 2643 | afs_uint32 volid, cloneid; |
| 2644 | afs_uint32 server; |
| 2645 | afs_int32 part, voltype; |
| 2646 | char partName[10], *volname; |
| 2647 | afs_int32 code, err, flags; |
| 2648 | struct nvldbentry entry; |
| 2649 | |
| 2650 | volid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2651 | if (volid == 0) { |
| 2652 | if (err) |
| 2653 | PrintError("", err); |
| 2654 | else |
| 2655 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2656 | as->parms[0].items->data); |
| 2657 | return ENOENT2; |
| 2658 | } |
| 2659 | |
| 2660 | if (as->parms[1].items || as->parms[2].items) { |
| 2661 | if (!as->parms[1].items || !as->parms[2].items) { |
| 2662 | fprintf(STDERR__stderrp, |
| 2663 | "Must specify both -server and -partition options\n"); |
| 2664 | return -1; |
| 2665 | } |
| 2666 | server = GetServer(as->parms[1].items->data); |
| 2667 | if (server == 0) { |
| 2668 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 2669 | as->parms[1].items->data); |
| 2670 | return ENOENT2; |
| 2671 | } |
| 2672 | part = volutil_GetPartitionID(as->parms[2].items->data); |
| 2673 | if (part < 0) { |
| 2674 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 2675 | as->parms[2].items->data); |
| 2676 | return EINVAL22; |
| 2677 | } |
| 2678 | if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */ |
| 2679 | if (code) |
| 2680 | PrintError("", code); |
| 2681 | else |
| 2682 | fprintf(STDERR__stderrp, |
| 2683 | "vos : partition %s does not exist on the server\n", |
| 2684 | as->parms[2].items->data); |
| 2685 | return ENOENT2; |
| 2686 | } |
| 2687 | } else { |
| 2688 | code = GetVolumeInfo(volid, &server, &part, &voltype, &entry); |
| 2689 | if (code) |
| 2690 | return code; |
| 2691 | } |
| 2692 | |
| 2693 | volname = 0; |
| 2694 | if (as->parms[3].items) { |
| 2695 | volname = as->parms[3].items->data; |
| 2696 | if (strlen(volname) > VOLSER_OLDMAXVOLNAME32 - 1) { |
| 2697 | fprintf(STDERR__stderrp, |
| 2698 | "vos: the name of the root volume %s exceeds the size limit of %d\n", |
| 2699 | volname, VOLSER_OLDMAXVOLNAME32 - 1); |
| 2700 | return E2BIG7; |
| 2701 | } |
| 2702 | #if 0 |
| 2703 | /* |
| 2704 | * In order that you be able to make clones of RO or BK, this |
| 2705 | * check must be omitted. |
| 2706 | */ |
| 2707 | if (!VolNameOK(volname)) { |
| 2708 | fprintf(STDERR__stderrp, |
| 2709 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 2710 | volname); |
| 2711 | return EINVAL22; |
| 2712 | } |
| 2713 | #endif |
| 2714 | if (IsNumeric(volname)) { |
| 2715 | fprintf(STDERR__stderrp, |
| 2716 | "Illegal volume name %s, should not be a number\n", |
| 2717 | volname); |
| 2718 | return EINVAL22; |
| 2719 | } |
| 2720 | } |
| 2721 | |
| 2722 | cloneid = 0; |
| 2723 | if (as->parms[4].items) { |
| 2724 | cloneid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err); |
| 2725 | if (cloneid == 0) { |
| 2726 | if (err) |
| 2727 | PrintError("", err); |
| 2728 | else |
| 2729 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2730 | as->parms[4].items->data); |
| 2731 | return ENOENT2; |
| 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | flags = 0; |
| 2736 | if (as->parms[5].items) flags |= RV_OFFLINE0x000002; |
| 2737 | if (as->parms[6].items) flags |= RV_RDONLY0x010000; |
| 2738 | |
| 2739 | |
| 2740 | code = |
| 2741 | UV_CloneVolume(server, part, volid, cloneid, volname, flags); |
| 2742 | |
| 2743 | if (code) { |
| 2744 | PrintDiagnostics("clone", code); |
| 2745 | return code; |
| 2746 | } |
| 2747 | MapPartIdIntoName(part, partName); |
| 2748 | fprintf(STDOUT__stdoutp, "Created clone for volume %s\n", |
| 2749 | as->parms[0].items->data); |
| 2750 | |
| 2751 | return 0; |
| 2752 | } |
| 2753 | |
| 2754 | |
| 2755 | static int |
| 2756 | BackupVolume(struct cmd_syndesc *as, void *arock) |
| 2757 | { |
| 2758 | afs_uint32 avolid; |
| 2759 | afs_uint32 aserver; |
| 2760 | afs_int32 apart, vtype, code, err; |
| 2761 | struct nvldbentry entry; |
| 2762 | |
| 2763 | afs_uint32 buvolid; |
| 2764 | afs_uint32 buserver; |
| 2765 | afs_int32 bupart, butype; |
| 2766 | struct nvldbentry buentry; |
| 2767 | |
| 2768 | avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2769 | if (avolid == 0) { |
| 2770 | if (err) |
| 2771 | PrintError("", err); |
| 2772 | else |
| 2773 | fprintf(STDERR__stderrp, "vos: can't find volume ID or name '%s'\n", |
| 2774 | as->parms[0].items->data); |
| 2775 | return ENOENT2; |
| 2776 | } |
| 2777 | code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry); |
| 2778 | if (code) |
| 2779 | exit(1); |
| 2780 | |
| 2781 | /* verify this is a readwrite volume */ |
| 2782 | |
| 2783 | if (vtype != RWVOL0) { |
| 2784 | fprintf(STDERR__stderrp, "%s not RW volume\n", as->parms[0].items->data); |
| 2785 | exit(1); |
| 2786 | } |
| 2787 | |
| 2788 | /* is there a backup volume already? */ |
| 2789 | |
| 2790 | if (entry.flags & BACK_EXISTS0x4000) { |
| 2791 | /* yep, where is it? */ |
| 2792 | |
| 2793 | buvolid = entry.volumeId[BACKVOL2]; |
| 2794 | code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry); |
| 2795 | if (code) |
| 2796 | exit(1); |
| 2797 | |
| 2798 | /* is it local? */ |
| 2799 | code = VLDB_IsSameAddrs(buserver, aserver, &err); |
| 2800 | if (err) { |
| 2801 | fprintf(STDERR__stderrp, |
| 2802 | "Failed to get info about server's %d address(es) from vlserver; aborting call!\n", |
| 2803 | buserver); |
| 2804 | exit(1); |
| 2805 | } |
| 2806 | if (!code) { |
| 2807 | fprintf(STDERR__stderrp, |
| 2808 | "FATAL ERROR: backup volume %lu exists on server %lu\n", |
| 2809 | (unsigned long)buvolid, (unsigned long)buserver); |
| 2810 | exit(1); |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | /* nope, carry on */ |
| 2815 | |
| 2816 | code = UV_BackupVolume(aserver, apart, avolid); |
| 2817 | |
| 2818 | if (code) { |
| 2819 | PrintDiagnostics("backup", code); |
| 2820 | return code; |
| 2821 | } |
| 2822 | fprintf(STDOUT__stdoutp, "Created backup volume for %s \n", |
| 2823 | as->parms[0].items->data); |
| 2824 | return 0; |
| 2825 | } |
| 2826 | |
| 2827 | static int |
| 2828 | ReleaseVolume(struct cmd_syndesc *as, void *arock) |
| 2829 | { |
| 2830 | |
| 2831 | struct nvldbentry entry; |
| 2832 | afs_uint32 avolid; |
| 2833 | afs_uint32 aserver; |
| 2834 | afs_int32 apart, vtype, code, err; |
| 2835 | int force = 0; |
| 2836 | |
| 2837 | if (as->parms[1].items) |
| 2838 | force = 1; |
| 2839 | avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2840 | if (avolid == 0) { |
| 2841 | if (err) |
| 2842 | PrintError("", err); |
| 2843 | else |
| 2844 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 2845 | as->parms[0].items->data); |
| 2846 | return ENOENT2; |
| 2847 | } |
| 2848 | code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry); |
| 2849 | if (code) |
| 2850 | return code; |
| 2851 | |
| 2852 | if (vtype != RWVOL0) { |
| 2853 | fprintf(STDERR__stderrp, "%s not a RW volume\n", as->parms[0].items->data); |
| 2854 | return (ENOENT2); |
| 2855 | } |
| 2856 | |
| 2857 | if (!ISNAMEVALID(entry.name)(strlen(entry.name) < (32 - 9))) { |
| 2858 | fprintf(STDERR__stderrp, |
| 2859 | "Volume name %s is too long, rename before releasing\n", |
| 2860 | entry.name); |
| 2861 | return E2BIG7; |
| 2862 | } |
| 2863 | |
| 2864 | code = UV_ReleaseVolume(avolid, aserver, apart, force); |
| 2865 | if (code) { |
| 2866 | PrintDiagnostics("release", code); |
| 2867 | return code; |
| 2868 | } |
| 2869 | fprintf(STDOUT__stdoutp, "Released volume %s successfully\n", |
| 2870 | as->parms[0].items->data); |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
| 2874 | static int |
| 2875 | DumpVolumeCmd(struct cmd_syndesc *as, void *arock) |
| 2876 | { |
| 2877 | afs_uint32 avolid; |
| 2878 | afs_uint32 aserver; |
| 2879 | afs_int32 apart, voltype, fromdate = 0, code, err, i, flags; |
| 2880 | char filename[MAXPATHLEN1024]; |
| 2881 | struct nvldbentry entry; |
| 2882 | |
| 2883 | rx_SetRxDeadTime(60 * 10)(rx_connDeadTime = (60 * 10)); |
| 2884 | for (i = 0; i < MAXSERVERS20; i++) { |
| 2885 | struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i)((i) >= 20? 0 : (cstruct)->conns[i]); |
| 2886 | if (rxConn == 0) |
| 2887 | break; |
| 2888 | rx_SetConnDeadTime(rxConn, rx_connDeadTime); |
| 2889 | if (rxConn->service) |
| 2890 | rxConn->service->connDeadTime = rx_connDeadTime; |
| 2891 | } |
| 2892 | |
| 2893 | avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 2894 | if (avolid == 0) { |
| 2895 | if (err) |
| 2896 | PrintError("", err); |
| 2897 | else |
| 2898 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 2899 | as->parms[0].items->data); |
| 2900 | return ENOENT2; |
| 2901 | } |
| 2902 | |
| 2903 | if (as->parms[3].items || as->parms[4].items) { |
| 2904 | if (!as->parms[3].items || !as->parms[4].items) { |
| 2905 | fprintf(STDERR__stderrp, |
| 2906 | "Must specify both -server and -partition options\n"); |
| 2907 | return -1; |
| 2908 | } |
| 2909 | aserver = GetServer(as->parms[3].items->data); |
| 2910 | if (aserver == 0) { |
| 2911 | fprintf(STDERR__stderrp, "Invalid server name\n"); |
| 2912 | return -1; |
| 2913 | } |
| 2914 | apart = volutil_GetPartitionID(as->parms[4].items->data); |
| 2915 | if (apart < 0) { |
| 2916 | fprintf(STDERR__stderrp, "Invalid partition name\n"); |
| 2917 | return -1; |
| 2918 | } |
| 2919 | } else { |
| 2920 | code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry); |
| 2921 | if (code) |
| 2922 | return code; |
| 2923 | } |
| 2924 | |
| 2925 | if (as->parms[1].items && strcmp(as->parms[1].items->data, "0")) { |
| 2926 | code = ktime_DateToInt32(as->parms[1].items->data, &fromdate); |
| 2927 | if (code) { |
| 2928 | fprintf(STDERR__stderrp, "vos: failed to parse date '%s' (error=%d))\n", |
| 2929 | as->parms[1].items->data, code); |
| 2930 | return code; |
| 2931 | } |
| 2932 | } |
| 2933 | if (as->parms[2].items) { |
| 2934 | strcpy(filename, as->parms[2].items->data); |
| 2935 | } else { |
| 2936 | strcpy(filename, ""); |
| 2937 | } |
| 2938 | |
| 2939 | flags = as->parms[6].items ? VOLDUMPV2_OMITDIRS1 : 0; |
| 2940 | retry_dump: |
| 2941 | if (as->parms[5].items) { |
| 2942 | code = |
| 2943 | UV_DumpClonedVolume(avolid, aserver, apart, fromdate, |
| 2944 | DumpFunction, filename, flags); |
| 2945 | } else { |
| 2946 | code = |
| 2947 | UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, |
| 2948 | filename, flags); |
| 2949 | } |
| 2950 | if ((code == RXGEN_OPCODE-455) && (as->parms[6].items)) { |
| 2951 | flags &= ~VOLDUMPV2_OMITDIRS1; |
| 2952 | goto retry_dump; |
| 2953 | } |
| 2954 | if (code) { |
| 2955 | PrintDiagnostics("dump", code); |
| 2956 | return code; |
| 2957 | } |
| 2958 | if (strcmp(filename, "")) |
| 2959 | fprintf(STDERR__stderrp, "Dumped volume %s in file %s\n", |
| 2960 | as->parms[0].items->data, filename); |
| 2961 | else |
| 2962 | fprintf(STDERR__stderrp, "Dumped volume %s in stdout \n", |
| 2963 | as->parms[0].items->data); |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
| 2967 | #define ASK0 0 |
| 2968 | #define ABORT1 1 |
| 2969 | #define FULL2 2 |
| 2970 | #define INC3 3 |
| 2971 | |
| 2972 | #define TS_DUMP1 1 |
| 2973 | #define TS_KEEP2 2 |
| 2974 | #define TS_NEW3 3 |
| 2975 | |
| 2976 | static int |
| 2977 | RestoreVolumeCmd(struct cmd_syndesc *as, void *arock) |
| 2978 | { |
| 2979 | afs_uint32 avolid, aparentid; |
| 2980 | afs_uint32 aserver; |
| 2981 | afs_int32 apart, code, vcode, err; |
| 2982 | afs_int32 aoverwrite = ASK0; |
| 2983 | afs_int32 acreation = 0, alastupdate = 0; |
| 2984 | int restoreflags = 0; |
| 2985 | int readonly = 0, offline = 0, voltype = RWVOL0; |
| 2986 | char afilename[MAXPATHLEN1024], avolname[VOLSER_MAXVOLNAME65 + 1], apartName[10]; |
| 2987 | char volname[VOLSER_MAXVOLNAME65 + 1]; |
| 2988 | struct nvldbentry entry; |
| 2989 | |
| 2990 | aparentid = 0; |
| 2991 | if (as->parms[4].items) { |
| 2992 | avolid = vsu_GetVolumeID(as->parms[4].items->data, cstruct, &err); |
| 2993 | if (avolid == 0) { |
| 2994 | if (err) |
| 2995 | PrintError("", err); |
| 2996 | else |
| 2997 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 2998 | as->parms[4].items->data); |
| 2999 | exit(1); |
| 3000 | } |
| 3001 | } else |
| 3002 | avolid = 0; |
| 3003 | |
| 3004 | if (as->parms[5].items) { |
| 3005 | if ((strcmp(as->parms[5].items->data, "a") == 0) |
| 3006 | || (strcmp(as->parms[5].items->data, "abort") == 0)) { |
| 3007 | aoverwrite = ABORT1; |
| 3008 | } else if ((strcmp(as->parms[5].items->data, "f") == 0) |
| 3009 | || (strcmp(as->parms[5].items->data, "full") == 0)) { |
| 3010 | aoverwrite = FULL2; |
| 3011 | } else if ((strcmp(as->parms[5].items->data, "i") == 0) |
| 3012 | || (strcmp(as->parms[5].items->data, "inc") == 0) |
| 3013 | || (strcmp(as->parms[5].items->data, "increment") == 0) |
| 3014 | || (strcmp(as->parms[5].items->data, "incremental") == 0)) { |
| 3015 | aoverwrite = INC3; |
| 3016 | } else { |
| 3017 | fprintf(STDERR__stderrp, "vos: %s is not a valid argument to -overwrite\n", |
| 3018 | as->parms[5].items->data); |
| 3019 | exit(1); |
| 3020 | } |
| 3021 | } |
| 3022 | if (as->parms[6].items) |
| 3023 | offline = 1; |
| 3024 | if (as->parms[7].items) { |
| 3025 | readonly = 1; |
| 3026 | voltype = ROVOL1; |
| 3027 | } |
| 3028 | |
| 3029 | if (as->parms[8].items) { |
| 3030 | if ((strcmp(as->parms[8].items->data, "d") == 0) |
| 3031 | || (strcmp(as->parms[8].items->data, "dump") == 0)) { |
| 3032 | acreation = TS_DUMP1; |
| 3033 | } else if ((strcmp(as->parms[8].items->data, "k") == 0) |
| 3034 | || (strcmp(as->parms[8].items->data, "keep") == 0)) { |
| 3035 | acreation = TS_KEEP2; |
| 3036 | } else if ((strcmp(as->parms[8].items->data, "n") == 0) |
| 3037 | || (strcmp(as->parms[8].items->data, "new") == 0)) { |
| 3038 | acreation = TS_NEW3; |
| 3039 | } else { |
| 3040 | fprintf(STDERR__stderrp, "vos: %s is not a valid argument to -creation\n", |
| 3041 | as->parms[8].items->data); |
| 3042 | exit(1); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | if (as->parms[9].items) { |
| 3047 | if ((strcmp(as->parms[9].items->data, "d") == 0) |
| 3048 | || (strcmp(as->parms[9].items->data, "dump") == 0)) { |
| 3049 | alastupdate = TS_DUMP1; |
| 3050 | } else if ((strcmp(as->parms[9].items->data, "k") == 0) |
| 3051 | || (strcmp(as->parms[9].items->data, "keep") == 0)) { |
| 3052 | alastupdate = TS_KEEP2; |
| 3053 | } else if ((strcmp(as->parms[9].items->data, "n") == 0) |
| 3054 | || (strcmp(as->parms[9].items->data, "new") == 0)) { |
| 3055 | alastupdate = TS_NEW3; |
| 3056 | } else { |
| 3057 | fprintf(STDERR__stderrp, "vos: %s is not a valid argument to -lastupdate\n", |
| 3058 | as->parms[9].items->data); |
| 3059 | exit(1); |
| 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | aserver = GetServer(as->parms[0].items->data); |
| 3064 | if (aserver == 0) { |
| 3065 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 3066 | as->parms[0].items->data); |
| 3067 | exit(1); |
| 3068 | } |
| 3069 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 3070 | if (apart < 0) { |
| 3071 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3072 | as->parms[1].items->data); |
| 3073 | exit(1); |
| 3074 | } |
| 3075 | if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ |
| 3076 | if (code) |
| 3077 | PrintError("", code); |
| 3078 | else |
| 3079 | fprintf(STDERR__stderrp, |
| 3080 | "vos : partition %s does not exist on the server\n", |
| 3081 | as->parms[1].items->data); |
| 3082 | exit(1); |
| 3083 | } |
| 3084 | strcpy(avolname, as->parms[2].items->data); |
| 3085 | if (!ISNAMEVALID(avolname)(strlen(avolname) < (32 - 9))) { |
| 3086 | fprintf(STDERR__stderrp, |
| 3087 | "vos: the name of the volume %s exceeds the size limit\n", |
| 3088 | avolname); |
| 3089 | exit(1); |
| 3090 | } |
| 3091 | if (!VolNameOK(avolname)) { |
| 3092 | fprintf(STDERR__stderrp, |
| 3093 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 3094 | avolname); |
| 3095 | exit(1); |
| 3096 | } |
| 3097 | if (as->parms[3].items) { |
| 3098 | strcpy(afilename, as->parms[3].items->data); |
| 3099 | if (!FileExists(afilename)) { |
| 3100 | fprintf(STDERR__stderrp, "Can't access file %s\n", afilename); |
| 3101 | exit(1); |
| 3102 | } |
| 3103 | } else { |
| 3104 | strcpy(afilename, ""); |
| 3105 | } |
| 3106 | |
| 3107 | /* Check if volume exists or not */ |
| 3108 | |
| 3109 | vsu_ExtractName(volname, avolname); |
| 3110 | vcode = VLDB_GetEntryByName(volname, &entry); |
| 3111 | if (vcode) { /* no volume - do a full restore */ |
| 3112 | restoreflags = RV_FULLRST0x000001; |
| 3113 | if ((aoverwrite == INC3) || (aoverwrite == ABORT1)) |
| 3114 | fprintf(STDERR__stderrp, |
| 3115 | "Volume does not exist; Will perform a full restore\n"); |
| 3116 | } |
| 3117 | |
| 3118 | else if ((!readonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */ |
| 3119 | ||(readonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */ |
| 3120 | restoreflags = RV_FULLRST0x000001; |
| 3121 | if ((aoverwrite == INC3) || (aoverwrite == ABORT1)) |
| 3122 | fprintf(STDERR__stderrp, |
| 3123 | "%s Volume does not exist; Will perform a full restore\n", |
| 3124 | readonly ? "RO" : "RW"); |
| 3125 | |
| 3126 | if (avolid == 0) { |
| 3127 | avolid = entry.volumeId[voltype]; |
| 3128 | } else if (entry.volumeId[voltype] != 0 |
| 3129 | && entry.volumeId[voltype] != avolid) { |
| 3130 | avolid = entry.volumeId[voltype]; |
| 3131 | } |
| 3132 | aparentid = entry.volumeId[RWVOL0]; |
| 3133 | } |
| 3134 | |
| 3135 | else { /* volume exists - do we do a full incremental or abort */ |
| 3136 | afs_uint32 Oserver; |
| 3137 | afs_int32 Opart, Otype, vol_elsewhere = 0; |
| 3138 | struct nvldbentry Oentry; |
| 3139 | int c, dc; |
| 3140 | |
| 3141 | if (avolid == 0) { |
| 3142 | avolid = entry.volumeId[voltype]; |
| 3143 | } else if (entry.volumeId[voltype] != 0 |
| 3144 | && entry.volumeId[voltype] != avolid) { |
| 3145 | avolid = entry.volumeId[voltype]; |
| 3146 | } |
| 3147 | aparentid = entry.volumeId[RWVOL0]; |
| 3148 | |
| 3149 | /* A file name was specified - check if volume is on another partition */ |
| 3150 | vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry); |
| 3151 | if (vcode) |
| 3152 | exit(1); |
| 3153 | |
| 3154 | vcode = VLDB_IsSameAddrs(Oserver, aserver, &err); |
| 3155 | if (err) { |
| 3156 | fprintf(STDERR__stderrp, |
| 3157 | "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", |
| 3158 | Oserver, err); |
| 3159 | exit(1); |
| 3160 | } |
| 3161 | if (!vcode || (Opart != apart)) |
| 3162 | vol_elsewhere = 1; |
| 3163 | |
| 3164 | if (aoverwrite == ASK0) { |
| 3165 | if (strcmp(afilename, "") == 0) { /* The file is from standard in */ |
| 3166 | fprintf(STDERR__stderrp, |
| 3167 | "Volume exists and no -overwrite option specified; Aborting restore command\n"); |
| 3168 | exit(1); |
| 3169 | } |
| 3170 | |
| 3171 | /* Ask what to do */ |
| 3172 | if (vol_elsewhere) { |
| 3173 | fprintf(STDERR__stderrp, |
| 3174 | "The volume %s %u already exists on a different server/part\n", |
| 3175 | volname, entry.volumeId[voltype]); |
| 3176 | fprintf(STDERR__stderrp, |
| 3177 | "Do you want to do a full restore or abort? [fa](a): "); |
| 3178 | } else { |
| 3179 | fprintf(STDERR__stderrp, |
| 3180 | "The volume %s %u already exists in the VLDB\n", |
| 3181 | volname, entry.volumeId[voltype]); |
| 3182 | fprintf(STDERR__stderrp, |
| 3183 | "Do you want to do a full/incremental restore or abort? [fia](a): "); |
| 3184 | } |
| 3185 | dc = c = getchar()(!__isthreaded ? (--(__stdinp)->_r < 0 ? __srget(__stdinp ) : (int)(*(__stdinp)->_p++)) : (getc)(__stdinp)); |
| 3186 | while (!(dc == EOF(-1) || dc == '\n')) |
| 3187 | dc = getchar()(!__isthreaded ? (--(__stdinp)->_r < 0 ? __srget(__stdinp ) : (int)(*(__stdinp)->_p++)) : (getc)(__stdinp)); /* goto end of line */ |
| 3188 | if ((c == 'f') || (c == 'F')) |
| 3189 | aoverwrite = FULL2; |
| 3190 | else if ((c == 'i') || (c == 'I')) |
| 3191 | aoverwrite = INC3; |
| 3192 | else |
| 3193 | aoverwrite = ABORT1; |
| 3194 | } |
| 3195 | |
| 3196 | if (aoverwrite == ABORT1) { |
| 3197 | fprintf(STDERR__stderrp, "Volume exists; Aborting restore command\n"); |
| 3198 | exit(1); |
| 3199 | } else if (aoverwrite == FULL2) { |
| 3200 | restoreflags = RV_FULLRST0x000001; |
| 3201 | fprintf(STDERR__stderrp, |
| 3202 | "Volume exists; Will delete and perform full restore\n"); |
| 3203 | } else if (aoverwrite == INC3) { |
| 3204 | restoreflags = 0; |
| 3205 | if (vol_elsewhere) { |
| 3206 | fprintf(STDERR__stderrp, |
| 3207 | "%s volume %lu already exists on a different server/part; not allowed\n", |
| 3208 | readonly ? "RO" : "RW", (unsigned long)avolid); |
| 3209 | exit(1); |
| 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | if (offline) |
| 3214 | restoreflags |= RV_OFFLINE0x000002; |
| 3215 | if (readonly) |
| 3216 | restoreflags |= RV_RDONLY0x010000; |
| 3217 | |
| 3218 | switch (acreation) { |
| 3219 | case TS_DUMP1: |
| 3220 | restoreflags |= RV_CRDUMP0x000010; |
| 3221 | break; |
| 3222 | case TS_KEEP2: |
| 3223 | restoreflags |= RV_CRKEEP0x000020; |
| 3224 | break; |
| 3225 | case TS_NEW3: |
| 3226 | restoreflags |= RV_CRNEW0x000040; |
| 3227 | break; |
| 3228 | default: |
| 3229 | if (aoverwrite == FULL2) |
| 3230 | restoreflags |= RV_CRNEW0x000040; |
| 3231 | else |
| 3232 | restoreflags |= RV_CRKEEP0x000020; |
| 3233 | } |
| 3234 | |
| 3235 | switch (alastupdate) { |
| 3236 | case TS_DUMP1: |
| 3237 | restoreflags |= RV_LUDUMP0x000100; |
| 3238 | break; |
| 3239 | case TS_KEEP2: |
| 3240 | restoreflags |= RV_LUKEEP0x000200; |
| 3241 | break; |
| 3242 | case TS_NEW3: |
| 3243 | restoreflags |= RV_LUNEW0x000400; |
| 3244 | break; |
| 3245 | default: |
| 3246 | restoreflags |= RV_LUDUMP0x000100; |
| 3247 | } |
| 3248 | if (as->parms[10].items) { |
| 3249 | restoreflags |= RV_NODEL0x100000; |
| 3250 | } |
| 3251 | |
| 3252 | |
| 3253 | code = |
| 3254 | UV_RestoreVolume2(aserver, apart, avolid, aparentid, |
| 3255 | avolname, restoreflags, WriteData, afilename); |
| 3256 | if (code) { |
| 3257 | PrintDiagnostics("restore", code); |
| 3258 | exit(1); |
| 3259 | } |
| 3260 | MapPartIdIntoName(apart, apartName); |
| 3261 | |
| 3262 | /* |
| 3263 | * patch typo here - originally "parms[1]", should be "parms[0]" |
| 3264 | */ |
| 3265 | |
| 3266 | fprintf(STDOUT__stdoutp, "Restored volume %s on %s %s\n", avolname, |
| 3267 | as->parms[0].items->data, apartName); |
| 3268 | return 0; |
| 3269 | } |
| 3270 | |
| 3271 | static int |
| 3272 | LockReleaseCmd(struct cmd_syndesc *as, void *arock) |
| 3273 | { |
| 3274 | afs_uint32 avolid; |
| 3275 | afs_int32 code, err; |
| 3276 | |
| 3277 | avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 3278 | if (avolid == 0) { |
| 3279 | if (err) |
| 3280 | PrintError("", err); |
| 3281 | else |
| 3282 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 3283 | as->parms[0].items->data); |
| 3284 | exit(1); |
| 3285 | } |
| 3286 | |
| 3287 | code = UV_LockRelease(avolid); |
| 3288 | if (code) { |
| 3289 | PrintDiagnostics("unlock", code); |
| 3290 | exit(1); |
| 3291 | } |
| 3292 | fprintf(STDOUT__stdoutp, "Released lock on vldb entry for volume %s\n", |
| 3293 | as->parms[0].items->data); |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
| 3297 | static int |
| 3298 | AddSite(struct cmd_syndesc *as, void *arock) |
| 3299 | { |
| 3300 | afs_uint32 avolid; |
| 3301 | afs_uint32 aserver; |
| 3302 | afs_int32 apart, code, err, arovolid, valid = 0; |
| 3303 | char apartName[10], avolname[VOLSER_MAXVOLNAME65 + 1]; |
| 3304 | |
| 3305 | vsu_ExtractName(avolname, as->parms[2].items->data);; |
| 3306 | avolid = vsu_GetVolumeID(avolname, cstruct, &err); |
| 3307 | if (avolid == 0) { |
| 3308 | if (err) |
| 3309 | PrintError("", err); |
| 3310 | else |
| 3311 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 3312 | as->parms[2].items->data); |
| 3313 | exit(1); |
| 3314 | } |
| 3315 | arovolid = 0; |
| 3316 | if (as->parms[3].items) { |
| 3317 | vsu_ExtractName(avolname, as->parms[3].items->data); |
| 3318 | arovolid = vsu_GetVolumeID(avolname, cstruct, &err); |
| 3319 | if (!arovolid) { |
| 3320 | fprintf(STDERR__stderrp, "vos: invalid ro volume id '%s'\n", |
| 3321 | as->parms[3].items->data); |
| 3322 | exit(1); |
| 3323 | } |
| 3324 | } |
| 3325 | aserver = GetServer(as->parms[0].items->data); |
| 3326 | if (aserver == 0) { |
| 3327 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 3328 | as->parms[0].items->data); |
| 3329 | exit(1); |
| 3330 | } |
| 3331 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 3332 | if (apart < 0) { |
| 3333 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3334 | as->parms[1].items->data); |
| 3335 | exit(1); |
| 3336 | } |
| 3337 | if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ |
| 3338 | if (code) |
| 3339 | PrintError("", code); |
| 3340 | else |
| 3341 | fprintf(STDERR__stderrp, |
| 3342 | "vos : partition %s does not exist on the server\n", |
| 3343 | as->parms[1].items->data); |
| 3344 | exit(1); |
| 3345 | } |
| 3346 | if (as->parms[4].items) { |
| 3347 | valid = 1; |
| 3348 | } |
| 3349 | code = UV_AddSite2(aserver, apart, avolid, arovolid, valid); |
| 3350 | if (code) { |
| 3351 | PrintDiagnostics("addsite", code); |
| 3352 | exit(1); |
| 3353 | } |
| 3354 | MapPartIdIntoName(apart, apartName); |
| 3355 | fprintf(STDOUT__stdoutp, "Added replication site %s %s for volume %s\n", |
| 3356 | as->parms[0].items->data, apartName, as->parms[2].items->data); |
| 3357 | return 0; |
| 3358 | } |
| 3359 | |
| 3360 | static int |
| 3361 | RemoveSite(struct cmd_syndesc *as, void *arock) |
| 3362 | { |
| 3363 | |
| 3364 | afs_uint32 avolid; |
| 3365 | afs_uint32 aserver; |
| 3366 | afs_int32 apart, code, err; |
| 3367 | char apartName[10], avolname[VOLSER_MAXVOLNAME65 + 1]; |
| 3368 | |
| 3369 | vsu_ExtractName(avolname, as->parms[2].items->data); |
| 3370 | avolid = vsu_GetVolumeID(avolname, cstruct, &err); |
| 3371 | if (avolid == 0) { |
| 3372 | if (err) |
| 3373 | PrintError("", err); |
| 3374 | else |
| 3375 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 3376 | as->parms[2].items->data); |
| 3377 | exit(1); |
| 3378 | } |
| 3379 | aserver = GetServer(as->parms[0].items->data); |
| 3380 | if (aserver == 0) { |
| 3381 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 3382 | as->parms[0].items->data); |
| 3383 | exit(1); |
| 3384 | } |
| 3385 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 3386 | if (apart < 0) { |
| 3387 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3388 | as->parms[1].items->data); |
| 3389 | exit(1); |
| 3390 | } |
| 3391 | /* |
| 3392 | *skip the partition validity check, since it is possible that the partition |
| 3393 | *has since been decomissioned. |
| 3394 | */ |
| 3395 | /* |
| 3396 | if (!IsPartValid(apart,aserver,&code)){ |
| 3397 | if(code) PrintError("",code); |
| 3398 | else fprintf(STDERR,"vos : partition %s does not exist on the server\n",as->parms[1].items->data); |
| 3399 | exit(1); |
| 3400 | } |
| 3401 | */ |
| 3402 | code = UV_RemoveSite(aserver, apart, avolid); |
| 3403 | if (code) { |
| 3404 | PrintDiagnostics("remsite", code); |
| 3405 | exit(1); |
| 3406 | } |
| 3407 | MapPartIdIntoName(apart, apartName); |
| 3408 | fprintf(STDOUT__stdoutp, "Removed replication site %s %s for volume %s\n", |
| 3409 | as->parms[0].items->data, apartName, as->parms[2].items->data); |
| 3410 | return 0; |
| 3411 | } |
| 3412 | |
| 3413 | static int |
| 3414 | ChangeLocation(struct cmd_syndesc *as, void *arock) |
| 3415 | { |
| 3416 | afs_uint32 avolid; |
| 3417 | afs_uint32 aserver; |
| 3418 | afs_int32 apart, code, err; |
| 3419 | char apartName[10]; |
| 3420 | |
| 3421 | avolid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); |
| 3422 | if (avolid == 0) { |
| 3423 | if (err) |
| 3424 | PrintError("", err); |
| 3425 | else |
| 3426 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 3427 | as->parms[2].items->data); |
| 3428 | exit(1); |
| 3429 | } |
| 3430 | aserver = GetServer(as->parms[0].items->data); |
| 3431 | if (aserver == 0) { |
| 3432 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 3433 | as->parms[0].items->data); |
| 3434 | exit(1); |
| 3435 | } |
| 3436 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 3437 | if (apart < 0) { |
| 3438 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3439 | as->parms[1].items->data); |
| 3440 | exit(1); |
| 3441 | } |
| 3442 | if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ |
| 3443 | if (code) |
| 3444 | PrintError("", code); |
| 3445 | else |
| 3446 | fprintf(STDERR__stderrp, |
| 3447 | "vos : partition %s does not exist on the server\n", |
| 3448 | as->parms[1].items->data); |
| 3449 | exit(1); |
| 3450 | } |
| 3451 | code = UV_ChangeLocation(aserver, apart, avolid); |
| 3452 | if (code) { |
| 3453 | PrintDiagnostics("addsite", code); |
| 3454 | exit(1); |
| 3455 | } |
| 3456 | MapPartIdIntoName(apart, apartName); |
| 3457 | fprintf(STDOUT__stdoutp, "Changed location to %s %s for volume %s\n", |
| 3458 | as->parms[0].items->data, apartName, as->parms[2].items->data); |
| 3459 | return 0; |
| 3460 | } |
| 3461 | |
| 3462 | static int |
| 3463 | ListPartitions(struct cmd_syndesc *as, void *arock) |
| 3464 | { |
| 3465 | afs_uint32 aserver; |
| 3466 | afs_int32 code; |
| 3467 | struct partList dummyPartList; |
| 3468 | int i; |
| 3469 | char pname[10]; |
| 3470 | int total, cnt; |
| 3471 | |
| 3472 | aserver = GetServer(as->parms[0].items->data); |
| 3473 | if (aserver == 0) { |
| 3474 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 3475 | as->parms[0].items->data); |
| 3476 | exit(1); |
| 3477 | } |
| 3478 | |
| 3479 | |
| 3480 | code = UV_ListPartitions(aserver, &dummyPartList, &cnt); |
| 3481 | if (code) { |
| 3482 | PrintDiagnostics("listpart", code); |
| 3483 | exit(1); |
| 3484 | } |
| 3485 | total = 0; |
| 3486 | fprintf(STDOUT__stdoutp, "The partitions on the server are:\n"); |
| 3487 | for (i = 0; i < cnt; i++) { |
| 3488 | if (dummyPartList.partFlags[i] & PARTVALID0x01) { |
| 3489 | memset(pname, 0, sizeof(pname)); |
| 3490 | MapPartIdIntoName(dummyPartList.partId[i], pname); |
| 3491 | fprintf(STDOUT__stdoutp, " %10s ", pname); |
| 3492 | total++; |
| 3493 | if ((i % 5) == 0 && (i != 0)) |
| 3494 | fprintf(STDOUT__stdoutp, "\n"); |
| 3495 | } |
| 3496 | } |
| 3497 | fprintf(STDOUT__stdoutp, "\n"); |
| 3498 | fprintf(STDOUT__stdoutp, "Total: %d\n", total); |
| 3499 | return 0; |
| 3500 | |
| 3501 | } |
| 3502 | |
| 3503 | static int |
| 3504 | CompareVolName(const void *p1, const void *p2) |
| 3505 | { |
| 3506 | volintInfo *arg1, *arg2; |
| 3507 | |
| 3508 | arg1 = (volintInfo *) p1; |
| 3509 | arg2 = (volintInfo *) p2; |
| 3510 | return (strcmp(arg1->name, arg2->name)); |
| 3511 | |
| 3512 | } |
| 3513 | |
| 3514 | /*------------------------------------------------------------------------ |
| 3515 | * PRIVATE XCompareVolName |
| 3516 | * |
| 3517 | * Description: |
| 3518 | * Comparison routine for volume names coming from an extended |
| 3519 | * volume listing. |
| 3520 | * |
| 3521 | * Arguments: |
| 3522 | * a_obj1P : Char ptr to first extended vol info object |
| 3523 | * a_obj1P : Char ptr to second extended vol info object |
| 3524 | * |
| 3525 | * Returns: |
| 3526 | * The value of strcmp() on the volume names within the passed |
| 3527 | * objects (i,e., -1, 0, or 1). |
| 3528 | * |
| 3529 | * Environment: |
| 3530 | * Passed to qsort() as the designated comparison routine. |
| 3531 | * |
| 3532 | * Side Effects: |
| 3533 | * As advertised. |
| 3534 | *------------------------------------------------------------------------*/ |
| 3535 | |
| 3536 | static int |
| 3537 | XCompareVolName(const void *a_obj1P, const void *a_obj2P) |
| 3538 | { /*XCompareVolName */ |
| 3539 | |
| 3540 | return (strcmp |
| 3541 | (((struct volintXInfo *)(a_obj1P))->name, |
| 3542 | ((struct volintXInfo *)(a_obj2P))->name)); |
| 3543 | |
| 3544 | } /*XCompareVolName */ |
| 3545 | |
| 3546 | static int |
| 3547 | CompareVolID(const void *p1, const void *p2) |
| 3548 | { |
| 3549 | volintInfo *arg1, *arg2; |
| 3550 | |
| 3551 | arg1 = (volintInfo *) p1; |
| 3552 | arg2 = (volintInfo *) p2; |
| 3553 | if (arg1->volid == arg2->volid) |
| 3554 | return 0; |
| 3555 | if (arg1->volid > arg2->volid) |
| 3556 | return 1; |
| 3557 | else |
| 3558 | return -1; |
| 3559 | |
| 3560 | } |
| 3561 | |
| 3562 | /*------------------------------------------------------------------------ |
| 3563 | * PRIVATE XCompareVolID |
| 3564 | * |
| 3565 | * Description: |
| 3566 | * Comparison routine for volume IDs coming from an extended |
| 3567 | * volume listing. |
| 3568 | * |
| 3569 | * Arguments: |
| 3570 | * a_obj1P : Char ptr to first extended vol info object |
| 3571 | * a_obj1P : Char ptr to second extended vol info object |
| 3572 | * |
| 3573 | * Returns: |
| 3574 | * The value of strcmp() on the volume names within the passed |
| 3575 | * objects (i,e., -1, 0, or 1). |
| 3576 | * |
| 3577 | * Environment: |
| 3578 | * Passed to qsort() as the designated comparison routine. |
| 3579 | * |
| 3580 | * Side Effects: |
| 3581 | * As advertised. |
| 3582 | *------------------------------------------------------------------------*/ |
| 3583 | |
| 3584 | static int |
| 3585 | XCompareVolID(const void *a_obj1P, const void *a_obj2P) |
| 3586 | { /*XCompareVolID */ |
| 3587 | |
| 3588 | afs_int32 id1, id2; /*Volume IDs we're comparing */ |
| 3589 | |
| 3590 | id1 = ((struct volintXInfo *)(a_obj1P))->volid; |
| 3591 | id2 = ((struct volintXInfo *)(a_obj2P))->volid; |
| 3592 | if (id1 == id2) |
| 3593 | return (0); |
| 3594 | else if (id1 > id2) |
| 3595 | return (1); |
| 3596 | else |
| 3597 | return (-1); |
| 3598 | |
| 3599 | } /*XCompareVolID */ |
| 3600 | |
| 3601 | /*------------------------------------------------------------------------ |
| 3602 | * PRIVATE ListVolumes |
| 3603 | * |
| 3604 | * Description: |
| 3605 | * Routine used to list volumes, contacting the Volume Server |
| 3606 | * directly, bypassing the VLDB. |
| 3607 | * |
| 3608 | * Arguments: |
| 3609 | * as : Ptr to parsed command line arguments. |
| 3610 | * |
| 3611 | * Returns: |
| 3612 | * 0 Successful operation |
| 3613 | * |
| 3614 | * Environment: |
| 3615 | * Nothing interesting. |
| 3616 | * |
| 3617 | * Side Effects: |
| 3618 | * As advertised. |
| 3619 | *------------------------------------------------------------------------*/ |
| 3620 | |
| 3621 | static int |
| 3622 | ListVolumes(struct cmd_syndesc *as, void *arock) |
| 3623 | { |
| 3624 | afs_int32 apart, int32list, fast; |
| 3625 | afs_uint32 aserver; |
| 3626 | afs_int32 code; |
| 3627 | volintInfo *pntr; |
| 3628 | volintInfo *oldpntr = NULL((void *)0); |
| 3629 | afs_int32 count; |
| 3630 | int i; |
| 3631 | char *base; |
| 3632 | volintXInfo *xInfoP; |
| 3633 | volintXInfo *origxInfoP = NULL((void *)0); /*Ptr to current/orig extended vol info */ |
| 3634 | int wantExtendedInfo; /*Do we want extended vol info? */ |
| 3635 | |
| 3636 | char pname[10]; |
| 3637 | struct partList dummyPartList; |
| 3638 | int all; |
| 3639 | int quiet, cnt; |
| 3640 | |
| 3641 | apart = -1; |
| 3642 | fast = 0; |
| 3643 | int32list = 0; |
| 3644 | |
| 3645 | if (as->parms[3].items) |
| 3646 | int32list = 1; |
| 3647 | if (as->parms[4].items) |
| 3648 | quiet = 1; |
| 3649 | else |
| 3650 | quiet = 0; |
| 3651 | if (as->parms[2].items) |
| 3652 | fast = 1; |
| 3653 | if (fast) |
| 3654 | all = 0; |
| 3655 | else |
| 3656 | all = 1; |
| 3657 | if (as->parms[5].items) { |
| 3658 | /* |
| 3659 | * We can't coexist with the fast flag. |
| 3660 | */ |
| 3661 | if (fast) { |
| 3662 | fprintf(STDERR__stderrp, |
| 3663 | "vos: Can't use the -fast and -extended flags together\n"); |
| 3664 | exit(1); |
| 3665 | } |
| 3666 | |
| 3667 | /* |
| 3668 | * We need to turn on ``long'' listings to get the full effect. |
| 3669 | */ |
| 3670 | wantExtendedInfo = 1; |
| 3671 | int32list = 1; |
| 3672 | } else |
| 3673 | wantExtendedInfo = 0; |
| 3674 | if (as->parms[1].items) { |
| 3675 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 3676 | if (apart < 0) { |
| 3677 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3678 | as->parms[1].items->data); |
| 3679 | exit(1); |
| 3680 | } |
| 3681 | dummyPartList.partId[0] = apart; |
| 3682 | dummyPartList.partFlags[0] = PARTVALID0x01; |
| 3683 | cnt = 1; |
| 3684 | } |
| 3685 | aserver = GetServer(as->parms[0].items->data); |
| 3686 | if (aserver == 0) { |
| 3687 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 3688 | as->parms[0].items->data); |
| 3689 | exit(1); |
| 3690 | } |
| 3691 | |
| 3692 | if (apart != -1) { |
| 3693 | if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ |
| 3694 | if (code) |
| 3695 | PrintError("", code); |
| 3696 | else |
| 3697 | fprintf(STDERR__stderrp, |
| 3698 | "vos : partition %s does not exist on the server\n", |
| 3699 | as->parms[1].items->data); |
| 3700 | exit(1); |
| 3701 | } |
| 3702 | } else { |
| 3703 | code = UV_ListPartitions(aserver, &dummyPartList, &cnt); |
| 3704 | if (code) { |
| 3705 | PrintDiagnostics("listvol", code); |
| 3706 | exit(1); |
| 3707 | } |
| 3708 | } |
| 3709 | for (i = 0; i < cnt; i++) { |
| 3710 | if (dummyPartList.partFlags[i] & PARTVALID0x01) { |
| 3711 | if (wantExtendedInfo) |
| 3712 | code = |
| 3713 | UV_XListVolumes(aserver, dummyPartList.partId[i], all, |
| 3714 | &xInfoP, &count); |
| 3715 | else |
| 3716 | code = |
| 3717 | UV_ListVolumes(aserver, dummyPartList.partId[i], all, |
| 3718 | &pntr, &count); |
| 3719 | if (code) { |
| 3720 | PrintDiagnostics("listvol", code); |
| 3721 | if (pntr) |
| 3722 | free(pntr); |
| 3723 | exit(1); |
| 3724 | } |
| 3725 | if (wantExtendedInfo) { |
| 3726 | origxInfoP = xInfoP; |
| 3727 | base = (char *)xInfoP; |
| 3728 | } else { |
| 3729 | oldpntr = pntr; |
| 3730 | base = (char *)pntr; |
| 3731 | } |
| 3732 | |
| 3733 | if (!fast) { |
| 3734 | if (wantExtendedInfo) |
| 3735 | qsort(base, count, sizeof(volintXInfo), XCompareVolName); |
| 3736 | else |
| 3737 | qsort(base, count, sizeof(volintInfo), CompareVolName); |
| 3738 | } else { |
| 3739 | if (wantExtendedInfo) |
| 3740 | qsort(base, count, sizeof(volintXInfo), XCompareVolID); |
| 3741 | else |
| 3742 | qsort(base, count, sizeof(volintInfo), CompareVolID); |
| 3743 | } |
| 3744 | MapPartIdIntoName(dummyPartList.partId[i], pname); |
| 3745 | if (!quiet) |
| 3746 | fprintf(STDOUT__stdoutp, |
| 3747 | "Total number of volumes on server %s partition %s: %lu \n", |
| 3748 | as->parms[0].items->data, pname, |
| 3749 | (unsigned long)count); |
| 3750 | if (wantExtendedInfo) { |
| 3751 | if (as->parms[6].items) |
| 3752 | XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP, |
| 3753 | count, int32list, fast, quiet); |
| 3754 | else |
| 3755 | XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP, |
| 3756 | count, int32list, fast, quiet); |
| 3757 | if (xInfoP) |
| 3758 | free(xInfoP); |
| 3759 | xInfoP = (volintXInfo *) 0; |
| 3760 | } else { |
| 3761 | if (as->parms[6].items) |
| 3762 | DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr, |
| 3763 | count); |
| 3764 | else |
| 3765 | DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr, |
| 3766 | count, int32list, fast, quiet); |
| 3767 | if (pntr) |
| 3768 | free(pntr); |
| 3769 | pntr = (volintInfo *) 0; |
| 3770 | } |
| 3771 | } |
| 3772 | } |
| 3773 | return 0; |
| 3774 | } |
| 3775 | |
| 3776 | static int |
| 3777 | SyncVldb(struct cmd_syndesc *as, void *arock) |
| 3778 | { |
| 3779 | afs_int32 pnum = 0, code; /* part name */ |
| 3780 | char part[10]; |
| 3781 | int flags = 0; |
| 3782 | char *volname = 0; |
| 3783 | |
| 3784 | tserver = 0; |
| 3785 | if (as->parms[0].items) { |
| 3786 | tserver = GetServer(as->parms[0].items->data); |
| 3787 | if (!tserver) { |
| 3788 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 3789 | as->parms[0].items->data); |
| 3790 | exit(1); |
| 3791 | } |
| 3792 | } |
| 3793 | |
| 3794 | if (as->parms[1].items) { |
| 3795 | pnum = volutil_GetPartitionID(as->parms[1].items->data); |
| 3796 | if (pnum < 0) { |
| 3797 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3798 | as->parms[1].items->data); |
| 3799 | exit(1); |
| 3800 | } |
| 3801 | if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */ |
| 3802 | if (code) |
| 3803 | PrintError("", code); |
| 3804 | else |
| 3805 | fprintf(STDERR__stderrp, |
| 3806 | "vos: partition %s does not exist on the server\n", |
| 3807 | as->parms[1].items->data); |
| 3808 | exit(1); |
| 3809 | } |
| 3810 | flags = 1; |
| 3811 | |
| 3812 | if (!tserver) { |
| 3813 | fprintf(STDERR__stderrp, |
| 3814 | "The -partition option requires a -server option\n"); |
| 3815 | exit(1); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | if (as->parms[3].items) { |
| 3820 | flags |= 2; /* don't update */ |
| 3821 | } |
| 3822 | |
| 3823 | if (as->parms[2].items) { |
| 3824 | /* Synchronize an individual volume */ |
| 3825 | volname = as->parms[2].items->data; |
| 3826 | code = UV_SyncVolume(tserver, pnum, volname, flags); |
| 3827 | } else { |
| 3828 | if (!tserver) { |
| 3829 | fprintf(STDERR__stderrp, |
| 3830 | "Without a -volume option, the -server option is required\n"); |
| 3831 | exit(1); |
| 3832 | } |
| 3833 | code = UV_SyncVldb(tserver, pnum, flags, 0 /*unused */ ); |
| 3834 | } |
| 3835 | |
| 3836 | if (code) { |
| 3837 | PrintDiagnostics("syncvldb", code); |
| 3838 | exit(1); |
| 3839 | } |
| 3840 | |
| 3841 | /* Print a summary of what we did */ |
| 3842 | if (volname) |
| 3843 | fprintf(STDOUT__stdoutp, "VLDB volume %s synchronized", volname); |
| 3844 | else |
| 3845 | fprintf(STDOUT__stdoutp, "VLDB synchronized"); |
| 3846 | if (tserver) { |
| 3847 | fprintf(STDOUT__stdoutp, " with state of server %s", as->parms[0].items->data); |
| 3848 | } |
| 3849 | if (flags & 1) { |
| 3850 | MapPartIdIntoName(pnum, part); |
| 3851 | fprintf(STDOUT__stdoutp, " partition %s\n", part); |
| 3852 | } |
| 3853 | fprintf(STDOUT__stdoutp, "\n"); |
| 3854 | |
| 3855 | return 0; |
| 3856 | } |
| 3857 | |
| 3858 | static int |
| 3859 | SyncServer(struct cmd_syndesc *as, void *arock) |
| 3860 | { |
| 3861 | afs_int32 pnum, code; /* part name */ |
| 3862 | char part[10]; |
| 3863 | |
| 3864 | int flags = 0; |
| 3865 | |
| 3866 | tserver = GetServer(as->parms[0].items->data); |
| 3867 | if (!tserver) { |
| 3868 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 3869 | as->parms[0].items->data); |
| 3870 | exit(1); |
| 3871 | } |
| 3872 | if (as->parms[1].items) { |
| 3873 | pnum = volutil_GetPartitionID(as->parms[1].items->data); |
| 3874 | if (pnum < 0) { |
| 3875 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3876 | as->parms[1].items->data); |
| 3877 | exit(1); |
| 3878 | } |
| 3879 | if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */ |
| 3880 | if (code) |
| 3881 | PrintError("", code); |
| 3882 | else |
| 3883 | fprintf(STDERR__stderrp, |
| 3884 | "vos : partition %s does not exist on the server\n", |
| 3885 | as->parms[1].items->data); |
| 3886 | exit(1); |
| 3887 | } |
| 3888 | flags = 1; |
| 3889 | } else { |
| 3890 | pnum = -1; |
| 3891 | } |
| 3892 | |
| 3893 | if (as->parms[2].items) { |
| 3894 | flags |= 2; /* don't update */ |
| 3895 | } |
| 3896 | code = UV_SyncServer(tserver, pnum, flags, 0 /*unused */ ); |
| 3897 | if (code) { |
| 3898 | PrintDiagnostics("syncserv", code); |
| 3899 | exit(1); |
| 3900 | } |
| 3901 | if (flags & 1) { |
| 3902 | MapPartIdIntoName(pnum, part); |
| 3903 | fprintf(STDOUT__stdoutp, "Server %s partition %s synchronized with VLDB\n", |
| 3904 | as->parms[0].items->data, part); |
| 3905 | } else |
| 3906 | fprintf(STDOUT__stdoutp, "Server %s synchronized with VLDB\n", |
| 3907 | as->parms[0].items->data); |
| 3908 | return 0; |
| 3909 | |
| 3910 | } |
| 3911 | |
| 3912 | static int |
| 3913 | VolumeInfoCmd(char *name) |
| 3914 | { |
| 3915 | struct nvldbentry entry; |
| 3916 | afs_int32 vcode; |
| 3917 | |
| 3918 | /* The vlserver will handle names with the .readonly |
| 3919 | * and .backup extension as well as volume ids. |
| 3920 | */ |
| 3921 | vcode = VLDB_GetEntryByName(name, &entry); |
| 3922 | if (vcode) { |
| 3923 | PrintError("", vcode); |
| 3924 | exit(1); |
| 3925 | } |
| 3926 | MapHostToNetwork(&entry); |
| 3927 | EnumerateEntry(&entry); |
| 3928 | |
| 3929 | /* Defect #3027: grubby check to handle locked volume. |
| 3930 | * If VLOP_ALLOPERS is set, the entry is locked. |
| 3931 | * Leave this routine as is, but put in correct check. |
| 3932 | */ |
| 3933 | PrintLocked(entry.flags); |
| 3934 | |
| 3935 | return 0; |
| 3936 | } |
| 3937 | |
| 3938 | static int |
| 3939 | VolumeZap(struct cmd_syndesc *as, void *arock) |
| 3940 | { |
| 3941 | struct nvldbentry entry; |
| 3942 | afs_uint32 volid, zapbackupid = 0, backupid = 0; |
| 3943 | afs_int32 code, server, part, err; |
| 3944 | |
| 3945 | if (as->parms[3].items) { |
| 3946 | /* force flag is on, use the other version */ |
| 3947 | return NukeVolume(as); |
| 3948 | } |
| 3949 | |
| 3950 | if (as->parms[4].items) { |
| 3951 | zapbackupid = 1; |
| 3952 | } |
| 3953 | |
| 3954 | volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err); |
| 3955 | if (volid == 0) { |
| 3956 | if (err) |
| 3957 | PrintError("", err); |
| 3958 | else |
| 3959 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 3960 | as->parms[2].items->data); |
| 3961 | exit(1); |
| 3962 | } |
| 3963 | part = volutil_GetPartitionID(as->parms[1].items->data); |
| 3964 | if (part < 0) { |
| 3965 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 3966 | as->parms[1].items->data); |
| 3967 | exit(1); |
| 3968 | } |
| 3969 | server = GetServer(as->parms[0].items->data); |
| 3970 | if (!server) { |
| 3971 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 3972 | as->parms[0].items->data); |
| 3973 | exit(1); |
| 3974 | } |
| 3975 | if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */ |
| 3976 | if (code) |
| 3977 | PrintError("", code); |
| 3978 | else |
| 3979 | fprintf(STDERR__stderrp, |
| 3980 | "vos : partition %s does not exist on the server\n", |
| 3981 | as->parms[1].items->data); |
| 3982 | exit(1); |
| 3983 | } |
| 3984 | code = VLDB_GetEntryByID(volid, -1, &entry); |
| 3985 | if (!code) { |
| 3986 | if (volid == entry.volumeId[RWVOL0]) |
| 3987 | backupid = entry.volumeId[BACKVOL2]; |
| 3988 | fprintf(STDERR__stderrp, |
| 3989 | "Warning: Entry for volume number %lu exists in VLDB (but we're zapping it anyway!)\n", |
| 3990 | (unsigned long)volid); |
| 3991 | } |
| 3992 | if (zapbackupid) { |
| 3993 | volintInfo *pntr = (volintInfo *) 0; |
| 3994 | |
| 3995 | if (!backupid) { |
| 3996 | code = UV_ListOneVolume(server, part, volid, &pntr); |
| 3997 | if (!code) { |
| 3998 | if (volid == pntr->parentID) |
| 3999 | backupid = pntr->backupID; |
| 4000 | if (pntr) |
| 4001 | free(pntr); |
| 4002 | } |
| 4003 | } |
| 4004 | if (backupid) { |
| 4005 | code = UV_VolumeZap(server, part, backupid); |
| 4006 | if (code) { |
| 4007 | PrintDiagnostics("zap", code); |
| 4008 | exit(1); |
| 4009 | } |
| 4010 | fprintf(STDOUT__stdoutp, "Backup Volume %lu deleted\n", |
| 4011 | (unsigned long)backupid); |
| 4012 | } |
| 4013 | } |
| 4014 | code = UV_VolumeZap(server, part, volid); |
| 4015 | if (code) { |
| 4016 | PrintDiagnostics("zap", code); |
| 4017 | exit(1); |
| 4018 | } |
| 4019 | fprintf(STDOUT__stdoutp, "Volume %lu deleted\n", (unsigned long)volid); |
| 4020 | |
| 4021 | return 0; |
| 4022 | } |
| 4023 | |
| 4024 | static int |
| 4025 | VolserStatus(struct cmd_syndesc *as, void *arock) |
| 4026 | { |
| 4027 | afs_uint32 server; |
| 4028 | afs_int32 code; |
| 4029 | transDebugInfo *pntr, *oldpntr; |
| 4030 | afs_int32 count; |
| 4031 | int i; |
| 4032 | char pname[10]; |
| 4033 | time_t t; |
| 4034 | |
| 4035 | server = GetServer(as->parms[0].items->data); |
| 4036 | if (!server) { |
| 4037 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 4038 | as->parms[0].items->data); |
| 4039 | exit(1); |
| 4040 | } |
| 4041 | code = UV_VolserStatus(server, &pntr, &count); |
| 4042 | if (code) { |
| 4043 | PrintDiagnostics("status", code); |
| 4044 | exit(1); |
| 4045 | } |
| 4046 | oldpntr = pntr; |
| 4047 | if (count == 0) |
| 4048 | fprintf(STDOUT__stdoutp, "No active transactions on %s\n", |
| 4049 | as->parms[0].items->data); |
| 4050 | else { |
| 4051 | fprintf(STDOUT__stdoutp, "Total transactions: %d\n", count); |
| 4052 | } |
| 4053 | for (i = 0; i < count; i++) { |
| 4054 | /*print out the relevant info */ |
| 4055 | fprintf(STDOUT__stdoutp, "--------------------------------------\n"); |
| 4056 | t = pntr->creationTime; |
| 4057 | fprintf(STDOUT__stdoutp, "transaction: %lu created: %s", |
| 4058 | (unsigned long)pntr->tid, ctime(&t)); |
| 4059 | t = pntr->time; |
| 4060 | fprintf(STDOUT__stdoutp, "lastActiveTime: %s", ctime(&t)); |
| 4061 | if (pntr->returnCode) { |
| 4062 | fprintf(STDOUT__stdoutp, "returnCode: %lu\n", |
| 4063 | (unsigned long)pntr->returnCode); |
| 4064 | } |
| 4065 | if (pntr->iflags) { |
| 4066 | fprintf(STDOUT__stdoutp, "attachFlags: "); |
| 4067 | switch (pntr->iflags) { |
| 4068 | case ITOffline1: |
| 4069 | fprintf(STDOUT__stdoutp, "offline "); |
| 4070 | break; |
| 4071 | case ITBusy2: |
| 4072 | fprintf(STDOUT__stdoutp, "busy "); |
| 4073 | break; |
| 4074 | case ITReadOnly8: |
| 4075 | fprintf(STDOUT__stdoutp, "readonly "); |
| 4076 | break; |
| 4077 | case ITCreate0x10: |
| 4078 | fprintf(STDOUT__stdoutp, "create "); |
| 4079 | break; |
| 4080 | case ITCreateVolID0x1000: |
| 4081 | fprintf(STDOUT__stdoutp, "create volid "); |
| 4082 | break; |
| 4083 | } |
| 4084 | fprintf(STDOUT__stdoutp, "\n"); |
| 4085 | } |
| 4086 | if (pntr->vflags) { |
| 4087 | fprintf(STDOUT__stdoutp, "volumeStatus: "); |
| 4088 | switch (pntr->vflags) { |
| 4089 | case VTDeleteOnSalvage1: |
| 4090 | fprintf(STDOUT__stdoutp, "deleteOnSalvage "); |
| 4091 | case VTOutOfService2: |
| 4092 | fprintf(STDOUT__stdoutp, "outOfService "); |
| 4093 | case VTDeleted4: |
| 4094 | fprintf(STDOUT__stdoutp, "deleted "); |
| 4095 | } |
| 4096 | fprintf(STDOUT__stdoutp, "\n"); |
| 4097 | } |
| 4098 | if (pntr->tflags) { |
| 4099 | fprintf(STDOUT__stdoutp, "transactionFlags: "); |
| 4100 | fprintf(STDOUT__stdoutp, "delete\n"); |
| 4101 | } |
| 4102 | MapPartIdIntoName(pntr->partition, pname); |
| 4103 | fprintf(STDOUT__stdoutp, "volume: %lu partition: %s procedure: %s\n", |
| 4104 | (unsigned long)pntr->volid, pname, pntr->lastProcName); |
| 4105 | if (pntr->callValid) { |
| 4106 | t = pntr->lastReceiveTime; |
| 4107 | fprintf(STDOUT__stdoutp, "packetRead: %lu lastReceiveTime: %s", |
| 4108 | (unsigned long)pntr->readNext, ctime(&t)); |
| 4109 | t = pntr->lastSendTime; |
| 4110 | fprintf(STDOUT__stdoutp, "packetSend: %lu lastSendTime: %s", |
| 4111 | (unsigned long)pntr->transmitNext, ctime(&t)); |
| 4112 | } |
| 4113 | pntr++; |
| 4114 | fprintf(STDOUT__stdoutp, "--------------------------------------\n"); |
| 4115 | fprintf(STDOUT__stdoutp, "\n"); |
| 4116 | } |
| 4117 | if (oldpntr) |
| 4118 | free(oldpntr); |
| 4119 | return 0; |
| 4120 | } |
| 4121 | |
| 4122 | static int |
| 4123 | RenameVolume(struct cmd_syndesc *as, void *arock) |
| 4124 | { |
| 4125 | afs_int32 code1, code2, code; |
| 4126 | struct nvldbentry entry; |
| 4127 | |
| 4128 | code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry); |
| 4129 | if (code1) { |
| 4130 | fprintf(STDERR__stderrp, "vos: Could not find entry for volume %s\n", |
| 4131 | as->parms[0].items->data); |
| 4132 | exit(1); |
| 4133 | } |
| 4134 | code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry); |
| 4135 | if ((!code1) && (!code2)) { /*the newname already exists */ |
| 4136 | fprintf(STDERR__stderrp, "vos: volume %s already exists\n", |
| 4137 | as->parms[1].items->data); |
| 4138 | exit(1); |
| 4139 | } |
| 4140 | |
| 4141 | if (code1 && code2) { |
| 4142 | fprintf(STDERR__stderrp, "vos: Could not find entry for volume %s or %s\n", |
| 4143 | as->parms[0].items->data, as->parms[1].items->data); |
| 4144 | exit(1); |
| 4145 | } |
| 4146 | if (!VolNameOK(as->parms[0].items->data)) { |
| 4147 | fprintf(STDERR__stderrp, |
| 4148 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 4149 | as->parms[0].items->data); |
| 4150 | exit(1); |
| 4151 | } |
| 4152 | if (!ISNAMEVALID(as->parms[1].items->data)(strlen(as->parms[1].items->data) < (32 - 9))) { |
| 4153 | fprintf(STDERR__stderrp, |
| 4154 | "vos: the new volume name %s exceeds the size limit of %d\n", |
| 4155 | as->parms[1].items->data, VOLSER_OLDMAXVOLNAME32 - 10); |
| 4156 | exit(1); |
| 4157 | } |
| 4158 | if (!VolNameOK(as->parms[1].items->data)) { |
| 4159 | fprintf(STDERR__stderrp, |
| 4160 | "Illegal volume name %s, should not end in .readonly or .backup\n", |
| 4161 | as->parms[1].items->data); |
| 4162 | exit(1); |
| 4163 | } |
| 4164 | if (IsNumeric(as->parms[1].items->data)) { |
| 4165 | fprintf(STDERR__stderrp, "Illegal volume name %s, should not be a number\n", |
| 4166 | as->parms[1].items->data); |
| 4167 | exit(1); |
| 4168 | } |
| 4169 | MapHostToNetwork(&entry); |
| 4170 | code = |
| 4171 | UV_RenameVolume(&entry, as->parms[0].items->data, |
| 4172 | as->parms[1].items->data); |
| 4173 | if (code) { |
| 4174 | PrintDiagnostics("rename", code); |
| 4175 | exit(1); |
| 4176 | } |
| 4177 | fprintf(STDOUT__stdoutp, "Renamed volume %s to %s\n", as->parms[0].items->data, |
| 4178 | as->parms[1].items->data); |
| 4179 | return 0; |
| 4180 | } |
| 4181 | |
| 4182 | int |
| 4183 | GetVolumeInfo(afs_uint32 volid, afs_uint32 *server, afs_int32 *part, afs_int32 *voltype, |
| 4184 | struct nvldbentry *rentry) |
| 4185 | { |
| 4186 | afs_int32 vcode; |
| 4187 | int i, index = -1; |
| 4188 | |
| 4189 | vcode = VLDB_GetEntryByID(volid, -1, rentry); |
| 4190 | if (vcode) { |
| 4191 | fprintf(STDERR__stderrp, |
| 4192 | "Could not fetch the entry for volume %lu from VLDB \n", |
| 4193 | (unsigned long)volid); |
| 4194 | PrintError("", vcode); |
| 4195 | return (vcode); |
| 4196 | } |
| 4197 | MapHostToNetwork(rentry); |
| 4198 | if (volid == rentry->volumeId[ROVOL1]) { |
| 4199 | *voltype = ROVOL1; |
| 4200 | for (i = 0; i < rentry->nServers; i++) { |
| 4201 | if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL0x02) |
| 4202 | && !(rentry->serverFlags[i] & RO_DONTUSE0x20)) |
| 4203 | index = i; |
| 4204 | } |
| 4205 | if (index == -1) { |
| 4206 | fprintf(STDERR__stderrp, |
| 4207 | "RO volume is not found in VLDB entry for volume %lu\n", |
| 4208 | (unsigned long)volid); |
| 4209 | return -1; |
| 4210 | } |
| 4211 | |
| 4212 | *server = rentry->serverNumber[index]; |
| 4213 | *part = rentry->serverPartition[index]; |
| 4214 | return 0; |
| 4215 | } |
| 4216 | |
| 4217 | index = Lp_GetRwIndex(rentry); |
| 4218 | if (index == -1) { |
| 4219 | fprintf(STDERR__stderrp, |
| 4220 | "RW Volume is not found in VLDB entry for volume %lu\n", |
| 4221 | (unsigned long)volid); |
| 4222 | return -1; |
| 4223 | } |
| 4224 | if (volid == rentry->volumeId[RWVOL0]) { |
| 4225 | *voltype = RWVOL0; |
| 4226 | *server = rentry->serverNumber[index]; |
| 4227 | *part = rentry->serverPartition[index]; |
| 4228 | return 0; |
| 4229 | } |
| 4230 | if (volid == rentry->volumeId[BACKVOL2]) { |
| 4231 | *voltype = BACKVOL2; |
| 4232 | *server = rentry->serverNumber[index]; |
| 4233 | *part = rentry->serverPartition[index]; |
| 4234 | return 0; |
| 4235 | } |
| 4236 | fprintf(STDERR__stderrp, |
| 4237 | "unexpected volume type for volume %lu\n", |
| 4238 | (unsigned long)volid); |
| 4239 | return -1; |
| 4240 | } |
| 4241 | |
| 4242 | static int |
| 4243 | DeleteEntry(struct cmd_syndesc *as, void *arock) |
| 4244 | { |
| 4245 | afs_int32 apart = 0; |
| 4246 | afs_uint32 avolid; |
| 4247 | afs_int32 vcode; |
| 4248 | struct VldbListByAttributes attributes; |
| 4249 | nbulkentries arrayEntries; |
| 4250 | struct nvldbentry *vllist; |
| 4251 | struct cmd_item *itp; |
| 4252 | afs_int32 nentries; |
| 4253 | int j; |
| 4254 | char prefix[VOLSER_MAXVOLNAME65 + 1]; |
| 4255 | int seenprefix = 0; |
| 4256 | afs_int32 totalBack = 0, totalFail = 0, err; |
| 4257 | |
| 4258 | if (as->parms[0].items) { /* -id */ |
| 4259 | if (as->parms[1].items || as->parms[2].items || as->parms[3].items) { |
| 4260 | fprintf(STDERR__stderrp, |
| 4261 | "You cannot use -server, -partition, or -prefix with the -id argument\n"); |
| 4262 | exit(-2); |
| 4263 | } |
| 4264 | for (itp = as->parms[0].items; itp; itp = itp->next) { |
| 4265 | avolid = vsu_GetVolumeID(itp->data, cstruct, &err); |
| 4266 | if (avolid == 0) { |
| 4267 | if (err) |
| 4268 | PrintError("", err); |
| 4269 | else |
| 4270 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 4271 | itp->data); |
| 4272 | continue; |
| 4273 | } |
| 4274 | if (as->parms[4].items || as->parms[5].items) { |
| 4275 | /* -noexecute (hidden) or -dryrun */ |
| 4276 | fprintf(STDOUT__stdoutp, "Would have deleted VLDB entry for %s \n", |
| 4277 | itp->data); |
| 4278 | fflush(STDOUT__stdoutp); |
| 4279 | continue; |
| 4280 | } |
| 4281 | vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL0); |
| 4282 | if (vcode) { |
| 4283 | fprintf(STDERR__stderrp, "Could not delete entry for volume %s\n", |
| 4284 | itp->data); |
| 4285 | fprintf(STDERR__stderrp, |
| 4286 | "You must specify a RW volume name or ID " |
| 4287 | "(the entire VLDB entry will be deleted)\n"); |
| 4288 | PrintError("", vcode); |
| 4289 | totalFail++; |
| 4290 | continue; |
| 4291 | } |
| 4292 | totalBack++; |
| 4293 | } |
| 4294 | fprintf(STDOUT__stdoutp, "Deleted %d VLDB entries\n", totalBack); |
| 4295 | return (totalFail); |
| 4296 | } |
| 4297 | |
| 4298 | if (!as->parms[1].items && !as->parms[2].items && !as->parms[3].items) { |
| 4299 | fprintf(STDERR__stderrp, "You must specify an option\n"); |
| 4300 | exit(-2); |
| 4301 | } |
| 4302 | |
| 4303 | /* Zero out search attributes */ |
| 4304 | memset(&attributes, 0, sizeof(struct VldbListByAttributes)); |
| 4305 | |
| 4306 | if (as->parms[1].items) { /* -prefix */ |
| 4307 | strncpy(prefix, as->parms[1].items->data, VOLSER_MAXVOLNAME65); |
| 4308 | seenprefix = 1; |
| 4309 | if (!as->parms[2].items && !as->parms[3].items) { /* a single entry only */ |
| 4310 | fprintf(STDERR__stderrp, |
| 4311 | "You must provide -server with the -prefix argument\n"); |
| 4312 | exit(-2); |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | if (as->parms[2].items) { /* -server */ |
| 4317 | afs_uint32 aserver; |
| 4318 | aserver = GetServer(as->parms[2].items->data); |
| 4319 | if (aserver == 0) { |
| 4320 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 4321 | as->parms[2].items->data); |
| 4322 | exit(-1); |
| 4323 | } |
| 4324 | 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)); |
| 4325 | attributes.Mask |= VLLIST_SERVER0x1; |
| 4326 | } |
| 4327 | |
| 4328 | if (as->parms[3].items) { /* -partition */ |
| 4329 | if (!as->parms[2].items) { |
| 4330 | fprintf(STDERR__stderrp, |
| 4331 | "You must provide -server with the -partition argument\n"); |
| 4332 | exit(-2); |
| 4333 | } |
| 4334 | apart = volutil_GetPartitionID(as->parms[3].items->data); |
| 4335 | if (apart < 0) { |
| 4336 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 4337 | as->parms[3].items->data); |
| 4338 | exit(-1); |
| 4339 | } |
| 4340 | attributes.partition = apart; |
| 4341 | attributes.Mask |= VLLIST_PARTITION0x2; |
| 4342 | } |
| 4343 | |
| 4344 | /* Print status line of what we are doing */ |
| 4345 | fprintf(STDOUT__stdoutp, "Deleting VLDB entries for "); |
| 4346 | if (as->parms[2].items) { |
| 4347 | fprintf(STDOUT__stdoutp, "server %s ", as->parms[2].items->data); |
| 4348 | } |
| 4349 | if (as->parms[3].items) { |
| 4350 | char pname[10]; |
| 4351 | MapPartIdIntoName(apart, pname); |
| 4352 | fprintf(STDOUT__stdoutp, "partition %s ", pname); |
| 4353 | } |
| 4354 | if (seenprefix) { |
| 4355 | fprintf(STDOUT__stdoutp, "which are prefixed with %s ", prefix); |
| 4356 | } |
| 4357 | fprintf(STDOUT__stdoutp, "\n"); |
| 4358 | fflush(STDOUT__stdoutp); |
| 4359 | |
| 4360 | /* Get all the VLDB entries on a server and/or partition */ |
| 4361 | memset(&arrayEntries, 0, sizeof(arrayEntries)); |
| 4362 | vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); |
| 4363 | if (vcode) { |
| 4364 | fprintf(STDERR__stderrp, "Could not access the VLDB for attributes\n"); |
| 4365 | PrintError("", vcode); |
| 4366 | exit(-1); |
| 4367 | } |
| 4368 | |
| 4369 | /* Process each entry */ |
| 4370 | for (j = 0; j < nentries; j++) { |
| 4371 | vllist = &arrayEntries.nbulkentries_val[j]; |
| 4372 | if (seenprefix) { |
| 4373 | /* It only deletes the RW volumes */ |
| 4374 | if (strncmp(vllist->name, prefix, strlen(prefix))) { |
| 4375 | if (verbose) { |
| 4376 | fprintf(STDOUT__stdoutp, |
| 4377 | "Omitting to delete %s due to prefix %s mismatch\n", |
| 4378 | vllist->name, prefix); |
| 4379 | } |
| 4380 | fflush(STDOUT__stdoutp); |
| 4381 | continue; |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | if (as->parms[4].items || as->parms[5].items) { |
| 4386 | /* -noexecute (hidden) or -dryrun */ |
| 4387 | fprintf(STDOUT__stdoutp, "Would have deleted VLDB entry for %s \n", |
| 4388 | vllist->name); |
| 4389 | fflush(STDOUT__stdoutp); |
| 4390 | continue; |
| 4391 | } |
| 4392 | |
| 4393 | /* Only matches the RW volume name */ |
| 4394 | avolid = vllist->volumeId[RWVOL0]; |
| 4395 | vcode = ubik_VL_DeleteEntry(cstruct, 0, avolid, RWVOL0); |
| 4396 | if (vcode) { |
| 4397 | fprintf(STDOUT__stdoutp, "Could not delete VLDB entry for %s\n", |
| 4398 | vllist->name); |
| 4399 | totalFail++; |
| 4400 | PrintError("", vcode); |
| 4401 | continue; |
| 4402 | } else { |
| 4403 | totalBack++; |
| 4404 | if (verbose) |
| 4405 | fprintf(STDOUT__stdoutp, "Deleted VLDB entry for %s \n", vllist->name); |
| 4406 | } |
| 4407 | fflush(STDOUT__stdoutp); |
| 4408 | } /*for */ |
| 4409 | |
| 4410 | fprintf(STDOUT__stdoutp, "----------------------\n"); |
| 4411 | fprintf(STDOUT__stdoutp, |
| 4412 | "Total VLDB entries deleted: %lu; failed to delete: %lu\n", |
| 4413 | (unsigned long)totalBack, (unsigned long)totalFail); |
| 4414 | |
| 4415 | xdr_freeafs_xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries); |
| 4416 | return 0; |
| 4417 | } |
| 4418 | |
| 4419 | |
| 4420 | static int |
| 4421 | CompareVldbEntryByName(const void *p1, const void *p2) |
| 4422 | { |
| 4423 | struct nvldbentry *arg1, *arg2; |
| 4424 | |
| 4425 | arg1 = (struct nvldbentry *)p1; |
| 4426 | arg2 = (struct nvldbentry *)p2; |
| 4427 | return (strcmp(arg1->name, arg2->name)); |
| 4428 | } |
| 4429 | |
| 4430 | /* |
| 4431 | static int CompareVldbEntry(char *p1, char *p2) |
| 4432 | { |
| 4433 | struct nvldbentry *arg1,*arg2; |
| 4434 | int i; |
| 4435 | int pos1, pos2; |
| 4436 | char comp1[100],comp2[100]; |
| 4437 | char temp1[20],temp2[20]; |
| 4438 | |
| 4439 | arg1 = (struct nvldbentry *)p1; |
| 4440 | arg2 = (struct nvldbentry *)p2; |
| 4441 | pos1 = -1; |
| 4442 | pos2 = -1; |
| 4443 | |
| 4444 | for(i = 0; i < arg1->nServers; i++) |
| 4445 | if(arg1->serverFlags[i] & ITSRWVOL) pos1 = i; |
| 4446 | for(i = 0; i < arg2->nServers; i++) |
| 4447 | if(arg2->serverFlags[i] & ITSRWVOL) pos2 = i; |
| 4448 | if(pos1 == -1 || pos2 == -1){ |
| 4449 | pos1 = 0; |
| 4450 | pos2 = 0; |
| 4451 | } |
| 4452 | sprintf(comp1,"%10u",arg1->serverNumber[pos1]); |
| 4453 | sprintf(comp2,"%10u",arg2->serverNumber[pos2]); |
| 4454 | sprintf(temp1,"%10u",arg1->serverPartition[pos1]); |
| 4455 | sprintf(temp2,"%10u",arg2->serverPartition[pos2]); |
| 4456 | strcat(comp1,temp1); |
| 4457 | strcat(comp2,temp2); |
| 4458 | strcat(comp1,arg1->name); |
| 4459 | strcat(comp1,arg2->name); |
| 4460 | return(strcmp(comp1,comp2)); |
| 4461 | |
| 4462 | } |
| 4463 | |
| 4464 | */ |
| 4465 | static int |
| 4466 | ListVLDB(struct cmd_syndesc *as, void *arock) |
| 4467 | { |
| 4468 | afs_int32 apart; |
| 4469 | afs_uint32 aserver; |
| 4470 | afs_int32 code; |
| 4471 | afs_int32 vcode; |
| 4472 | struct VldbListByAttributes attributes; |
| 4473 | nbulkentries arrayEntries; |
| 4474 | struct nvldbentry *vllist, *tarray = 0, *ttarray; |
| 4475 | afs_int32 centries, nentries = 0; |
| 4476 | afs_int32 tarraysize = 0; |
| 4477 | afs_int32 parraysize; |
| 4478 | int j; |
| 4479 | char pname[10]; |
| 4480 | int quiet, sort, lock; |
| 4481 | afs_int32 thisindex, nextindex; |
| 4482 | |
| 4483 | aserver = 0; |
| 4484 | apart = 0; |
| 4485 | |
| 4486 | attributes.Mask = 0; |
| 4487 | lock = (as->parms[3].items ? 1 : 0); /* -lock flag */ |
| 4488 | quiet = (as->parms[4].items ? 1 : 0); /* -quit flag */ |
| 4489 | sort = (as->parms[5].items ? 0 : 1); /* -nosort flag */ |
| 4490 | |
| 4491 | /* If the volume name is given, Use VolumeInfoCmd to look it up |
| 4492 | * and not ListAttributes. |
| 4493 | */ |
| 4494 | if (as->parms[0].items) { |
| 4495 | if (lock) { |
| 4496 | fprintf(STDERR__stderrp, |
| 4497 | "vos: illegal use of '-locked' switch, need to specify server and/or partition\n"); |
| 4498 | exit(1); |
| 4499 | } |
| 4500 | code = VolumeInfoCmd(as->parms[0].items->data); |
| 4501 | if (code) { |
| 4502 | PrintError("", code); |
| 4503 | exit(1); |
| 4504 | } |
| 4505 | return 0; |
| 4506 | } |
| 4507 | |
| 4508 | /* Server specified */ |
| 4509 | if (as->parms[1].items) { |
| 4510 | aserver = GetServer(as->parms[1].items->data); |
| 4511 | if (aserver == 0) { |
| 4512 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 4513 | as->parms[1].items->data); |
| 4514 | exit(1); |
| 4515 | } |
| 4516 | 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)); |
| 4517 | attributes.Mask |= VLLIST_SERVER0x1; |
| 4518 | } |
| 4519 | |
| 4520 | /* Partition specified */ |
| 4521 | if (as->parms[2].items) { |
| 4522 | apart = volutil_GetPartitionID(as->parms[2].items->data); |
| 4523 | if (apart < 0) { |
| 4524 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 4525 | as->parms[2].items->data); |
| 4526 | exit(1); |
| 4527 | } |
| 4528 | attributes.partition = apart; |
| 4529 | attributes.Mask |= VLLIST_PARTITION0x2; |
| 4530 | } |
| 4531 | |
| 4532 | if (lock) { |
| 4533 | attributes.Mask |= VLLIST_FLAG0x10; |
| 4534 | attributes.flag = VLOP_ALLOPERS( 0x10 | 0x20 | 0x40 | 0x80 | 0x100); |
| 4535 | } |
| 4536 | |
| 4537 | /* Print header information */ |
| 4538 | if (!quiet) { |
| 4539 | MapPartIdIntoName(apart, pname); |
| 4540 | fprintf(STDOUT__stdoutp, "VLDB entries for %s %s%s%s %s\n", |
| 4541 | (as->parms[1].items ? "server" : "all"), |
| 4542 | (as->parms[1].items ? as->parms[1].items->data : "servers"), |
| 4543 | (as->parms[2].items ? " partition " : ""), |
| 4544 | (as->parms[2].items ? pname : ""), |
| 4545 | (lock ? "which are locked:" : "")); |
| 4546 | } |
| 4547 | |
| 4548 | for (thisindex = 0; (thisindex != -1); thisindex = nextindex) { |
| 4549 | memset(&arrayEntries, 0, sizeof(arrayEntries)); |
| 4550 | centries = 0; |
| 4551 | nextindex = -1; |
| 4552 | |
| 4553 | vcode = |
| 4554 | VLDB_ListAttributesN2(&attributes, 0, thisindex, ¢ries, |
| 4555 | &arrayEntries, &nextindex); |
| 4556 | if (vcode == RXGEN_OPCODE-455) { |
| 4557 | /* Vlserver not running with ListAttributesN2. Fall back */ |
| 4558 | vcode = |
| 4559 | VLDB_ListAttributes(&attributes, ¢ries, &arrayEntries); |
| 4560 | nextindex = -1; |
| 4561 | } |
| 4562 | if (vcode) { |
| 4563 | fprintf(STDERR__stderrp, "Could not access the VLDB for attributes\n"); |
| 4564 | PrintError("", vcode); |
| 4565 | exit(1); |
| 4566 | } |
| 4567 | nentries += centries; |
| 4568 | |
| 4569 | /* We don't sort, so just print the entries now */ |
| 4570 | if (!sort) { |
| 4571 | for (j = 0; j < centries; j++) { /* process each entry */ |
| 4572 | vllist = &arrayEntries.nbulkentries_val[j]; |
| 4573 | MapHostToNetwork(vllist); |
| 4574 | EnumerateEntry(vllist); |
| 4575 | |
| 4576 | PrintLocked(vllist->flags); |
| 4577 | } |
| 4578 | } |
| 4579 | |
| 4580 | /* So we sort. First we must collect all the entries and keep |
| 4581 | * them in memory. |
| 4582 | */ |
| 4583 | else if (centries > 0) { |
| 4584 | if (!tarray) { |
| 4585 | /* malloc the first bulk entries array */ |
| 4586 | tarraysize = centries * sizeof(struct nvldbentry); |
| 4587 | tarray = malloc(tarraysize); |
| 4588 | if (!tarray) { |
| 4589 | fprintf(STDERR__stderrp, |
| 4590 | "Could not allocate enough space for the VLDB entries\n"); |
| 4591 | goto bypass; |
| 4592 | } |
| 4593 | memcpy((char*)tarray, arrayEntries.nbulkentries_val, tarraysize); |
| 4594 | } else { |
| 4595 | /* Grow the tarray to keep the extra entries */ |
| 4596 | parraysize = (centries * sizeof(struct nvldbentry)); |
| 4597 | ttarray = |
| 4598 | (struct nvldbentry *)realloc(tarray, |
| 4599 | tarraysize + parraysize); |
| 4600 | if (!ttarray) { |
| 4601 | fprintf(STDERR__stderrp, |
| 4602 | "Could not allocate enough space for the VLDB entries\n"); |
| 4603 | goto bypass; |
| 4604 | } |
| 4605 | tarray = ttarray; |
| 4606 | |
| 4607 | /* Copy them in */ |
| 4608 | memcpy(((char *)tarray) + tarraysize, |
| 4609 | (char *)arrayEntries.nbulkentries_val, parraysize); |
| 4610 | tarraysize += parraysize; |
| 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | /* Free the bulk array */ |
| 4615 | xdr_freeafs_xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries); |
| 4616 | } |
| 4617 | |
| 4618 | /* Here is where we now sort all the entries and print them */ |
| 4619 | if (sort && (nentries > 0)) { |
| 4620 | qsort((char *)tarray, nentries, sizeof(struct nvldbentry), |
| 4621 | CompareVldbEntryByName); |
| 4622 | for (vllist = tarray, j = 0; j < nentries; j++, vllist++) { |
| 4623 | MapHostToNetwork(vllist); |
| 4624 | EnumerateEntry(vllist); |
| 4625 | |
| 4626 | PrintLocked(vllist->flags); |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | bypass: |
| 4631 | if (!quiet) |
| 4632 | fprintf(STDOUT__stdoutp, "\nTotal entries: %lu\n", (unsigned long)nentries); |
| 4633 | if (tarray) |
| 4634 | free(tarray); |
| 4635 | return 0; |
| 4636 | } |
| 4637 | |
| 4638 | static int |
| 4639 | BackSys(struct cmd_syndesc *as, void *arock) |
| 4640 | { |
| 4641 | afs_uint32 avolid; |
| 4642 | afs_int32 apart = 0; |
| 4643 | afs_uint32 aserver = 0, aserver1; |
| 4644 | afs_int32 code, apart1; |
| 4645 | afs_int32 vcode; |
| 4646 | struct VldbListByAttributes attributes; |
| 4647 | nbulkentries arrayEntries; |
| 4648 | struct nvldbentry *vllist; |
| 4649 | afs_int32 nentries; |
| 4650 | int j; |
| 4651 | char pname[10]; |
| 4652 | int seenprefix, seenxprefix, exclude, ex, exp, noaction; |
| 4653 | afs_int32 totalBack = 0; |
| 4654 | afs_int32 totalFail = 0; |
| 4655 | int previdx = -1; |
| 4656 | int error; |
| 4657 | int same = 0; |
| 4658 | struct cmd_item *ti; |
| 4659 | int match = 0; |
| 4660 | #ifndef HAVE_POSIX_REGEX1 |
| 4661 | char *ccode; |
| 4662 | #endif |
| 4663 | |
| 4664 | memset(&attributes, 0, sizeof(struct VldbListByAttributes)); |
| 4665 | attributes.Mask = 0; |
| 4666 | |
| 4667 | seenprefix = (as->parms[0].items ? 1 : 0); |
| 4668 | exclude = (as->parms[3].items ? 1 : 0); |
| 4669 | seenxprefix = (as->parms[4].items ? 1 : 0); |
| 4670 | noaction = (as->parms[5].items ? 1 : 0); |
| 4671 | |
| 4672 | if (as->parms[1].items) { /* -server */ |
| 4673 | aserver = GetServer(as->parms[1].items->data); |
| 4674 | if (aserver == 0) { |
| 4675 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 4676 | as->parms[1].items->data); |
| 4677 | exit(1); |
| 4678 | } |
| 4679 | 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)); |
| 4680 | attributes.Mask |= VLLIST_SERVER0x1; |
| 4681 | } |
| 4682 | |
| 4683 | if (as->parms[2].items) { /* -partition */ |
| 4684 | apart = volutil_GetPartitionID(as->parms[2].items->data); |
| 4685 | if (apart < 0) { |
| 4686 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 4687 | as->parms[2].items->data); |
| 4688 | exit(1); |
| 4689 | } |
| 4690 | attributes.partition = apart; |
| 4691 | attributes.Mask |= VLLIST_PARTITION0x2; |
| 4692 | } |
| 4693 | |
| 4694 | /* Check to make sure the prefix and xprefix expressions compile ok */ |
| 4695 | if (seenprefix) { |
| 4696 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 4697 | if (strncmp(ti->data, "^", 1) == 0) { |
| 4698 | #ifdef HAVE_POSIX_REGEX1 |
| 4699 | regex_t re; |
| 4700 | char errbuf[256]; |
| 4701 | |
| 4702 | code = regcomp(&re, ti->data, REG_NOSUB0004); |
| 4703 | if (code != 0) { |
| 4704 | regerror(code, &re, errbuf, sizeof errbuf); |
| 4705 | fprintf(STDERR__stderrp, |
| 4706 | "Unrecognizable -prefix regular expression: '%s': %s\n", |
| 4707 | ti->data, errbuf); |
| 4708 | exit(1); |
| 4709 | } |
| 4710 | regfree(&re); |
| 4711 | #else |
| 4712 | ccode = (char *)re_comp(ti->data); |
| 4713 | if (ccode) { |
| 4714 | fprintf(STDERR__stderrp, |
| 4715 | "Unrecognizable -prefix regular expression: '%s': %s\n", |
| 4716 | ti->data, ccode); |
| 4717 | exit(1); |
| 4718 | } |
| 4719 | #endif |
| 4720 | } |
| 4721 | } |
| 4722 | } |
| 4723 | if (seenxprefix) { |
| 4724 | for (ti = as->parms[4].items; ti; ti = ti->next) { |
| 4725 | if (strncmp(ti->data, "^", 1) == 0) { |
| 4726 | #ifdef HAVE_POSIX_REGEX1 |
| 4727 | regex_t re; |
| 4728 | char errbuf[256]; |
| 4729 | |
| 4730 | code = regcomp(&re, ti->data, REG_NOSUB0004); |
| 4731 | if (code != 0) { |
| 4732 | regerror(code, &re, errbuf, sizeof errbuf); |
| 4733 | fprintf(STDERR__stderrp, |
| 4734 | "Unrecognizable -xprefix regular expression: '%s': %s\n", |
| 4735 | ti->data, errbuf); |
| 4736 | exit(1); |
| 4737 | } |
| 4738 | regfree(&re); |
| 4739 | #else |
| 4740 | ccode = (char *)re_comp(ti->data); |
| 4741 | if (ccode) { |
| 4742 | fprintf(STDERR__stderrp, |
| 4743 | "Unrecognizable -xprefix regular expression: '%s': %s\n", |
| 4744 | ti->data, ccode); |
| 4745 | exit(1); |
| 4746 | } |
| 4747 | #endif |
| 4748 | } |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | memset(&arrayEntries, 0, sizeof(arrayEntries)); /* initialize to hint the stub to alloc space */ |
| 4753 | vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); |
| 4754 | if (vcode) { |
| 4755 | fprintf(STDERR__stderrp, "Could not access the VLDB for attributes\n"); |
| 4756 | PrintError("", vcode); |
| 4757 | exit(1); |
| 4758 | } |
| 4759 | |
| 4760 | if (as->parms[1].items || as->parms[2].items || verbose) { |
| 4761 | fprintf(STDOUT__stdoutp, "%s up volumes", |
| 4762 | (noaction ? "Would have backed" : "Backing")); |
| 4763 | |
| 4764 | if (as->parms[1].items) { |
| 4765 | fprintf(STDOUT__stdoutp, " on server %s", as->parms[1].items->data); |
| 4766 | } else if (as->parms[2].items) { |
| 4767 | fprintf(STDOUT__stdoutp, " for all servers"); |
| 4768 | } |
| 4769 | |
| 4770 | if (as->parms[2].items) { |
| 4771 | MapPartIdIntoName(apart, pname); |
| 4772 | fprintf(STDOUT__stdoutp, " partition %s", pname); |
| 4773 | } |
| 4774 | |
| 4775 | if (seenprefix || (!seenprefix && seenxprefix)) { |
| 4776 | ti = (seenprefix ? as->parms[0].items : as->parms[4].items); |
| 4777 | ex = (seenprefix ? exclude : !exclude); |
| 4778 | exp = (strncmp(ti->data, "^", 1) == 0); |
| 4779 | fprintf(STDOUT__stdoutp, " which %smatch %s '%s'", (ex ? "do not " : ""), |
| 4780 | (exp ? "expression" : "prefix"), ti->data); |
| 4781 | for (ti = ti->next; ti; ti = ti->next) { |
| 4782 | exp = (strncmp(ti->data, "^", 1) == 0); |
| 4783 | printf(" %sor %s '%s'", (ex ? "n" : ""), |
| 4784 | (exp ? "expression" : "prefix"), ti->data); |
| 4785 | } |
| 4786 | } |
| 4787 | |
| 4788 | if (seenprefix && seenxprefix) { |
| 4789 | ti = as->parms[4].items; |
| 4790 | exp = (strncmp(ti->data, "^", 1) == 0); |
| 4791 | fprintf(STDOUT__stdoutp, " %swhich match %s '%s'", |
| 4792 | (exclude ? "adding those " : "removing those "), |
| 4793 | (exp ? "expression" : "prefix"), ti->data); |
| 4794 | for (ti = ti->next; ti; ti = ti->next) { |
| 4795 | exp = (strncmp(ti->data, "^", 1) == 0); |
| 4796 | printf(" or %s '%s'", (exp ? "expression" : "prefix"), |
| 4797 | ti->data); |
| 4798 | } |
| 4799 | } |
| 4800 | fprintf(STDOUT__stdoutp, " .. "); |
| 4801 | if (verbose) |
| 4802 | fprintf(STDOUT__stdoutp, "\n"); |
| 4803 | fflush(STDOUT__stdoutp); |
| 4804 | } |
| 4805 | |
| 4806 | for (j = 0; j < nentries; j++) { /* process each vldb entry */ |
| 4807 | vllist = &arrayEntries.nbulkentries_val[j]; |
| 4808 | |
| 4809 | if (seenprefix) { |
| 4810 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 4811 | if (strncmp(ti->data, "^", 1) == 0) { |
| 4812 | #ifdef HAVE_POSIX_REGEX1 |
| 4813 | regex_t re; |
| 4814 | char errbuf[256]; |
| 4815 | |
| 4816 | /* XXX -- should just do the compile once! */ |
| 4817 | code = regcomp(&re, ti->data, REG_NOSUB0004); |
| 4818 | if (code != 0) { |
| 4819 | regerror(code, &re, errbuf, sizeof errbuf); |
| 4820 | fprintf(STDERR__stderrp, |
| 4821 | "Error in -prefix regular expression: '%s': %s\n", |
| 4822 | ti->data, errbuf); |
| 4823 | exit(1); |
| 4824 | } |
| 4825 | match = (regexec(&re, vllist->name, 0, NULL((void *)0), 0) == 0); |
| 4826 | regfree(&re); |
| 4827 | #else |
| 4828 | ccode = (char *)re_comp(ti->data); |
| 4829 | if (ccode) { |
| 4830 | fprintf(STDERR__stderrp, |
| 4831 | "Error in -prefix regular expression: '%s': %s\n", |
| 4832 | ti->data, ccode); |
| 4833 | exit(1); |
| 4834 | } |
| 4835 | match = (re_exec(vllist->name) == 1); |
| 4836 | #endif |
| 4837 | } else { |
| 4838 | match = |
| 4839 | (strncmp(vllist->name, ti->data, strlen(ti->data)) == |
| 4840 | 0); |
| 4841 | } |
| 4842 | if (match) |
| 4843 | break; |
| 4844 | } |
| 4845 | } else { |
| 4846 | match = 1; |
| 4847 | } |
| 4848 | |
| 4849 | /* Without the -exclude flag: If it matches the prefix, then |
| 4850 | * check if we want to exclude any from xprefix. |
| 4851 | * With the -exclude flag: If it matches the prefix, then |
| 4852 | * check if we want to add any from xprefix. |
| 4853 | */ |
| 4854 | if (match && seenxprefix) { |
| 4855 | for (ti = as->parms[4].items; ti; ti = ti->next) { |
| 4856 | if (strncmp(ti->data, "^", 1) == 0) { |
| 4857 | #ifdef HAVE_POSIX_REGEX1 |
| 4858 | regex_t re; |
| 4859 | char errbuf[256]; |
| 4860 | |
| 4861 | /* XXX -- should just do the compile once! */ |
| 4862 | code = regcomp(&re, ti->data, REG_NOSUB0004); |
| 4863 | if (code != 0) { |
| 4864 | regerror(code, &re, errbuf, sizeof errbuf); |
| 4865 | fprintf(STDERR__stderrp, |
| 4866 | "Error in -xprefix regular expression: '%s': %s\n", |
| 4867 | ti->data, errbuf); |
| 4868 | exit(1); |
| 4869 | } |
| 4870 | if (regexec(&re, vllist->name, 0, NULL((void *)0), 0) == 0) |
| 4871 | match = 0; |
| 4872 | regfree(&re); |
| 4873 | #else |
| 4874 | ccode = (char *)re_comp(ti->data); |
| 4875 | if (ccode) { |
| 4876 | fprintf(STDERR__stderrp, |
| 4877 | "Error in -xprefix regular expression: '%s': %s\n", |
| 4878 | ti->data, ccode); |
| 4879 | exit(1); |
| 4880 | } |
| 4881 | if (re_exec(vllist->name) == 1) { |
| 4882 | match = 0; |
| 4883 | break; |
| 4884 | } |
| 4885 | #endif |
| 4886 | } else { |
| 4887 | if (strncmp(vllist->name, ti->data, strlen(ti->data)) == |
| 4888 | 0) { |
| 4889 | match = 0; |
| 4890 | break; |
| 4891 | } |
| 4892 | } |
| 4893 | } |
| 4894 | } |
| 4895 | |
| 4896 | if (exclude) |
| 4897 | match = !match; /* -exclude will reverse the match */ |
| 4898 | if (!match) |
| 4899 | continue; /* Skip if no match */ |
| 4900 | |
| 4901 | /* Print list of volumes to backup */ |
| 4902 | if (noaction) { |
| 4903 | fprintf(STDOUT__stdoutp, " %s\n", vllist->name); |
| 4904 | continue; |
| 4905 | } |
| 4906 | |
| 4907 | if (!(vllist->flags & RW_EXISTS0x1000)) { |
| 4908 | if (verbose) { |
| 4909 | fprintf(STDOUT__stdoutp, |
| 4910 | "Omitting to backup %s since RW volume does not exist \n", |
| 4911 | vllist->name); |
| 4912 | fprintf(STDOUT__stdoutp, "\n"); |
| 4913 | } |
| 4914 | fflush(STDOUT__stdoutp); |
| 4915 | continue; |
| 4916 | } |
| 4917 | |
| 4918 | avolid = vllist->volumeId[RWVOL0]; |
| 4919 | MapHostToNetwork(vllist); |
| 4920 | GetServerAndPart(vllist, RWVOL0, &aserver1, &apart1, &previdx); |
| 4921 | if (aserver1 == -1 || apart1 == -1) { |
| 4922 | fprintf(STDOUT__stdoutp, "could not backup %s, invalid VLDB entry\n", |
| 4923 | vllist->name); |
| 4924 | totalFail++; |
| 4925 | continue; |
| 4926 | } |
| 4927 | if (aserver) { |
| 4928 | same = VLDB_IsSameAddrs(aserver, aserver1, &error); |
| 4929 | if (error) { |
| 4930 | fprintf(STDERR__stderrp, |
| 4931 | "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", |
| 4932 | aserver, error); |
| 4933 | totalFail++; |
| 4934 | continue; |
| 4935 | } |
| 4936 | } |
| 4937 | if ((aserver && !same) || (apart && (apart != apart1))) { |
| 4938 | if (verbose) { |
| 4939 | fprintf(STDOUT__stdoutp, |
| 4940 | "Omitting to backup %s since the RW is in a different location\n", |
| 4941 | vllist->name); |
| 4942 | } |
| 4943 | continue; |
| 4944 | } |
| 4945 | if (verbose) { |
| 4946 | time_t now = time(0); |
| 4947 | fprintf(STDOUT__stdoutp, "Creating backup volume for %s on %s", |
| 4948 | vllist->name, ctime(&now)); |
| 4949 | fflush(STDOUT__stdoutp); |
| 4950 | } |
| 4951 | |
| 4952 | code = UV_BackupVolume(aserver1, apart1, avolid); |
| 4953 | if (code) { |
| 4954 | fprintf(STDOUT__stdoutp, "Could not backup %s\n", vllist->name); |
| 4955 | totalFail++; |
| 4956 | } else { |
| 4957 | totalBack++; |
| 4958 | } |
| 4959 | if (verbose) |
| 4960 | fprintf(STDOUT__stdoutp, "\n"); |
| 4961 | fflush(STDOUT__stdoutp); |
| 4962 | } /* process each vldb entry */ |
| 4963 | fprintf(STDOUT__stdoutp, "done\n"); |
| 4964 | fprintf(STDOUT__stdoutp, "Total volumes backed up: %lu; failed to backup: %lu\n", |
| 4965 | (unsigned long)totalBack, (unsigned long)totalFail); |
| 4966 | fflush(STDOUT__stdoutp); |
| 4967 | xdr_freeafs_xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries); |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
| 4971 | static int |
| 4972 | UnlockVLDB(struct cmd_syndesc *as, void *arock) |
| 4973 | { |
| 4974 | afs_int32 apart; |
| 4975 | afs_uint32 aserver = 0; |
| 4976 | afs_int32 code; |
| 4977 | afs_int32 vcode; |
| 4978 | struct VldbListByAttributes attributes; |
| 4979 | nbulkentries arrayEntries; |
| 4980 | struct nvldbentry *vllist; |
| 4981 | afs_int32 nentries; |
| 4982 | int j; |
| 4983 | afs_uint32 volid; |
| 4984 | afs_int32 totalE; |
| 4985 | char pname[10]; |
| 4986 | |
| 4987 | apart = -1; |
| 4988 | totalE = 0; |
| 4989 | attributes.Mask = 0; |
| 4990 | |
| 4991 | if (as->parms[0].items) { /* server specified */ |
| 4992 | aserver = GetServer(as->parms[0].items->data); |
| 4993 | if (aserver == 0) { |
| 4994 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 4995 | as->parms[0].items->data); |
| 4996 | exit(1); |
| 4997 | } |
| 4998 | 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)); |
| 4999 | attributes.Mask |= VLLIST_SERVER0x1; |
| 5000 | } |
| 5001 | if (as->parms[1].items) { /* partition specified */ |
| 5002 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 5003 | if (apart < 0) { |
| 5004 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 5005 | as->parms[1].items->data); |
| 5006 | exit(1); |
| 5007 | } |
| 5008 | if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ |
| 5009 | if (code) |
| 5010 | PrintError("", code); |
| 5011 | else |
| 5012 | fprintf(STDERR__stderrp, |
| 5013 | "vos : partition %s does not exist on the server\n", |
| 5014 | as->parms[1].items->data); |
| 5015 | exit(1); |
| 5016 | } |
| 5017 | attributes.partition = apart; |
| 5018 | attributes.Mask |= VLLIST_PARTITION0x2; |
| 5019 | } |
| 5020 | attributes.flag = VLOP_ALLOPERS( 0x10 | 0x20 | 0x40 | 0x80 | 0x100); |
| 5021 | attributes.Mask |= VLLIST_FLAG0x10; |
| 5022 | memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */ |
| 5023 | vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries); |
| 5024 | if (vcode) { |
| 5025 | fprintf(STDERR__stderrp, "Could not access the VLDB for attributes\n"); |
| 5026 | PrintError("", vcode); |
| 5027 | exit(1); |
| 5028 | } |
| 5029 | for (j = 0; j < nentries; j++) { /* process each entry */ |
| 5030 | vllist = &arrayEntries.nbulkentries_val[j]; |
| 5031 | volid = vllist->volumeId[RWVOL0]; |
| 5032 | vcode = |
| 5033 | ubik_VL_ReleaseLock(cstruct, 0, volid, -1, |
| 5034 | LOCKREL_OPCODE2 | LOCKREL_AFSID4 | |
| 5035 | LOCKREL_TIMESTAMP1); |
| 5036 | if (vcode) { |
| 5037 | fprintf(STDERR__stderrp, "Could not unlock entry for volume %s\n", |
| 5038 | vllist->name); |
| 5039 | PrintError("", vcode); |
| 5040 | totalE++; |
| 5041 | } |
| 5042 | |
| 5043 | } |
| 5044 | MapPartIdIntoName(apart, pname); |
| 5045 | if (totalE) |
| 5046 | fprintf(STDOUT__stdoutp, |
| 5047 | "Could not lock %lu VLDB entries of %lu locked entries\n", |
| 5048 | (unsigned long)totalE, (unsigned long)nentries); |
| 5049 | else { |
| 5050 | if (as->parms[0].items) { |
| 5051 | fprintf(STDOUT__stdoutp, |
| 5052 | "Unlocked all the VLDB entries for volumes on server %s ", |
| 5053 | as->parms[0].items->data); |
| 5054 | if (as->parms[1].items) { |
| 5055 | MapPartIdIntoName(apart, pname); |
| 5056 | fprintf(STDOUT__stdoutp, "partition %s\n", pname); |
| 5057 | } else |
| 5058 | fprintf(STDOUT__stdoutp, "\n"); |
| 5059 | |
| 5060 | } else if (as->parms[1].items) { |
| 5061 | MapPartIdIntoName(apart, pname); |
| 5062 | fprintf(STDOUT__stdoutp, |
| 5063 | "Unlocked all the VLDB entries for volumes on partition %s on all servers\n", |
| 5064 | pname); |
| 5065 | } |
| 5066 | } |
| 5067 | |
| 5068 | xdr_freeafs_xdr_free((xdrproc_t) xdr_nbulkentries, &arrayEntries); |
| 5069 | return 0; |
| 5070 | } |
| 5071 | |
| 5072 | static char * |
| 5073 | PrintInt64Size(afs_uint64 in) |
| 5074 | { |
| 5075 | afs_uint32 hi, lo; |
| 5076 | char * units; |
| 5077 | static char output[16]; |
| 5078 | |
| 5079 | SplitInt64(in,hi,lo)(hi) = ((afs_int64)in) >> 32; (lo) = (in) & 0xFFFFFFFF ;; |
| 5080 | |
| 5081 | if (hi == 0) { |
| 5082 | units = "KB"; |
| 5083 | } else if (!(hi & 0xFFFFFC00)) { |
| 5084 | units = "MB"; |
| 5085 | lo = (hi << 22) | (lo >> 10); |
| 5086 | } else if (!(hi & 0xFFF00000)) { |
| 5087 | units = "GB"; |
| 5088 | lo = (hi << 12) | (lo >> 20); |
| 5089 | } else if (!(hi & 0xC0000000)) { |
| 5090 | units = "TB"; |
| 5091 | lo = (hi << 2) | (lo >> 30); |
| 5092 | } else { |
| 5093 | units = "PB"; |
| 5094 | lo = (hi >> 8); |
| 5095 | } |
| 5096 | sprintf(output,"%u %s", lo, units); |
| 5097 | return output; |
| 5098 | } |
| 5099 | |
| 5100 | static int |
| 5101 | PartitionInfo(struct cmd_syndesc *as, void *arock) |
| 5102 | { |
| 5103 | afs_int32 apart; |
| 5104 | afs_uint32 aserver; |
| 5105 | afs_int32 code; |
| 5106 | char pname[10]; |
| 5107 | struct diskPartition64 partition; |
| 5108 | struct partList dummyPartList; |
| 5109 | int i, cnt; |
| 5110 | int printSummary=0, sumPartitions=0; |
| 5111 | afs_uint64 sumFree, sumStorage; |
| 5112 | |
| 5113 | ZeroInt64(sumFree)(sumFree = 0); |
| 5114 | ZeroInt64(sumStorage)(sumStorage = 0); |
| 5115 | apart = -1; |
| 5116 | aserver = GetServer(as->parms[0].items->data); |
| 5117 | if (aserver == 0) { |
| 5118 | fprintf(STDERR__stderrp, "vos: server '%s' not found in host table\n", |
| 5119 | as->parms[0].items->data); |
| 5120 | exit(1); |
| 5121 | } |
| 5122 | if (as->parms[1].items) { |
| 5123 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 5124 | if (apart < 0) { |
| 5125 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 5126 | as->parms[1].items->data); |
| 5127 | exit(1); |
| 5128 | } |
| 5129 | dummyPartList.partId[0] = apart; |
| 5130 | dummyPartList.partFlags[0] = PARTVALID0x01; |
| 5131 | cnt = 1; |
| 5132 | } |
| 5133 | if (as->parms[2].items) { |
| 5134 | printSummary = 1; |
| 5135 | } |
| 5136 | if (apart != -1) { |
| 5137 | if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */ |
| 5138 | if (code) |
| 5139 | PrintError("", code); |
| 5140 | else |
| 5141 | fprintf(STDERR__stderrp, |
| 5142 | "vos : partition %s does not exist on the server\n", |
| 5143 | as->parms[1].items->data); |
| 5144 | exit(1); |
| 5145 | } |
| 5146 | } else { |
| 5147 | code = UV_ListPartitions(aserver, &dummyPartList, &cnt); |
| 5148 | if (code) { |
| 5149 | PrintDiagnostics("listpart", code); |
| 5150 | exit(1); |
| 5151 | } |
| 5152 | } |
| 5153 | for (i = 0; i < cnt; i++) { |
| 5154 | if (dummyPartList.partFlags[i] & PARTVALID0x01) { |
| 5155 | MapPartIdIntoName(dummyPartList.partId[i], pname); |
| 5156 | code = UV_PartitionInfo64(aserver, pname, &partition); |
| 5157 | if (code) { |
| 5158 | fprintf(STDERR__stderrp, "Could not get information on partition %s\n", |
| 5159 | pname); |
| 5160 | PrintError("", code); |
| 5161 | exit(1); |
| 5162 | } |
| 5163 | fprintf(STDOUT__stdoutp, |
| 5164 | "Free space on partition %s: %" AFS_INT64_FMT"lld" " K blocks out of total %" AFS_INT64_FMT"lld" "\n", |
| 5165 | pname, partition.free, partition.minFree); |
| 5166 | sumPartitions++; |
| 5167 | AddUInt64(sumFree,partition.free,&sumFree)*(&sumFree) = (afs_uint64)(sumFree) + (afs_uint64)(partition .free); |
| 5168 | AddUInt64(sumStorage,partition.minFree,&sumStorage)*(&sumStorage) = (afs_uint64)(sumStorage) + (afs_uint64)( partition.minFree); |
| 5169 | } |
| 5170 | } |
| 5171 | if (printSummary) { |
| 5172 | fprintf(STDOUT__stdoutp, |
| 5173 | "Summary: %s free out of ", |
| 5174 | PrintInt64Size(sumFree)); |
| 5175 | fprintf(STDOUT__stdoutp, |
| 5176 | "%s on %d partitions\n", |
| 5177 | PrintInt64Size(sumStorage), |
| 5178 | sumPartitions); |
| 5179 | } |
| 5180 | return 0; |
| 5181 | } |
| 5182 | |
| 5183 | static int |
| 5184 | ChangeAddr(struct cmd_syndesc *as, void *arock) |
| 5185 | { |
| 5186 | afs_int32 ip1, ip2, vcode; |
| 5187 | int remove = 0; |
| 5188 | |
| 5189 | if (noresolve) |
| 5190 | ip1 = GetServerNoresolve(as->parms[0].items->data); |
| 5191 | else |
| 5192 | ip1 = GetServer(as->parms[0].items->data); |
| 5193 | if (!ip1) { |
| 5194 | fprintf(STDERR__stderrp, "vos: invalid host address\n"); |
| 5195 | return (EINVAL22); |
| 5196 | } |
| 5197 | |
| 5198 | if ((as->parms[1].items && as->parms[2].items) |
| 5199 | || (!as->parms[1].items && !as->parms[2].items)) { |
| 5200 | fprintf(STDERR__stderrp, |
| 5201 | "vos: Must specify either '-newaddr <addr>' or '-remove' flag\n"); |
| 5202 | return (EINVAL22); |
| 5203 | } |
| 5204 | |
| 5205 | if (as->parms[1].items) { |
| 5206 | if (noresolve) |
| 5207 | ip2 = GetServerNoresolve(as->parms[1].items->data); |
| 5208 | else |
| 5209 | ip2 = GetServer(as->parms[1].items->data); |
| 5210 | if (!ip2) { |
| 5211 | fprintf(STDERR__stderrp, "vos: invalid host address\n"); |
| 5212 | return (EINVAL22); |
| 5213 | } |
| 5214 | } else { |
| 5215 | /* Play a trick here. If we are removing an address, ip1 will be -1 |
| 5216 | * and ip2 will be the original address. This switch prevents an |
| 5217 | * older revision vlserver from removing the IP address. |
| 5218 | */ |
| 5219 | remove = 1; |
| 5220 | ip2 = ip1; |
| 5221 | ip1 = 0xffffffff; |
| 5222 | } |
| 5223 | |
| 5224 | vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW2, ntohl(ip1)(__builtin_constant_p(ip1) ? ((((__uint32_t)(ip1)) >> 24 ) | ((((__uint32_t)(ip1)) & (0xff << 16)) >> 8 ) | ((((__uint32_t)(ip1)) & (0xff << 8)) << 8 ) | (((__uint32_t)(ip1)) << 24)) : __bswap32_var(ip1)), ntohl(ip2)(__builtin_constant_p(ip2) ? ((((__uint32_t)(ip2)) >> 24 ) | ((((__uint32_t)(ip2)) & (0xff << 16)) >> 8 ) | ((((__uint32_t)(ip2)) & (0xff << 8)) << 8 ) | (((__uint32_t)(ip2)) << 24)) : __bswap32_var(ip2))); |
| 5225 | if (vcode) { |
| 5226 | char hoststr1[16], hoststr2[16]; |
| 5227 | if (remove) { |
| 5228 | afs_inet_ntoa_r(ip2, hoststr2); |
| 5229 | fprintf(STDERR__stderrp, "Could not remove server %s from the VLDB\n", |
| 5230 | hoststr2); |
| 5231 | if (vcode == VL_NOENT(363524L)) { |
| 5232 | fprintf(STDERR__stderrp, |
| 5233 | "vlserver does not support the remove flag or "); |
| 5234 | } |
| 5235 | } else { |
| 5236 | afs_inet_ntoa_r(ip1, hoststr1); |
| 5237 | afs_inet_ntoa_r(ip2, hoststr2); |
| 5238 | fprintf(STDERR__stderrp, "Could not change server %s to server %s\n", |
| 5239 | hoststr1, hoststr2); |
| 5240 | } |
| 5241 | PrintError("", vcode); |
| 5242 | return (vcode); |
| 5243 | } |
| 5244 | |
| 5245 | if (remove) { |
| 5246 | fprintf(STDOUT__stdoutp, "Removed server %s from the VLDB\n", |
| 5247 | as->parms[0].items->data); |
| 5248 | } else { |
| 5249 | fprintf(STDOUT__stdoutp, "Changed server %s to server %s\n", |
| 5250 | as->parms[0].items->data, as->parms[1].items->data); |
| 5251 | } |
| 5252 | return 0; |
| 5253 | } |
| 5254 | |
| 5255 | static void |
| 5256 | print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries, |
| 5257 | int print) |
| 5258 | { |
| 5259 | int i; |
| 5260 | afs_uint32 *addrp; |
| 5261 | char buf[1024]; |
| 5262 | |
| 5263 | if (print) { |
| 5264 | afsUUID_to_string(m_uuid, buf, sizeof(buf)); |
| 5265 | printf("UUID: %s\n", buf); |
| 5266 | } |
| 5267 | |
| 5268 | /* print out the list of all the server */ |
| 5269 | addrp = (afs_uint32 *) addrs->bulkaddrs_val; |
| 5270 | for (i = 0; i < nentries; i++, addrp++) { |
| 5271 | *addrp = htonl(*addrp)(__builtin_constant_p(*addrp) ? ((((__uint32_t)(*addrp)) >> 24) | ((((__uint32_t)(*addrp)) & (0xff << 16)) >> 8) | ((((__uint32_t)(*addrp)) & (0xff << 8)) << 8) | (((__uint32_t)(*addrp)) << 24)) : __bswap32_var(* addrp)); |
| 5272 | if (noresolve) { |
| 5273 | char hoststr[16]; |
| 5274 | printf("%s\n", afs_inet_ntoa_r(*addrp, hoststr)); |
| 5275 | } else { |
| 5276 | printf("%s\n", hostutil_GetNameByINet(*addrp)); |
| 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | if (print) { |
| 5281 | printf("\n"); |
| 5282 | } |
| 5283 | return; |
| 5284 | } |
| 5285 | |
| 5286 | static int |
| 5287 | ListAddrs(struct cmd_syndesc *as, void *arock) |
| 5288 | { |
| 5289 | afs_int32 vcode, m_uniq=0; |
| 5290 | afs_int32 i, printuuid = 0; |
| 5291 | struct VLCallBack vlcb; |
| 5292 | afs_int32 nentries; |
| 5293 | bulkaddrs m_addrs; |
| 5294 | ListAddrByAttributes m_attrs; |
| 5295 | afsUUID m_uuid, askuuid; |
| 5296 | afs_int32 m_nentries; |
| 5297 | |
| 5298 | if (as->parms[0].items && as->parms[1].items) { |
| 5299 | fprintf(STDERR__stderrp, "vos: Can't use the -uuid and -host flags together\n"); |
| 5300 | exit(-1); |
| 5301 | } |
| 5302 | |
| 5303 | memset(&m_attrs, 0, sizeof(struct ListAddrByAttributes)); |
| 5304 | memset(&askuuid, 0, sizeof(afsUUID)); |
| 5305 | if (as->parms[0].items) { |
| 5306 | /* -uuid */ |
| 5307 | if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) { |
| 5308 | fprintf(STDERR__stderrp, "vos: invalid UUID '%s'\n", |
| 5309 | as->parms[0].items->data); |
| 5310 | exit(-1); |
| 5311 | } |
| 5312 | m_attrs.Mask = VLADDR_UUID0x4; |
| 5313 | m_attrs.uuid = askuuid; |
| 5314 | } else if (as->parms[1].items) { |
| 5315 | /* -host */ |
| 5316 | struct hostent *he; |
| 5317 | afs_uint32 saddr; |
| 5318 | he = hostutil_GetHostByName((char *)as->parms[1].items->data); |
| 5319 | if (he == NULL((void *)0)) { |
| 5320 | fprintf(STDERR__stderrp, "vos: Can't get host info for '%s'\n", |
| 5321 | as->parms[1].items->data); |
| 5322 | exit(-1); |
| 5323 | } |
| 5324 | memcpy(&saddr, he->h_addrh_addr_list[0], 4); |
| 5325 | m_attrs.Mask = VLADDR_IPADDR0x1; |
| 5326 | m_attrs.ipaddr = ntohl(saddr)(__builtin_constant_p(saddr) ? ((((__uint32_t)(saddr)) >> 24) | ((((__uint32_t)(saddr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(saddr)) & (0xff << 8)) << 8) | (((__uint32_t)(saddr)) << 24)) : __bswap32_var(saddr )); |
| 5327 | } else { |
| 5328 | /* by index */ |
| 5329 | m_attrs.Mask = VLADDR_INDEX0x2; |
| 5330 | } |
| 5331 | |
| 5332 | if (as->parms[2].items) { |
| 5333 | printuuid = 1; |
| 5334 | } |
| 5335 | |
| 5336 | memset(&m_addrs, 0, sizeof(bulkaddrs)); |
| 5337 | memset(&vlcb, 0, sizeof(struct VLCallBack)); |
| 5338 | |
| 5339 | vcode = |
| 5340 | ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW2, 0, 0, &vlcb, &nentries, |
| 5341 | &m_addrs); |
| 5342 | if (vcode) { |
| 5343 | fprintf(STDERR__stderrp, "vos: could not list the server addresses\n"); |
| 5344 | PrintError("", vcode); |
| 5345 | goto out; |
| 5346 | } |
| 5347 | |
| 5348 | for (i = 1, m_nentries = 0; nentries; i++) { |
| 5349 | m_attrs.index = i; |
| 5350 | |
| 5351 | xdr_freeafs_xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); /* reset addr list */ |
| 5352 | vcode = |
| 5353 | ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW2, &m_attrs, &m_uuid, |
| 5354 | &m_uniq, &m_nentries, &m_addrs); |
| 5355 | switch (vcode) { |
| 5356 | case 0: /* success */ |
| 5357 | print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid); |
| 5358 | nentries--; |
| 5359 | break; |
| 5360 | |
| 5361 | case VL_NOENT(363524L): |
| 5362 | if (m_attrs.Mask == VLADDR_UUID0x4) { |
| 5363 | fprintf(STDERR__stderrp, "vos: no entry for UUID '%s' found in VLDB\n", |
| 5364 | as->parms[0].items->data); |
| 5365 | exit(-1); |
| 5366 | } else if (m_attrs.Mask == VLADDR_IPADDR0x1) { |
| 5367 | fprintf(STDERR__stderrp, "vos: no entry for host '%s' [0x%08x] found in VLDB\n", |
| 5368 | as->parms[1].items->data, m_attrs.ipaddr); |
| 5369 | exit(-1); |
| 5370 | } |
| 5371 | continue; |
| 5372 | |
| 5373 | case VL_INDEXERANGE(363549L): |
| 5374 | vcode = 0; /* not an error, just means we're done */ |
| 5375 | goto out; |
| 5376 | |
| 5377 | default: /* any other error */ |
| 5378 | fprintf(STDERR__stderrp, "vos: could not list the server addresses\n"); |
| 5379 | PrintError("", vcode); |
| 5380 | goto out; |
| 5381 | } |
| 5382 | |
| 5383 | /* if -uuid or -host, only list one response */ |
| 5384 | if (as->parms[1].items || as->parms[0].items) |
| 5385 | break; |
| 5386 | } |
| 5387 | |
| 5388 | out: |
| 5389 | xdr_freeafs_xdr_free((xdrproc_t)xdr_bulkaddrs, &m_addrs); |
| 5390 | return vcode; |
| 5391 | } |
| 5392 | |
| 5393 | |
| 5394 | static int |
| 5395 | SetAddrs(struct cmd_syndesc *as, void *arock) |
| 5396 | { |
| 5397 | afs_int32 vcode; |
| 5398 | bulkaddrs m_addrs; |
| 5399 | afsUUID askuuid; |
| 5400 | afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE16]; |
| 5401 | |
| 5402 | memset(&m_addrs, 0, sizeof(bulkaddrs)); |
| 5403 | memset(&askuuid, 0, sizeof(afsUUID)); |
| 5404 | if (as->parms[0].items) { |
| 5405 | /* -uuid */ |
| 5406 | if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) { |
| 5407 | fprintf(STDERR__stderrp, "vos: invalid UUID '%s'\n", |
| 5408 | as->parms[0].items->data); |
| 5409 | exit(-1); |
| 5410 | } |
| 5411 | } |
| 5412 | if (as->parms[1].items) { |
| 5413 | /* -host */ |
| 5414 | struct cmd_item *ti; |
| 5415 | afs_uint32 saddr; |
| 5416 | int i = 0; |
| 5417 | |
| 5418 | for (ti = as->parms[1].items; ti && i < ADDRSPERSITE16; ti = ti->next) { |
| 5419 | |
| 5420 | if (noresolve) |
| 5421 | saddr = GetServerNoresolve(ti->data); |
| 5422 | else |
| 5423 | saddr = GetServer(ti->data); |
| 5424 | |
| 5425 | if (!saddr) { |
| 5426 | fprintf(STDERR__stderrp, "vos: Can't get host info for '%s'\n", |
| 5427 | ti->data); |
| 5428 | exit(-1); |
| 5429 | } |
| 5430 | /* Convert it to host byte order */ |
| 5431 | FS_HostAddrs_HBO[i] = ntohl(saddr)(__builtin_constant_p(saddr) ? ((((__uint32_t)(saddr)) >> 24) | ((((__uint32_t)(saddr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(saddr)) & (0xff << 8)) << 8) | (((__uint32_t)(saddr)) << 24)) : __bswap32_var(saddr )); |
| 5432 | i++; |
| 5433 | } |
| 5434 | m_addrs.bulkaddrs_len = i; |
| 5435 | m_addrs.bulkaddrs_val = FS_HostAddrs_HBO; |
| 5436 | } |
| 5437 | |
| 5438 | vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs); |
| 5439 | |
| 5440 | if (vcode) { |
| 5441 | if (vcode == VL_MULTIPADDR(363550L)) { |
| 5442 | fprintf(STDERR__stderrp, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"); |
| 5443 | PrintError("", vcode); |
| 5444 | return vcode; |
| 5445 | } else if (vcode == RXGEN_OPCODE-455) { |
| 5446 | fprintf(STDERR__stderrp, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"); |
| 5447 | PrintError("", vcode); |
| 5448 | return vcode; |
| 5449 | } |
| 5450 | } |
| 5451 | if (verbose) { |
| 5452 | fprintf(STDOUT__stdoutp, "vos: Changed UUID with addresses:\n"); |
| 5453 | print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1); |
| 5454 | } |
| 5455 | return 0; |
| 5456 | } |
| 5457 | |
| 5458 | static int |
| 5459 | LockEntry(struct cmd_syndesc *as, void *arock) |
| 5460 | { |
| 5461 | afs_uint32 avolid; |
| 5462 | afs_int32 vcode, err; |
| 5463 | |
| 5464 | avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 5465 | if (avolid == 0) { |
| 5466 | if (err) |
| 5467 | PrintError("", err); |
| 5468 | else |
| 5469 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 5470 | as->parms[0].items->data); |
| 5471 | exit(1); |
| 5472 | } |
| 5473 | vcode = ubik_VL_SetLock(cstruct, 0, avolid, -1, VLOP_DELETE0x80); |
| 5474 | if (vcode) { |
| 5475 | fprintf(STDERR__stderrp, "Could not lock VLDB entry for volume %s\n", |
| 5476 | as->parms[0].items->data); |
| 5477 | PrintError("", vcode); |
| 5478 | exit(1); |
| 5479 | } |
| 5480 | fprintf(STDOUT__stdoutp, "Locked VLDB entry for volume %s\n", |
| 5481 | as->parms[0].items->data); |
| 5482 | return 0; |
| 5483 | } |
| 5484 | |
| 5485 | static int |
| 5486 | ConvertRO(struct cmd_syndesc *as, void *arock) |
| 5487 | { |
| 5488 | afs_int32 partition = -1; |
| 5489 | afs_uint32 volid; |
| 5490 | afs_uint32 server; |
| 5491 | afs_int32 code, i, same; |
| 5492 | struct nvldbentry entry, storeEntry; |
| 5493 | afs_int32 vcode; |
| 5494 | afs_int32 rwindex = 0; |
| 5495 | afs_uint32 rwserver = 0; |
| 5496 | afs_int32 rwpartition = 0; |
| 5497 | afs_int32 roindex = 0; |
| 5498 | afs_uint32 roserver = 0; |
| 5499 | afs_int32 ropartition = 0; |
| 5500 | int force = 0; |
| 5501 | struct rx_connection *aconn; |
| 5502 | int c, dc; |
| 5503 | |
| 5504 | server = GetServer(as->parms[0].items->data); |
| 5505 | if (!server) { |
| 5506 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 5507 | as->parms[0].items->data); |
| 5508 | return ENOENT2; |
| 5509 | } |
| 5510 | partition = volutil_GetPartitionID(as->parms[1].items->data); |
| 5511 | if (partition < 0) { |
| 5512 | fprintf(STDERR__stderrp, "vos: could not interpret partition name '%s'\n", |
| 5513 | as->parms[1].items->data); |
| 5514 | return ENOENT2; |
| 5515 | } |
| 5516 | if (!IsPartValid(partition, server, &code)) { |
| 5517 | if (code) |
| 5518 | PrintError("", code); |
| 5519 | else |
| 5520 | fprintf(STDERR__stderrp, |
| 5521 | "vos : partition %s does not exist on the server\n", |
| 5522 | as->parms[1].items->data); |
| 5523 | return ENOENT2; |
| 5524 | } |
| 5525 | volid = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &code); |
| 5526 | if (volid == 0) { |
| 5527 | if (code) |
| 5528 | PrintError("", code); |
| 5529 | else |
| 5530 | fprintf(STDERR__stderrp, "Unknown volume ID or name '%s'\n", |
| 5531 | as->parms[0].items->data); |
| 5532 | return -1; |
| 5533 | } |
| 5534 | if (as->parms[3].items) |
| 5535 | force = 1; |
| 5536 | |
| 5537 | vcode = VLDB_GetEntryByID(volid, -1, &entry); |
| 5538 | if (vcode) { |
| 5539 | fprintf(STDERR__stderrp, |
| 5540 | "Could not fetch the entry for volume %lu from VLDB\n", |
| 5541 | (unsigned long)volid); |
| 5542 | PrintError("convertROtoRW", code); |
| 5543 | return vcode; |
| 5544 | } |
| 5545 | |
| 5546 | /* use RO volid even if user specified RW or BK volid */ |
| 5547 | |
| 5548 | if (volid != entry.volumeId[ROVOL1]) |
| 5549 | volid = entry.volumeId[ROVOL1]; |
| 5550 | |
| 5551 | MapHostToNetwork(&entry); |
| 5552 | for (i = 0; i < entry.nServers; i++) { |
| 5553 | if (entry.serverFlags[i] & ITSRWVOL0x04) { |
| 5554 | rwindex = i; |
| 5555 | rwserver = entry.serverNumber[i]; |
| 5556 | rwpartition = entry.serverPartition[i]; |
| 5557 | } |
| 5558 | if (entry.serverFlags[i] & ITSROVOL0x02) { |
| 5559 | same = VLDB_IsSameAddrs(server, entry.serverNumber[i], &code); |
| 5560 | if (code) { |
| 5561 | fprintf(STDERR__stderrp, |
| 5562 | "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n", |
| 5563 | server, code); |
| 5564 | return ENOENT2; |
| 5565 | } |
| 5566 | if (same) { |
| 5567 | roindex = i; |
| 5568 | roserver = entry.serverNumber[i]; |
| 5569 | ropartition = entry.serverPartition[i]; |
| 5570 | break; |
| 5571 | } |
| 5572 | } |
| 5573 | } |
| 5574 | if (!roserver) { |
| 5575 | fprintf(STDERR__stderrp, "Warning: RO volume didn't exist in vldb!\n"); |
| 5576 | } |
| 5577 | if (ropartition != partition) { |
| 5578 | fprintf(STDERR__stderrp, |
| 5579 | "Warning: RO volume should be in partition %d instead of %d (vldb)\n", |
| 5580 | ropartition, partition); |
| 5581 | } |
| 5582 | |
| 5583 | if (rwserver) { |
| 5584 | fprintf(STDERR__stderrp, |
| 5585 | "VLDB indicates that a RW volume exists already on %s in partition %s.\n", |
| 5586 | hostutil_GetNameByINet(rwserver), |
| 5587 | volutil_PartitionName(rwpartition)); |
| 5588 | if (!force) { |
| 5589 | fprintf(STDERR__stderrp, "Overwrite this VLDB entry? [y|n] (n)\n"); |
| 5590 | dc = c = getchar()(!__isthreaded ? (--(__stdinp)->_r < 0 ? __srget(__stdinp ) : (int)(*(__stdinp)->_p++)) : (getc)(__stdinp)); |
| 5591 | while (!(dc == EOF(-1) || dc == '\n')) |
| 5592 | dc = getchar()(!__isthreaded ? (--(__stdinp)->_r < 0 ? __srget(__stdinp ) : (int)(*(__stdinp)->_p++)) : (getc)(__stdinp)); /* goto end of line */ |
| 5593 | if ((c != 'y') && (c != 'Y')) { |
| 5594 | fprintf(STDERR__stderrp, "aborted.\n"); |
| 5595 | return -1; |
| 5596 | } |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | vcode = |
Value stored to 'vcode' is never read | |
| 5601 | ubik_VL_SetLock(cstruct, 0, entry.volumeId[RWVOL0], RWVOL0, |
| 5602 | VLOP_MOVE0x10); |
| 5603 | aconn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); |
| 5604 | code = AFSVolConvertROtoRWvolume(aconn, partition, volid); |
| 5605 | if (code) { |
| 5606 | fprintf(STDERR__stderrp, |
| 5607 | "Converting RO volume %lu to RW volume failed with code %d\n", |
| 5608 | (unsigned long)volid, code); |
| 5609 | PrintError("convertROtoRW ", code); |
| 5610 | return -1; |
| 5611 | } |
| 5612 | entry.serverFlags[roindex] = ITSRWVOL0x04; |
| 5613 | entry.flags |= RW_EXISTS0x1000; |
| 5614 | entry.flags &= ~BACK_EXISTS0x4000; |
| 5615 | if (rwserver) { |
| 5616 | (entry.nServers)--; |
| 5617 | if (rwindex != entry.nServers) { |
| 5618 | entry.serverNumber[rwindex] = entry.serverNumber[entry.nServers]; |
| 5619 | entry.serverPartition[rwindex] = |
| 5620 | entry.serverPartition[entry.nServers]; |
| 5621 | entry.serverFlags[rwindex] = entry.serverFlags[entry.nServers]; |
| 5622 | entry.serverNumber[entry.nServers] = 0; |
| 5623 | entry.serverPartition[entry.nServers] = 0; |
| 5624 | entry.serverFlags[entry.nServers] = 0; |
| 5625 | } |
| 5626 | } |
| 5627 | entry.flags &= ~RO_EXISTS0x2000; |
| 5628 | for (i = 0; i < entry.nServers; i++) { |
| 5629 | if (entry.serverFlags[i] & ITSROVOL0x02) { |
| 5630 | if (!(entry.serverFlags[i] & (RO_DONTUSE0x20 | NEW_REPSITE0x01))) |
| 5631 | entry.flags |= RO_EXISTS0x2000; |
| 5632 | } |
| 5633 | } |
| 5634 | MapNetworkToHost(&entry, &storeEntry); |
| 5635 | code = |
| 5636 | VLDB_ReplaceEntry(entry.volumeId[RWVOL0], RWVOL0, &storeEntry, |
| 5637 | (LOCKREL_OPCODE2 | LOCKREL_AFSID4 | |
| 5638 | LOCKREL_TIMESTAMP1)); |
| 5639 | if (code) { |
| 5640 | fprintf(STDERR__stderrp, |
| 5641 | "Warning: volume converted, but vldb update failed with code %d!\n", |
| 5642 | code); |
| 5643 | } |
| 5644 | vcode = UV_LockRelease(entry.volumeId[RWVOL0]); |
| 5645 | if (vcode) { |
| 5646 | PrintDiagnostics("unlock", vcode); |
| 5647 | } |
| 5648 | return code; |
| 5649 | } |
| 5650 | |
| 5651 | static int |
| 5652 | Sizes(struct cmd_syndesc *as, void *arock) |
| 5653 | { |
| 5654 | afs_uint32 avolid; |
| 5655 | afs_uint32 aserver; |
| 5656 | afs_int32 apart, voltype, fromdate = 0, code, err, i; |
| 5657 | struct nvldbentry entry; |
| 5658 | volintSize vol_size; |
| 5659 | |
| 5660 | rx_SetRxDeadTime(60 * 10)(rx_connDeadTime = (60 * 10)); |
| 5661 | for (i = 0; i < MAXSERVERS20; i++) { |
| 5662 | struct rx_connection *rxConn = ubik_GetRPCConn(cstruct, i)((i) >= 20? 0 : (cstruct)->conns[i]); |
| 5663 | if (rxConn == 0) |
| 5664 | break; |
| 5665 | rx_SetConnDeadTime(rxConn, rx_connDeadTime); |
| 5666 | if (rxConn->service) |
| 5667 | rxConn->service->connDeadTime = rx_connDeadTime; |
| 5668 | } |
| 5669 | |
| 5670 | avolid = vsu_GetVolumeID(as->parms[0].items->data, cstruct, &err); |
| 5671 | if (avolid == 0) { |
| 5672 | if (err) |
| 5673 | PrintError("", err); |
| 5674 | else |
| 5675 | fprintf(STDERR__stderrp, "vos: can't find volume '%s'\n", |
| 5676 | as->parms[0].items->data); |
| 5677 | return ENOENT2; |
| 5678 | } |
| 5679 | |
| 5680 | if (as->parms[1].items || as->parms[2].items) { |
| 5681 | if (!as->parms[1].items || !as->parms[2].items) { |
| 5682 | fprintf(STDERR__stderrp, |
| 5683 | "Must specify both -server and -partition options\n"); |
| 5684 | return -1; |
| 5685 | } |
| 5686 | aserver = GetServer(as->parms[2].items->data); |
| 5687 | if (aserver == 0) { |
| 5688 | fprintf(STDERR__stderrp, "Invalid server name\n"); |
| 5689 | return -1; |
| 5690 | } |
| 5691 | apart = volutil_GetPartitionID(as->parms[1].items->data); |
| 5692 | if (apart < 0) { |
| 5693 | fprintf(STDERR__stderrp, "Invalid partition name\n"); |
| 5694 | return -1; |
| 5695 | } |
| 5696 | } else { |
| 5697 | code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry); |
| 5698 | if (code) |
| 5699 | return code; |
| 5700 | } |
| 5701 | |
| 5702 | fromdate = 0; |
| 5703 | |
| 5704 | if (as->parms[4].items && strcmp(as->parms[4].items->data, "0")) { |
| 5705 | code = ktime_DateToInt32(as->parms[4].items->data, &fromdate); |
| 5706 | if (code) { |
| 5707 | fprintf(STDERR__stderrp, "vos: failed to parse date '%s' (error=%d))\n", |
| 5708 | as->parms[4].items->data, code); |
| 5709 | return code; |
| 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | fprintf(STDOUT__stdoutp, "Volume: %s\n", as->parms[0].items->data); |
| 5714 | |
| 5715 | if (as->parms[3].items) { /* do the dump estimate */ |
| 5716 | vol_size.dump_size = 0; |
| 5717 | code = UV_GetSize(avolid, aserver, apart, fromdate, &vol_size); |
| 5718 | if (code) { |
| 5719 | PrintDiagnostics("size", code); |
| 5720 | return code; |
| 5721 | } |
| 5722 | /* presumably the size info is now gathered in pntr */ |
| 5723 | /* now we display it */ |
| 5724 | |
| 5725 | fprintf(STDOUT__stdoutp, "dump_size: %llu\n", vol_size.dump_size); |
| 5726 | } |
| 5727 | |
| 5728 | /* Display info */ |
| 5729 | |
| 5730 | return 0; |
| 5731 | } |
| 5732 | |
| 5733 | static int |
| 5734 | EndTrans(struct cmd_syndesc *as, void *arock) |
| 5735 | { |
| 5736 | afs_uint32 server; |
| 5737 | afs_int32 code, tid, rcode; |
| 5738 | struct rx_connection *aconn; |
| 5739 | |
| 5740 | server = GetServer(as->parms[0].items->data); |
| 5741 | if (!server) { |
| 5742 | fprintf(STDERR__stderrp, "vos: host '%s' not found in host table\n", |
| 5743 | as->parms[0].items->data); |
| 5744 | return EINVAL22; |
| 5745 | } |
| 5746 | |
| 5747 | code = util_GetInt32(as->parms[1].items->data, &tid); |
| 5748 | if (code) { |
| 5749 | fprintf(STDERR__stderrp, "vos: bad integer specified for transaction ID.\n"); |
| 5750 | return code; |
| 5751 | } |
| 5752 | |
| 5753 | aconn = UV_Bind(server, AFSCONF_VOLUMEPORT7005); |
| 5754 | code = AFSVolEndTrans(aconn, tid, &rcode); |
| 5755 | if (!code) { |
| 5756 | code = rcode; |
| 5757 | } |
| 5758 | |
| 5759 | if (code) { |
| 5760 | PrintDiagnostics("endtrans", code); |
| 5761 | return 1; |
| 5762 | } |
| 5763 | |
| 5764 | return 0; |
| 5765 | } |
| 5766 | |
| 5767 | int |
| 5768 | PrintDiagnostics(char *astring, afs_int32 acode) |
| 5769 | { |
| 5770 | if (acode == EACCES13) { |
| 5771 | fprintf(STDERR__stderrp, |
| 5772 | "You are not authorized to perform the 'vos %s' command (%d)\n", |
| 5773 | astring, acode); |
| 5774 | } else { |
| 5775 | fprintf(STDERR__stderrp, "Error in vos %s command.\n", astring); |
| 5776 | PrintError("", acode); |
| 5777 | } |
| 5778 | return 0; |
| 5779 | } |
| 5780 | |
| 5781 | |
| 5782 | #ifdef AFS_NT40_ENV |
| 5783 | static DWORD |
| 5784 | win32_enableCrypt(void) |
| 5785 | { |
| 5786 | HKEY parmKey; |
| 5787 | DWORD dummyLen; |
| 5788 | DWORD cryptall = 0; |
| 5789 | DWORD code; |
| 5790 | |
| 5791 | /* Look up configuration parameters in Registry */ |
| 5792 | code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY, |
| 5793 | 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey); |
| 5794 | if (code != ERROR_SUCCESS) { |
| 5795 | dummyLen = sizeof(cryptall); |
| 5796 | RegQueryValueEx(parmKey, "SecurityLevel", NULL((void *)0), NULL((void *)0), |
| 5797 | (BYTE *) &cryptall, &dummyLen); |
| 5798 | } |
| 5799 | RegCloseKey (parmKey); |
| 5800 | |
| 5801 | return cryptall; |
| 5802 | } |
| 5803 | #endif /* AFS_NT40_ENV */ |
| 5804 | |
| 5805 | static int |
| 5806 | MyBeforeProc(struct cmd_syndesc *as, void *arock) |
| 5807 | { |
| 5808 | char *tcell; |
| 5809 | afs_int32 code; |
| 5810 | afs_int32 sauth; |
| 5811 | |
| 5812 | /* Initialize the ubik_client connection */ |
| 5813 | rx_SetRxDeadTime(90)(rx_connDeadTime = (90)); |
| 5814 | cstruct = (struct ubik_client *)0; |
| 5815 | |
| 5816 | sauth = 0; |
| 5817 | tcell = NULL((void *)0); |
| 5818 | if (as->parms[12].items) /* if -cell specified */ |
| 5819 | tcell = as->parms[12].items->data; |
| 5820 | if (as->parms[14].items) /* -serverauth specified */ |
| 5821 | sauth = 1; |
| 5822 | if (as->parms[16].items /* -encrypt specified */ |
| 5823 | #ifdef AFS_NT40_ENV |
| 5824 | || win32_enableCrypt() |
| 5825 | #endif /* AFS_NT40_ENV */ |
| 5826 | ) |
| 5827 | vsu_SetCrypt(1); |
| 5828 | |
| 5829 | if (as->parms[18].items) /* -config flag set */ |
| 5830 | confdir = as->parms[18].items->data; |
| 5831 | |
| 5832 | if ((code = |
| 5833 | vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth, |
| 5834 | &cstruct, UV_SetSecurity))) { |
| 5835 | fprintf(STDERR__stderrp, "could not initialize VLDB library (code=%lu) \n", |
| 5836 | (unsigned long)code); |
| 5837 | exit(1); |
| 5838 | } |
| 5839 | rxInitDone = 1; |
| 5840 | if (as->parms[15].items) /* -verbose flag set */ |
| 5841 | verbose = 1; |
| 5842 | else |
| 5843 | verbose = 0; |
| 5844 | if (as->parms[17].items) /* -noresolve flag set */ |
| 5845 | noresolve = 1; |
| 5846 | else |
| 5847 | noresolve = 0; |
| 5848 | |
| 5849 | return 0; |
| 5850 | } |
| 5851 | |
| 5852 | int |
| 5853 | osi_audit(void) |
| 5854 | { |
| 5855 | /* this sucks but it works for now. |
| 5856 | */ |
| 5857 | return 0; |
| 5858 | } |
| 5859 | |
| 5860 | #include "AFS_component_version_number.c" |
| 5861 | |
| 5862 | int |
| 5863 | main(int argc, char **argv) |
| 5864 | { |
| 5865 | afs_int32 code; |
| 5866 | |
| 5867 | struct cmd_syndesc *ts; |
| 5868 | |
| 5869 | #ifdef AFS_AIX32_ENV |
| 5870 | /* |
| 5871 | * The following signal action for AIX is necessary so that in case of a |
| 5872 | * crash (i.e. core is generated) we can include the user's data section |
| 5873 | * in the core dump. Unfortunately, by default, only a partial core is |
| 5874 | * generated which, in many cases, isn't too useful. |
| 5875 | */ |
| 5876 | struct sigaction nsa; |
| 5877 | |
| 5878 | sigemptyset(&nsa.sa_mask); |
| 5879 | nsa.sa_handler__sigaction_u.__sa_handler = SIG_DFL((__sighandler_t *)0); |
| 5880 | nsa.sa_flags = SA_FULLDUMP; |
| 5881 | sigaction(SIGSEGV11, &nsa, NULL((void *)0)); |
| 5882 | #endif |
| 5883 | |
| 5884 | confdir = AFSDIR_CLIENT_ETC_DIRPATHgetDirPath(AFSDIR_CLIENT_ETC_DIRPATH_ID); |
| 5885 | |
| 5886 | cmd_SetBeforeProc(MyBeforeProc, NULL((void *)0)); |
| 5887 | |
| 5888 | ts = cmd_CreateSyntax("create", CreateVolume, NULL((void *)0), "create a new volume"); |
| 5889 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 5890 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 5891 | cmd_AddParm(ts, "-name", CMD_SINGLE2, 0, "volume name"); |
| 5892 | cmd_AddParm(ts, "-maxquota", CMD_SINGLE2, CMD_OPTIONAL1, |
| 5893 | "initial quota (KB)"); |
| 5894 | cmd_AddParm(ts, "-id", CMD_SINGLE2, CMD_OPTIONAL1, "volume ID"); |
| 5895 | cmd_AddParm(ts, "-roid", CMD_SINGLE2, CMD_OPTIONAL1, "readonly volume ID"); |
| 5896 | #ifdef notdef |
| 5897 | cmd_AddParm(ts, "-minquota", CMD_SINGLE2, CMD_OPTIONAL1, ""); |
| 5898 | #endif |
| 5899 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5900 | |
| 5901 | ts = cmd_CreateSyntax("remove", DeleteVolume, NULL((void *)0), "delete a volume"); |
| 5902 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 5903 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 5904 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 5905 | |
| 5906 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5907 | |
| 5908 | ts = cmd_CreateSyntax("move", MoveVolume, NULL((void *)0), "move a volume"); |
| 5909 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 5910 | cmd_AddParm(ts, "-fromserver", CMD_SINGLE2, 0, "machine name on source"); |
| 5911 | cmd_AddParm(ts, "-frompartition", CMD_SINGLE2, 0, |
| 5912 | "partition name on source"); |
| 5913 | cmd_AddParm(ts, "-toserver", CMD_SINGLE2, 0, |
| 5914 | "machine name on destination"); |
| 5915 | cmd_AddParm(ts, "-topartition", CMD_SINGLE2, 0, |
| 5916 | "partition name on destination"); |
| 5917 | cmd_AddParm(ts, "-live", CMD_FLAG1, CMD_OPTIONAL1, |
| 5918 | "copy live volume without cloning"); |
| 5919 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5920 | |
| 5921 | ts = cmd_CreateSyntax("copy", CopyVolume, NULL((void *)0), "copy a volume"); |
| 5922 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID on source"); |
| 5923 | cmd_AddParm(ts, "-fromserver", CMD_SINGLE2, 0, "machine name on source"); |
| 5924 | cmd_AddParm(ts, "-frompartition", CMD_SINGLE2, 0, |
| 5925 | "partition name on source"); |
| 5926 | cmd_AddParm(ts, "-toname", CMD_SINGLE2, 0, "volume name on destination"); |
| 5927 | cmd_AddParm(ts, "-toserver", CMD_SINGLE2, 0, |
| 5928 | "machine name on destination"); |
| 5929 | cmd_AddParm(ts, "-topartition", CMD_SINGLE2, 0, |
| 5930 | "partition name on destination"); |
| 5931 | cmd_AddParm(ts, "-offline", CMD_FLAG1, CMD_OPTIONAL1, |
| 5932 | "leave new volume offline"); |
| 5933 | cmd_AddParm(ts, "-readonly", CMD_FLAG1, CMD_OPTIONAL1, |
| 5934 | "make new volume read-only"); |
| 5935 | cmd_AddParm(ts, "-live", CMD_FLAG1, CMD_OPTIONAL1, |
| 5936 | "copy live volume without cloning"); |
| 5937 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5938 | |
| 5939 | ts = cmd_CreateSyntax("shadow", ShadowVolume, NULL((void *)0), |
| 5940 | "make or update a shadow volume"); |
| 5941 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID on source"); |
| 5942 | cmd_AddParm(ts, "-fromserver", CMD_SINGLE2, 0, "machine name on source"); |
| 5943 | cmd_AddParm(ts, "-frompartition", CMD_SINGLE2, 0, |
| 5944 | "partition name on source"); |
| 5945 | cmd_AddParm(ts, "-toserver", CMD_SINGLE2, 0, |
| 5946 | "machine name on destination"); |
| 5947 | cmd_AddParm(ts, "-topartition", CMD_SINGLE2, 0, |
| 5948 | "partition name on destination"); |
| 5949 | cmd_AddParm(ts, "-toname", CMD_SINGLE2, CMD_OPTIONAL1, |
| 5950 | "volume name on destination"); |
| 5951 | cmd_AddParm(ts, "-toid", CMD_SINGLE2, CMD_OPTIONAL1, |
| 5952 | "volume ID on destination"); |
| 5953 | cmd_AddParm(ts, "-offline", CMD_FLAG1, CMD_OPTIONAL1, |
| 5954 | "leave shadow volume offline"); |
| 5955 | cmd_AddParm(ts, "-readonly", CMD_FLAG1, CMD_OPTIONAL1, |
| 5956 | "make shadow volume read-only"); |
| 5957 | cmd_AddParm(ts, "-live", CMD_FLAG1, CMD_OPTIONAL1, |
| 5958 | "copy live volume without cloning"); |
| 5959 | cmd_AddParm(ts, "-incremental", CMD_FLAG1, CMD_OPTIONAL1, |
| 5960 | "do incremental update if target exists"); |
| 5961 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5962 | |
| 5963 | ts = cmd_CreateSyntax("backup", BackupVolume, NULL((void *)0), |
| 5964 | "make backup of a volume"); |
| 5965 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 5966 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5967 | |
| 5968 | ts = cmd_CreateSyntax("clone", CloneVolume, NULL((void *)0), |
| 5969 | "make clone of a volume"); |
| 5970 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 5971 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "server"); |
| 5972 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition"); |
| 5973 | cmd_AddParm(ts, "-toname", CMD_SINGLE2, CMD_OPTIONAL1, |
| 5974 | "volume name on destination"); |
| 5975 | cmd_AddParm(ts, "-toid", CMD_SINGLE2, CMD_OPTIONAL1, |
| 5976 | "volume ID on destination"); |
| 5977 | cmd_AddParm(ts, "-offline", CMD_FLAG1, CMD_OPTIONAL1, |
| 5978 | "leave clone volume offline"); |
| 5979 | cmd_AddParm(ts, "-readonly", CMD_FLAG1, CMD_OPTIONAL1, |
| 5980 | "make clone volume read-only, not readwrite"); |
| 5981 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5982 | |
| 5983 | ts = cmd_CreateSyntax("release", ReleaseVolume, NULL((void *)0), "release a volume"); |
| 5984 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 5985 | cmd_AddParm(ts, "-force", CMD_FLAG1, CMD_OPTIONAL1, |
| 5986 | "force a complete release"); |
| 5987 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 5988 | |
| 5989 | ts = cmd_CreateSyntax("dump", DumpVolumeCmd, NULL((void *)0), "dump a volume"); |
| 5990 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 5991 | cmd_AddParm(ts, "-time", CMD_SINGLE2, CMD_OPTIONAL1, "dump from time"); |
| 5992 | cmd_AddParm(ts, "-file", CMD_SINGLE2, CMD_OPTIONAL1, "dump file"); |
| 5993 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "server"); |
| 5994 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition"); |
| 5995 | cmd_AddParm(ts, "-clone", CMD_FLAG1, CMD_OPTIONAL1, |
| 5996 | "dump a clone of the volume"); |
| 5997 | cmd_AddParm(ts, "-omitdirs", CMD_FLAG1, CMD_OPTIONAL1, |
| 5998 | "omit unchanged directories from an incremental dump"); |
| 5999 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6000 | |
| 6001 | ts = cmd_CreateSyntax("restore", RestoreVolumeCmd, NULL((void *)0), |
| 6002 | "restore a volume"); |
| 6003 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6004 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 6005 | cmd_AddParm(ts, "-name", CMD_SINGLE2, 0, "name of volume to be restored"); |
| 6006 | cmd_AddParm(ts, "-file", CMD_SINGLE2, CMD_OPTIONAL1, "dump file"); |
| 6007 | cmd_AddParm(ts, "-id", CMD_SINGLE2, CMD_OPTIONAL1, "volume ID"); |
| 6008 | cmd_AddParm(ts, "-overwrite", CMD_SINGLE2, CMD_OPTIONAL1, |
| 6009 | "abort | full | incremental"); |
| 6010 | cmd_AddParm(ts, "-offline", CMD_FLAG1, CMD_OPTIONAL1, |
| 6011 | "leave restored volume offline"); |
| 6012 | cmd_AddParm(ts, "-readonly", CMD_FLAG1, CMD_OPTIONAL1, |
| 6013 | "make restored volume read-only"); |
| 6014 | cmd_AddParm(ts, "-creation", CMD_SINGLE2, CMD_OPTIONAL1, |
| 6015 | "dump | keep | new"); |
| 6016 | cmd_AddParm(ts, "-lastupdate", CMD_SINGLE2, CMD_OPTIONAL1, |
| 6017 | "dump | keep | new"); |
| 6018 | cmd_AddParm(ts, "-nodelete", CMD_FLAG1, CMD_OPTIONAL1, |
| 6019 | "do not delete old site when restoring to a new site"); |
| 6020 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6021 | |
| 6022 | ts = cmd_CreateSyntax("unlock", LockReleaseCmd, NULL((void *)0), |
| 6023 | "release lock on VLDB entry for a volume"); |
| 6024 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6025 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6026 | |
| 6027 | ts = cmd_CreateSyntax("changeloc", ChangeLocation, NULL((void *)0), |
| 6028 | "change an RW volume's location in the VLDB"); |
| 6029 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, |
| 6030 | "machine name for new location"); |
| 6031 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, |
| 6032 | "partition name for new location"); |
| 6033 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6034 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6035 | |
| 6036 | ts = cmd_CreateSyntax("addsite", AddSite, NULL((void *)0), "add a replication site"); |
| 6037 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name for new site"); |
| 6038 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, |
| 6039 | "partition name for new site"); |
| 6040 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6041 | cmd_AddParm(ts, "-roid", CMD_SINGLE2, CMD_OPTIONAL1, "volume name or ID for RO"); |
| 6042 | cmd_AddParm(ts, "-valid", CMD_FLAG1, CMD_OPTIONAL1, "publish as an up-to-date site in VLDB"); |
| 6043 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6044 | |
| 6045 | ts = cmd_CreateSyntax("remsite", RemoveSite, NULL((void *)0), |
| 6046 | "remove a replication site"); |
| 6047 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6048 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 6049 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6050 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6051 | |
| 6052 | ts = cmd_CreateSyntax("listpart", ListPartitions, NULL((void *)0), "list partitions"); |
| 6053 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6054 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6055 | |
| 6056 | ts = cmd_CreateSyntax("listvol", ListVolumes, NULL((void *)0), |
| 6057 | "list volumes on server (bypass VLDB)"); |
| 6058 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6059 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6060 | cmd_AddParm(ts, "-fast", CMD_FLAG1, CMD_OPTIONAL1, "minimal listing"); |
| 6061 | cmd_AddParm(ts, "-long", CMD_FLAG1, CMD_OPTIONAL1, |
| 6062 | "list all normal volume fields"); |
| 6063 | cmd_AddParm(ts, "-quiet", CMD_FLAG1, CMD_OPTIONAL1, |
| 6064 | "generate minimal information"); |
| 6065 | cmd_AddParm(ts, "-extended", CMD_FLAG1, CMD_OPTIONAL1, |
| 6066 | "list extended volume fields"); |
| 6067 | cmd_AddParm(ts, "-format", CMD_FLAG1, CMD_OPTIONAL1, |
| 6068 | "machine readable format"); |
| 6069 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6070 | |
| 6071 | ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL((void *)0), |
| 6072 | "synchronize VLDB with server"); |
| 6073 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 6074 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6075 | cmd_AddParm(ts, "-volume", CMD_SINGLE2, CMD_OPTIONAL1, "volume name or ID"); |
| 6076 | cmd_AddParm(ts, "-dryrun", CMD_FLAG1, CMD_OPTIONAL1, "list what would be done, don't do it"); |
| 6077 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6078 | |
| 6079 | ts = cmd_CreateSyntax("syncserv", SyncServer, NULL((void *)0), |
| 6080 | "synchronize server with VLDB"); |
| 6081 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6082 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6083 | cmd_AddParm(ts, "-dryrun", CMD_FLAG1, CMD_OPTIONAL1, "list what would be done, don't do it"); |
| 6084 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6085 | |
| 6086 | ts = cmd_CreateSyntax("examine", ExamineVolume, NULL((void *)0), |
| 6087 | "everything about the volume"); |
| 6088 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6089 | cmd_AddParm(ts, "-extended", CMD_FLAG1, CMD_OPTIONAL1, |
| 6090 | "list extended volume fields"); |
| 6091 | cmd_AddParm(ts, "-format", CMD_FLAG1, CMD_OPTIONAL1, |
| 6092 | "machine readable format"); |
| 6093 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6094 | cmd_CreateAlias(ts, "volinfo"); |
| 6095 | |
| 6096 | ts = cmd_CreateSyntax("setfields", SetFields, NULL((void *)0), |
| 6097 | "change volume info fields"); |
| 6098 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6099 | cmd_AddParm(ts, "-maxquota", CMD_SINGLE2, CMD_OPTIONAL1, "quota (KB)"); |
| 6100 | cmd_AddParm(ts, "-clearuse", CMD_FLAG1, CMD_OPTIONAL1, "clear dayUse"); |
| 6101 | cmd_AddParm(ts, "-clearVolUpCounter", CMD_FLAG1, CMD_OPTIONAL1, "clear volUpdateCounter"); |
| 6102 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6103 | |
| 6104 | ts = cmd_CreateSyntax("offline", volOffline, NULL((void *)0), "force the volume status to offline"); |
| 6105 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "server name"); |
| 6106 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 6107 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6108 | cmd_AddParm(ts, "-sleep", CMD_SINGLE2, CMD_OPTIONAL1, "seconds to sleep"); |
| 6109 | cmd_AddParm(ts, "-busy", CMD_FLAG1, CMD_OPTIONAL1, "busy volume"); |
| 6110 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6111 | |
| 6112 | ts = cmd_CreateSyntax("online", volOnline, NULL((void *)0), "force the volume status to online"); |
| 6113 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "server name"); |
| 6114 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 6115 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6116 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6117 | |
| 6118 | ts = cmd_CreateSyntax("zap", VolumeZap, NULL((void *)0), |
| 6119 | "delete the volume, don't bother with VLDB"); |
| 6120 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6121 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 6122 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume ID"); |
| 6123 | cmd_AddParm(ts, "-force", CMD_FLAG1, CMD_OPTIONAL1, |
| 6124 | "force deletion of bad volumes"); |
| 6125 | cmd_AddParm(ts, "-backup", CMD_FLAG1, CMD_OPTIONAL1, |
| 6126 | "also delete backup volume if one is found"); |
| 6127 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6128 | |
| 6129 | ts = cmd_CreateSyntax("status", VolserStatus, NULL((void *)0), |
| 6130 | "report on volser status"); |
| 6131 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6132 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6133 | |
| 6134 | ts = cmd_CreateSyntax("rename", RenameVolume, NULL((void *)0), "rename a volume"); |
| 6135 | cmd_AddParm(ts, "-oldname", CMD_SINGLE2, 0, "old volume name "); |
| 6136 | cmd_AddParm(ts, "-newname", CMD_SINGLE2, 0, "new volume name "); |
| 6137 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6138 | |
| 6139 | ts = cmd_CreateSyntax("listvldb", ListVLDB, NULL((void *)0), |
| 6140 | "list volumes in the VLDB"); |
| 6141 | cmd_AddParm(ts, "-name", CMD_SINGLE2, CMD_OPTIONAL1, "volume name or ID"); |
| 6142 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 6143 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6144 | cmd_AddParm(ts, "-locked", CMD_FLAG1, CMD_OPTIONAL1, "locked volumes only"); |
| 6145 | cmd_AddParm(ts, "-quiet", CMD_FLAG1, CMD_OPTIONAL1, |
| 6146 | "generate minimal information"); |
| 6147 | cmd_AddParm(ts, "-nosort", CMD_FLAG1, CMD_OPTIONAL1, |
| 6148 | "do not alphabetically sort the volume names"); |
| 6149 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6150 | |
| 6151 | ts = cmd_CreateSyntax("backupsys", BackSys, NULL((void *)0), "en masse backups"); |
| 6152 | cmd_AddParm(ts, "-prefix", CMD_LIST3, CMD_OPTIONAL1, |
| 6153 | "common prefix on volume(s)"); |
| 6154 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 6155 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6156 | cmd_AddParm(ts, "-exclude", CMD_FLAG1, CMD_OPTIONAL1, |
| 6157 | "exclude common prefix volumes"); |
| 6158 | cmd_AddParm(ts, "-xprefix", CMD_LIST3, CMD_OPTIONAL1, |
| 6159 | "negative prefix on volume(s)"); |
| 6160 | cmd_AddParm(ts, "-dryrun", CMD_FLAG1, CMD_OPTIONAL1, "list what would be done, don't do it"); |
| 6161 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6162 | |
| 6163 | ts = cmd_CreateSyntax("delentry", DeleteEntry, NULL((void *)0), |
| 6164 | "delete VLDB entry for a volume"); |
| 6165 | cmd_AddParm(ts, "-id", CMD_LIST3, CMD_OPTIONAL1, "volume name or ID"); |
| 6166 | cmd_AddParm(ts, "-prefix", CMD_SINGLE2, CMD_OPTIONAL1, |
| 6167 | "prefix of the volume whose VLDB entry is to be deleted"); |
| 6168 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 6169 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6170 | cmd_AddParm(ts, "-noexecute", CMD_FLAG1, CMD_OPTIONAL1|CMD_HIDDEN4, ""); |
| 6171 | cmd_AddParm(ts, "-dryrun", CMD_FLAG1, CMD_OPTIONAL1, |
| 6172 | "list what would be done, don't do it"); |
| 6173 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6174 | |
| 6175 | ts = cmd_CreateSyntax("partinfo", PartitionInfo, NULL((void *)0), |
| 6176 | "list partition information"); |
| 6177 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6178 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6179 | cmd_AddParm(ts, "-summary", CMD_FLAG1, CMD_OPTIONAL1, |
| 6180 | "print storage summary"); |
| 6181 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6182 | |
| 6183 | ts = cmd_CreateSyntax("unlockvldb", UnlockVLDB, NULL((void *)0), |
| 6184 | "unlock all the locked entries in the VLDB"); |
| 6185 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 6186 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6187 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6188 | |
| 6189 | ts = cmd_CreateSyntax("lock", LockEntry, NULL((void *)0), |
| 6190 | "lock VLDB entry for a volume"); |
| 6191 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6192 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6193 | |
| 6194 | ts = cmd_CreateSyntax("changeaddr", ChangeAddr, NULL((void *)0), |
| 6195 | "change the IP address of a file server"); |
| 6196 | cmd_AddParm(ts, "-oldaddr", CMD_SINGLE2, 0, "original IP address"); |
| 6197 | cmd_AddParm(ts, "-newaddr", CMD_SINGLE2, CMD_OPTIONAL1, "new IP address"); |
| 6198 | cmd_AddParm(ts, "-remove", CMD_FLAG1, CMD_OPTIONAL1, |
| 6199 | "remove the IP address from the VLDB"); |
| 6200 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6201 | |
| 6202 | ts = cmd_CreateSyntax("listaddrs", ListAddrs, NULL((void *)0), |
| 6203 | "list the IP address of all file servers registered in the VLDB"); |
| 6204 | cmd_AddParm(ts, "-uuid", CMD_SINGLE2, CMD_OPTIONAL1, "uuid of server"); |
| 6205 | cmd_AddParm(ts, "-host", CMD_SINGLE2, CMD_OPTIONAL1, "address of host"); |
| 6206 | cmd_AddParm(ts, "-printuuid", CMD_FLAG1, CMD_OPTIONAL1, |
| 6207 | "print uuid of hosts"); |
| 6208 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6209 | |
| 6210 | ts = cmd_CreateSyntax("convertROtoRW", ConvertRO, NULL((void *)0), |
| 6211 | "convert a RO volume into a RW volume (after loss of old RW volume)"); |
| 6212 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6213 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, 0, "partition name"); |
| 6214 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6215 | cmd_AddParm(ts, "-force", CMD_FLAG1, CMD_OPTIONAL1, "don't ask"); |
| 6216 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6217 | |
| 6218 | ts = cmd_CreateSyntax("size", Sizes, NULL((void *)0), |
| 6219 | "obtain various sizes of the volume."); |
| 6220 | cmd_AddParm(ts, "-id", CMD_SINGLE2, 0, "volume name or ID"); |
| 6221 | cmd_AddParm(ts, "-partition", CMD_SINGLE2, CMD_OPTIONAL1, "partition name"); |
| 6222 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, "machine name"); |
| 6223 | cmd_AddParm(ts, "-dump", CMD_FLAG1, CMD_OPTIONAL1, |
| 6224 | "Obtain the size of the dump"); |
| 6225 | cmd_AddParm(ts, "-time", CMD_SINGLE2, CMD_OPTIONAL1, "dump from time"); |
| 6226 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6227 | |
| 6228 | ts = cmd_CreateSyntax("endtrans", EndTrans, NULL((void *)0), |
| 6229 | "end a volserver transaction"); |
| 6230 | cmd_AddParm(ts, "-server", CMD_SINGLE2, 0, "machine name"); |
| 6231 | cmd_AddParm(ts, "-transaction", CMD_SINGLE2, 0, |
| 6232 | "transaction ID"); |
| 6233 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6234 | |
| 6235 | ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL((void *)0), |
| 6236 | "set the list of IP address for a given UUID in the VLDB"); |
| 6237 | cmd_AddParm(ts, "-uuid", CMD_SINGLE2, 0, "uuid of server"); |
| 6238 | cmd_AddParm(ts, "-host", CMD_LIST3, 0, "address of host"); |
| 6239 | |
| 6240 | COMMONPARMScmd_Seek(ts, 12);cmd_AddParm(ts, "-cell", 2, 1, "cell name"); cmd_AddParm(ts, "-noauth", 1, 1, "don't authenticate");cmd_AddParm (ts, "-localauth",1,1,"use server tickets");cmd_AddParm(ts, "-verbose" , 1, 1, "verbose");cmd_AddParm(ts, "-encrypt", 1, 1, "encrypt commands" );cmd_AddParm(ts, "-noresolve", 1, 1, "don't resolve addresses" ); cmd_AddParm(ts, "-config", 2, 1, "config location");; |
| 6241 | code = cmd_Dispatch(argc, argv); |
| 6242 | if (rxInitDone) { |
| 6243 | /* Shut down the ubik_client and rx connections */ |
| 6244 | if (cstruct) { |
| 6245 | (void)ubik_ClientDestroy(cstruct); |
| 6246 | cstruct = 0; |
| 6247 | } |
| 6248 | rx_Finalize(); |
| 6249 | } |
| 6250 | |
| 6251 | exit((code ? -1 : 0)); |
| 6252 | } |