Bug 12911

Summary: NFS umounts are not properly done if just the mountpoint gets umounted
Product: Base System Reporter: blapp <blapp>
Component: binAssignee: Alfred Perlstein <alfred>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description blapp 1999-08-01 20:10:00 UTC
If you umount a nfs-mountpoint, the server will not get an
authentificated umount request. If you unmount it with the full
path it works. With Linux 2.2 and Irix 6.5.2 as clients both
'umount /mountpoint' and 'umount somehost:/somedir' work.

Fix: 

workaround (no fix !):

# umount somehost:/somedir
How-To-Repeat: Client:

# mount somehost:/somedir /mountpoint
# umount /mountpoint

Server:

# showmount
Comment 1 mblapp 1999-08-01 22:31:17 UTC
Sorry - should be changed to bin/12911

Martin
Comment 2 bill fumerola freebsd_committer freebsd_triage 1999-08-09 01:17:21 UTC
Responsible Changed
From-To: freebsd-bugs->billf

The submitter sent me a patch, I am testing it. 

Comment 3 mblapp 1999-08-09 01:22:57 UTC
This should fix the problem with /usr/src/sbin/umount/umount.c :

--- umount.c    Mon Aug  3 08:44:46 1998
+++ umount.c    Mon Aug  9 02:00:10 1999
@@ -209,6 +209,8 @@
        struct sockaddr_in saddr;
        struct stat sb;
        struct timeval pertry, try;
+       char *mntfromname;
+
        CLIENT *clp;
        int so;
        char *type, *delimp, *hostp, *mntpt, *origname,
rname[MAXPATHLEN];
@@ -259,6 +261,16 @@
                        hp = gethostbyname(hostp);
                        name = delimp + 1;
                        *delimp = ':';
+               } else {
+                       mntfromname = (getmntname(rname, MNTFROM,
&type));
+                       name = mntfromname;
+                       if ((delimp = strchr(name, ':')) != NULL) {
+                               *delimp = '\0';
+                               hostp = name;
+                               hp = gethostbyname(hostp);
+                               name = delimp + 1;
+                               *delimp = ':';
+                       }
                }
        }
Comment 4 mblapp 1999-08-09 21:35:41 UTC
I reviewed my patch and recognized that nfs-unmounts within '@' were
still not fixed by my patch. I found and fixed other problems in
umount.c :

- getmntname() was not the right way recursive, so always the first
  mount on the same mountpoint was umounted. (fixed)
- umount -v had also problems with this, because it depends from
  getmntname(). (fixed)
- umount -v had problems with order of mount_union. (fixed)
- umount -v had problems with order of mount_nfs. (fixed)
- nfs-unmounts from mounts with an '@' still had problems if
  only the mntpnt got umounted. (fixed)

tnx for testing billf ;-)

-------------------------------------------------------------------

--- umount.c.orig       Mon Aug  9 17:20:13 1999
+++ umount.c    Mon Aug  9 21:32:45 1999
@@ -211,29 +211,31 @@
        struct timeval pertry, try;
        CLIENT *clp;
        int so;
-       char *type, *delimp, *hostp, *mntpt, *origname,
rname[MAXPATHLEN];
+       char *type, *delimp, *hostp, *mntpt, *mnton, *mntfrom,
rname[MAXPATHLEN];

        if (realpath(name, rname) == NULL) {
                /* Continue and let the system call check it... */
                strcpy(rname, name);
        }

-       origname = name;
+       mntfrom = getmntname(rname, MNTFROM, &type);
+       mnton = getmntname(name, MNTON, &type);
+
        if (stat(name, &sb) < 0) {
                mntpt = rname;
-               if ((getmntname(rname, MNTFROM, &type) == NULL) &&
-                   ((mntpt = getmntname(name, MNTON, &type)) == NULL))
{
+               if ((mntfrom == NULL) &&
+                   ((mntpt = mnton) == NULL)) {
                        warnx("%s: not currently mounted", name);
                        return (1);
                }
        } else if (S_ISBLK(sb.st_mode)) {
-               if ((mntpt = getmntname(name, MNTON, &type)) == NULL) {
+               if ((mntpt = mnton) == NULL) {
                        warnx("%s: not currently mounted", name);
                        return (1); 
                }
        } else if (S_ISDIR(sb.st_mode)) {
                mntpt = rname;
-               if (getmntname(mntpt, MNTFROM, &type) == NULL) {
+               if (mntfrom == NULL) {
                        warnx("%s: not currently mounted", name);
                        return (1);
                }
@@ -248,6 +250,12 @@

        hp = NULL;
        if (!strcmp(type, "nfs")) {
+
+               /* We need this if we get nothing but mntpt as argument
*/
+               if ((delimp = strpbrk(mntfrom, "@:")) != NULL) {
+                       name = mntfrom;
+               }
+
                if ((delimp = strchr(name, '@')) != NULL) {
                        hostp = delimp + 1;
                        *delimp = '\0';
@@ -262,11 +270,18 @@
                }
        }

+
+       /* make umount -v happy */
+       if (mntfrom == NULL) {
+               mntfrom = name;
+       }
+
        if (!namematch(hp))
                return (1);

-       if (vflag)
-               (void)printf("%s: unmount from %s\n", origname, mntpt);
+       if (vflag)
+               (void)printf("%s: unmount from %s\n", mntfrom, mntpt);
+
        if (fake)
                return (0);

@@ -320,7 +335,7 @@
                warn("getmntinfo");
                return (NULL);
        }
-       for (i = 0; i < mntsize; i++) {
+       for (i = mntsize; i > 0; i--) {
                if ((what == MNTON) && !strcmp(mntbuf[i].f_mntfromname,
name)) {
                        if (type)
                                *type = mntbuf[i].f_fstypename;
Comment 5 Doug 1999-08-22 02:19:04 UTC
blapp@attic.ch wrote:

> >Description:
> If you umount a nfs-mountpoint, the server will not get an
> authentificated umount request. If you unmount it with the full
> path it works. With Linux 2.2 and Irix 6.5.2 as clients both
> 'umount /mountpoint' and 'umount somehost:/somedir' work.
> >How-To-Repeat:
> Client:
> 
> # mount somehost:/somedir /mountpoint
> # umount /mountpoint

	I want to add a "me too" on this point in hopes that it another data point
helps. 

Doug
Comment 6 bill fumerola freebsd_committer freebsd_triage 1999-09-05 00:54:18 UTC
Responsible Changed
From-To: billf->alfred

Alfred has been working with Martin. 
Comment 7 Brian Feldman freebsd_committer freebsd_triage 1999-12-18 23:41:02 UTC
State Changed
From-To: open->closed

This has been fixed in -CURRENT and 3.3/3.4.