aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-10 18:48:16 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-10 18:48:16 +0000
commit30772946156dc49d04389b61bcd828ed352a00cc (patch)
treeb2c84d8a3f8ed29ae2e2d66beab7ec8153089a69
parentd2b13eab9805b4edd51d2e658f0d032d08f5de98 (diff)
downloadbusybox-w32-30772946156dc49d04389b61bcd828ed352a00cc.tar.gz
busybox-w32-30772946156dc49d04389b61bcd828ed352a00cc.tar.bz2
busybox-w32-30772946156dc49d04389b61bcd828ed352a00cc.zip
nfsmount: remove some really old code (for kernels 1.x!) + small cleanups.
-rw-r--r--util-linux/nfsmount.c123
1 files changed, 63 insertions, 60 deletions
diff --git a/util-linux/nfsmount.c b/util-linux/nfsmount.c
index 43c3b663d..d43bc3e3c 100644
--- a/util-linux/nfsmount.c
+++ b/util-linux/nfsmount.c
@@ -345,6 +345,7 @@ enum {
345 * nfs_mount_version according to the sources seen at compile time. 345 * nfs_mount_version according to the sources seen at compile time.
346 */ 346 */
347static int nfs_mount_version; 347static int nfs_mount_version;
348static int kernel_version;
348 349
349/* 350/*
350 * Unfortunately, the kernel prints annoying console messages 351 * Unfortunately, the kernel prints annoying console messages
@@ -360,8 +361,6 @@ static int nfs_mount_version;
360static void 361static void
361find_kernel_nfs_mount_version(void) 362find_kernel_nfs_mount_version(void)
362{ 363{
363 static int kernel_version = 0;
364
365 if (kernel_version) 364 if (kernel_version)
366 return; 365 return;
367 366
@@ -372,14 +371,11 @@ find_kernel_nfs_mount_version(void)
372 if (kernel_version < KERNEL_VERSION(2,1,32)) 371 if (kernel_version < KERNEL_VERSION(2,1,32))
373 nfs_mount_version = 1; 372 nfs_mount_version = 1;
374 else if (kernel_version < KERNEL_VERSION(2,2,18) || 373 else if (kernel_version < KERNEL_VERSION(2,2,18) ||
375 (kernel_version >= KERNEL_VERSION(2,3,0) && 374 (kernel_version >= KERNEL_VERSION(2,3,0) &&
376 kernel_version < KERNEL_VERSION(2,3,99))) 375 kernel_version < KERNEL_VERSION(2,3,99)))
377 nfs_mount_version = 3; 376 nfs_mount_version = 3;
378 else 377 /* else v4 since 2.3.99pre4 */
379 nfs_mount_version = 4; /* since 2.3.99pre4 */
380 } 378 }
381 if (nfs_mount_version > 4)
382 nfs_mount_version = 4;
383} 379}
384 380
385static struct pmap * 381static struct pmap *
@@ -433,14 +429,31 @@ next:
433int nfsmount(const char *spec, const char *node, int *flags, 429int nfsmount(const char *spec, const char *node, int *flags,
434 char **mount_opts, int running_bg) 430 char **mount_opts, int running_bg)
435{ 431{
432 /* prev_bg_host is a -o bg support:
433 * "bg: if the first NFS mount attempt times out,
434 * retry the mount in the background.
435 * After a mount operation is backgrounded,
436 * all subsequent mounts on the same NFS server
437 * will be backgrounded immediately, without first
438 * attempting the mount. A missing mount point is treated
439 * as a timeout, to allow for nested NFS mounts."
440 *
441 * But current implementation is a dirty hack -
442 * it works only if all mounts are to one host!
443 * IOW: think what will happen if you have this sequence:
444 * mount a.a.a.a:/dir /mnt/a -o bg
445 * mount b.b.b.b:/dir /mnt/b -o bg
446 * mount a.a.a.a:/dir /mnt/a -o bg
447 * mount b.b.b.b:/dir /mnt/b -o bg
448 */
449
436 static char *prev_bg_host; 450 static char *prev_bg_host;
437 char hostdir[1024]; 451 char *hostdir;
438 CLIENT *mclient; 452 CLIENT *mclient;
439 char *hostname; 453 char *hostname;
440 char *pathname; 454 char *pathname;
441 char *old_opts; 455 char *old_opts;
442 char *mounthost = NULL; 456 char *mounthost;
443 char new_opts[1024];
444 struct timeval total_timeout; 457 struct timeval total_timeout;
445 enum clnt_stat clnt_stat; 458 enum clnt_stat clnt_stat;
446 struct nfs_mount_data data; 459 struct nfs_mount_data data;
@@ -481,27 +494,26 @@ int nfsmount(const char *spec, const char *node, int *flags,
481 494
482 find_kernel_nfs_mount_version(); 495 find_kernel_nfs_mount_version();
483 496
497 /* NB: old_opts and hostdir must be free()d prior to return! */
498
499 old_opts = NULL;
500 mounthost = NULL;
484 retval = EX_FAIL; 501 retval = EX_FAIL;
485 msock = fsock = -1; 502 msock = fsock = -1;
486 mclient = NULL; 503 mclient = NULL;
487 if (strlen(spec) >= sizeof(hostdir)) { 504
488 bb_error_msg("excessively long host:dir argument"); 505 hostdir = xstrdup(spec);
489 goto fail; 506 /* mount_main() guarantees that ':' is there */
490 } 507 s = strchr(hostdir, ':');
491 strcpy(hostdir, spec); 508 hostname = hostdir;
492 if ((s = strchr(hostdir, ':'))) { 509 pathname = s + 1;
493 hostname = hostdir; 510 *s = '\0';
494 pathname = s + 1; 511 /* Ignore all but first hostname in replicated mounts
512 until they can be fully supported. (mack@sgi.com) */
513 s = strchr(hostdir, ',');
514 if (s) {
495 *s = '\0'; 515 *s = '\0';
496 /* Ignore all but first hostname in replicated mounts 516 bb_error_msg("warning: multiple hostnames not supported");
497 until they can be fully supported. (mack@sgi.com) */
498 if ((s = strchr(hostdir, ','))) {
499 *s = '\0';
500 bb_error_msg("warning: multiple hostnames not supported");
501 }
502 } else {
503 bb_error_msg("directory to mount not in host:dir format");
504 goto fail;
505 } 517 }
506 518
507 server_addr.sin_family = AF_INET; 519 server_addr.sin_family = AF_INET;
@@ -509,34 +521,29 @@ int nfsmount(const char *spec, const char *node, int *flags,
509 if (!inet_aton(hostname, &server_addr.sin_addr)) 521 if (!inet_aton(hostname, &server_addr.sin_addr))
510#endif 522#endif
511 { 523 {
512 if ((hp = gethostbyname(hostname)) == NULL) { 524 hp = gethostbyname(hostname);
525 if (hp == NULL) {
513 bb_herror_msg("%s", hostname); 526 bb_herror_msg("%s", hostname);
514 goto fail; 527 goto fail;
515 } else {
516 if (hp->h_length > sizeof(struct in_addr)) {
517 bb_error_msg("got bad hp->h_length");
518 hp->h_length = sizeof(struct in_addr);
519 }
520 memcpy(&server_addr.sin_addr,
521 hp->h_addr, hp->h_length);
522 } 528 }
529 if (hp->h_length > sizeof(struct in_addr)) {
530 bb_error_msg("got bad hp->h_length");
531 hp->h_length = sizeof(struct in_addr);
532 }
533 memcpy(&server_addr.sin_addr,
534 hp->h_addr, hp->h_length);
523 } 535 }
524 536
525 memcpy(&mount_server_addr, &server_addr, sizeof (mount_server_addr)); 537 memcpy(&mount_server_addr, &server_addr, sizeof(mount_server_addr));
526 538
527 /* add IP address to mtab options for use when unmounting */ 539 /* add IP address to mtab options for use when unmounting */
528 540
529 s = inet_ntoa(server_addr.sin_addr); 541 s = inet_ntoa(server_addr.sin_addr);
530 old_opts = *mount_opts; 542 old_opts = *mount_opts;
531 if (!old_opts) 543 if (!old_opts)
532 old_opts = ""; 544 old_opts = xstrdup("");
533 if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) { 545 *mount_opts = xasprintf("%s%saddr=%s",
534 bb_error_msg("excessively long option argument"); 546 old_opts, *old_opts ? "," : "", s);
535 goto fail;
536 }
537 sprintf(new_opts, "%s%saddr=%s",
538 old_opts, *old_opts ? "," : "", s);
539 *mount_opts = xstrdup(new_opts);
540 547
541 /* Set default options. 548 /* Set default options.
542 * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to 549 * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to
@@ -570,7 +577,8 @@ int nfsmount(const char *spec, const char *node, int *flags,
570 /* parse options */ 577 /* parse options */
571 578
572 for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) { 579 for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
573 if ((opteq = strchr(opt, '='))) { 580 opteq = strchr(opt, '=');
581 if (opteq) {
574 val = atoi(opteq + 1); 582 val = atoi(opteq + 1);
575 *opteq = '\0'; 583 *opteq = '\0';
576 if (!strcmp(opt, "rsize")) 584 if (!strcmp(opt, "rsize"))
@@ -681,8 +689,8 @@ int nfsmount(const char *spec, const char *node, int *flags,
681 if (nfs_mount_version >= 3) 689 if (nfs_mount_version >= 3)
682 data.flags |= (nolock ? NFS_MOUNT_NONLM : 0); 690 data.flags |= (nolock ? NFS_MOUNT_NONLM : 0);
683 if (nfsvers > MAX_NFSPROT || mountvers > MAX_NFSPROT) { 691 if (nfsvers > MAX_NFSPROT || mountvers > MAX_NFSPROT) {
684 bb_error_msg("NFSv%d not supported!", nfsvers); 692 bb_error_msg("NFSv%d not supported", nfsvers);
685 return 1; 693 goto fail;
686 } 694 }
687 if (nfsvers && !mountvers) 695 if (nfsvers && !mountvers)
688 mountvers = (nfsvers < 3) ? 1 : nfsvers; 696 mountvers = (nfsvers < 3) ? 1 : nfsvers;
@@ -727,7 +735,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
727 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) { 735 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) {
728 if (retry > 0) 736 if (retry > 0)
729 retval = EX_BG; 737 retval = EX_BG;
730 return retval; 738 goto ret;
731 } 739 }
732 740
733 /* create mount daemon client */ 741 /* create mount daemon client */
@@ -941,17 +949,6 @@ int nfsmount(const char *spec, const char *node, int *flags,
941 printf("using port %d for nfs daemon\n", port); 949 printf("using port %d for nfs daemon\n", port);
942#endif 950#endif
943 server_addr.sin_port = htons(port); 951 server_addr.sin_port = htons(port);
944 /*
945 * connect() the socket for kernels 1.3.10 and below only,
946 * to avoid problems with multihomed hosts.
947 * --Swen
948 */
949 if (get_linux_version_code() <= KERNEL_VERSION(2,3,10)
950 && connect(fsock, (struct sockaddr *) &server_addr,
951 sizeof (server_addr)) < 0) {
952 perror("nfs connect");
953 goto fail;
954 }
955 952
956 /* prepare data structure for kernel */ 953 /* prepare data structure for kernel */
957 954
@@ -967,7 +964,9 @@ int nfsmount(const char *spec, const char *node, int *flags,
967copy_data_and_return: 964copy_data_and_return:
968 *mount_opts = xrealloc(*mount_opts, sizeof(data)); 965 *mount_opts = xrealloc(*mount_opts, sizeof(data));
969 memcpy(*mount_opts, &data, sizeof(data)); 966 memcpy(*mount_opts, &data, sizeof(data));
970 return 0; 967
968 retval = 0;
969 goto ret;
971 970
972 /* abort */ 971 /* abort */
973 972
@@ -981,5 +980,9 @@ fail:
981 } 980 }
982 if (fsock != -1) 981 if (fsock != -1)
983 close(fsock); 982 close(fsock);
983
984ret:
985 free(hostdir);
986 free(old_opts);
984 return retval; 987 return retval;
985} 988}