Print this page
*** NO COMMENTS ***

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/fs.d/nfs/umount/umount.c
          +++ new/usr/src/cmd/fs.d/nfs/umount/umount.c
↓ open down ↓ 67 lines elided ↑ open up ↑
  68   68  
  69   69  #ifdef __STDC__
  70   70  static void pr_err(const char *fmt, ...);
  71   71  #else
  72   72  static void pr_err(char *fmt, va_dcl);
  73   73  #endif
  74   74  static  void    usage();
  75   75  static  int     nfs_unmount(char *, int);
  76   76  static  void    inform_server(char *, char *, bool_t);
  77   77  static  struct extmnttab *mnttab_find();
  78      -extern int __clnt_bindresvport();
       78 +extern int __clnt_bindresvport(CLIENT *);
  79   79  
  80   80  static  int is_v4_mount(struct extmnttab *);
  81   81  
  82   82  static char *myname;
  83   83  static char typename[64];
  84   84  
  85   85  int
  86   86  main(int argc, char *argv[])
  87   87  {
  88   88          extern int optind;
↓ open down ↓ 2 lines elided ↑ open up ↑
  91   91  
  92   92          (void) setlocale(LC_ALL, "");
  93   93  
  94   94  #if !defined(TEXT_DOMAIN)
  95   95  #define TEXT_DOMAIN "SYS_TEST"
  96   96  #endif
  97   97          (void) textdomain(TEXT_DOMAIN);
  98   98  
  99   99          myname = strrchr(argv[0], '/');
 100  100          myname = myname ? myname+1 : argv[0];
 101      -        (void) sprintf(typename, "nfs %s", myname);
      101 +        (void) snprintf(typename, sizeof (typename), "nfs %s", myname);
 102  102          argv[0] = typename;
 103  103  
 104  104          /*
 105  105           * Set options
 106  106           */
 107  107          while ((c = getopt(argc, argv, "f")) != EOF) {
 108  108                  switch (c) {
 109  109                  case 'f':
 110  110                          umnt_flag |= MS_FORCE; /* forced unmount is desired */
 111  111                          break;
↓ open down ↓ 35 lines elided ↑ open up ↑
 147  147          (void) fprintf(stderr, "%s: ", typename);
 148  148          (void) vfprintf(stderr, fmt, ap);
 149  149          (void) fflush(stderr);
 150  150          va_end(ap);
 151  151  }
 152  152  
 153  153  static void
 154  154  usage()
 155  155  {
 156  156          (void) fprintf(stderr,
 157      -            gettext("Usage: nfs umount [-o opts] {server:path | dir}\n"));
      157 +            gettext("Usage: nfs umount [-f] {server:path | dir}\n"));
 158  158          exit(RET_ERR);
 159  159  }
 160  160  
 161  161  static int
 162  162  nfs_unmount(char *pathname, int umnt_flag)
 163  163  {
 164  164          struct extmnttab *mntp;
 165  165          bool_t quick = FALSE;
 166  166          int is_v4 = FALSE;
 167  167  
↓ open down ↓ 51 lines elided ↑ open up ↑
 219  219          }
 220  220          while (getextmntent(fp, &mnt, sizeof (struct extmnttab)) == 0) {
 221  221                  if (strcmp(mnt.mnt_mountp, dirname) == 0 ||
 222  222                      strcmp(mnt.mnt_special, dirname) == 0) {
 223  223                          if (res)
 224  224                                  fsfreemnttab(res);
 225  225                          res = fsdupmnttab(&mnt);
 226  226                  }
 227  227          }
 228  228  
 229      -        fclose(fp);
      229 +        (void) fclose(fp);
 230  230          return (res);
 231  231  }
 232  232  
 233  233  /*
 234  234   * If quick is TRUE, it will try to inform server quickly
 235  235   * as possible.
 236  236   */
 237  237  static void
 238  238  inform_server(char *string, char *opts, bool_t quick)
 239  239  {
↓ open down ↓ 4 lines elided ↑ open up ↑
 244  244          int i, n;
 245  245          char *p = NULL;
 246  246          static struct timeval create_timeout = {5, 0};
 247  247          static struct timeval *timep;
 248  248  
 249  249          list = parse_replica(string, &n);
 250  250  
 251  251          if (list == NULL) {
 252  252                  if (n < 0)
 253  253                          pr_err(gettext("%s is not hostname:path format\n"),
 254      -                                string);
      254 +                            string);
 255  255                  else
 256  256                          pr_err(gettext("no memory\n"));
 257  257                  return;
 258  258          }
 259  259  
 260  260          /*
 261  261           * If mounted with -o public, then no need to contact server
 262  262           * because mount protocol was not used.
 263  263           */
 264  264          if (opts != NULL)
↓ open down ↓ 24 lines elided ↑ open up ↑
 289  289                  vers =  MOUNTVERS;
 290  290  retry:
 291  291                  /*
 292  292                   * Use 5 sec. timeout if file system is forced unmounted,
 293  293                   * otherwise use default timeout to create a client handle.
 294  294                   * This would minimize the time to force unmount a file
 295  295                   * system reside on a server that is down.
 296  296                   */
 297  297                  timep = (quick ? &create_timeout : NULL);
 298  298                  cl = clnt_create_timed(list[i].host, MOUNTPROG, vers,
 299      -                                "datagram_n", timep);
      299 +                    "datagram_n", timep);
 300  300                  /*
 301  301                   * Do not print any error messages in case of forced
 302  302                   * unmount.
 303  303                   */
 304  304                  if (cl == NULL) {
 305  305                          if (!quick)
 306  306                                  pr_err("%s:%s %s\n", list[i].host, list[i].path,
 307  307                                      clnt_spcreateerror(
 308      -                                        "server not responding"));
      308 +                                    "server not responding"));
 309  309                          continue;
 310  310                  }
 311  311                  /*
 312  312                   * Now it is most likely that the NFS client will be able
 313  313                   * to contact the server since rpcbind is running on
 314  314                   * the server. There is still a small window in which
 315  315                   * server can be unreachable.
 316  316                   */
 317  317  
 318  318                  if (__clnt_bindresvport(cl) < 0) {
↓ open down ↓ 8 lines elided ↑ open up ↑
 327  327                                  pr_err(gettext(
 328  328                                      "couldn't create authsys structure\n"));
 329  329                          clnt_destroy(cl);
 330  330                          return;
 331  331                  }
 332  332                  timeout.tv_usec = 0;
 333  333                  timeout.tv_sec = 5;
 334  334                  clnt_control(cl, CLSET_RETRY_TIMEOUT, (char *)&timeout);
 335  335                  timeout.tv_sec = 25;
 336  336                  rpc_stat = clnt_call(cl, MOUNTPROC_UMNT, xdr_dirpath,
 337      -                        (char *)&list[i].path, xdr_void, (char *)NULL,
 338      -                        timeout);
      337 +                    (char *)&list[i].path, xdr_void, (char *)NULL,
      338 +                    timeout);
 339  339                  AUTH_DESTROY(cl->cl_auth);
 340  340                  clnt_destroy(cl);
 341  341                  if (rpc_stat == RPC_PROGVERSMISMATCH && vers == MOUNTVERS) {
 342  342                          /*
 343  343                           * The rare case of a v3-only server
 344  344                           */
 345  345                          vers = MOUNTVERS3;
 346  346                          goto retry;
 347  347                  }
 348  348                  if (rpc_stat != RPC_SUCCESS)
↓ open down ↓ 5 lines elided ↑ open up ↑
 354  354  
 355  355  /*
 356  356   * This function's behavior is taken from nfsstat.
 357  357   * Trying to determine what NFS version was used for the mount.
 358  358   */
 359  359  int
 360  360  is_v4_mount(struct extmnttab *mntp)
 361  361  {
 362  362          kstat_ctl_t *kc = NULL;         /* libkstat cookie */
 363  363          kstat_t *ksp;
 364      -        ulong_t fsid;
 365  364          struct mntinfo_kstat mik;
 366  365  
 367  366          if (mntp == NULL)
 368  367                  return (FALSE);
 369  368  
 370  369          if ((kc = kstat_open()) == NULL)
 371  370                  return (FALSE);
 372  371  
 373  372          for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
 374  373                  if (ksp->ks_type != KSTAT_TYPE_RAW)
↓ open down ↓ 18 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX