From mboxrd@z Thu Jan 1 00:00:00 1970 From: teigland@sourceware.org Date: 2 Jan 2007 20:18:04 -0000 Subject: [Cluster-devel] cluster/gfs2/mount mtab.c util.c Message-ID: <20070102201804.24524.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: teigland at sourceware.org 2007-01-02 20:18:03 Modified files: gfs2/mount : mtab.c util.c Log message: mount/umount modifications of /etc/mtab weren't smart enough to get straight two different fs's mounted on the same mountpoint bz 218560 Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mount/mtab.c.diff?cvsroot=cluster&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mount/util.c.diff?cvsroot=cluster&r1=1.20&r2=1.21 --- cluster/gfs2/mount/mtab.c 2005/11/10 20:37:18 1.3 +++ cluster/gfs2/mount/mtab.c 2007/01/02 20:18:03 1.4 @@ -143,7 +143,8 @@ if ((sscanf(line, "%s %s %s", device, path, type) == 3) && (strncmp(type, "gfs", 3) == 0) && - (strcmp(path, mo->dir) == 0)) { + (strcmp(path, mo->dir) == 0) && + (strcmp(device, mo->dev) == 0)) { found = 1; continue; } --- cluster/gfs2/mount/util.c 2006/12/20 19:13:35 1.20 +++ cluster/gfs2/mount/util.c 2007/01/02 20:18:03 1.21 @@ -157,6 +157,12 @@ log_debug("parse_opts: locktable = \"%s\"", mo->locktable); } +/* - when unmounting, we don't know the dev and need this function to set it; + we also want to select the _last_ line with a matching dir since it will + be the top-most fs that the umount(2) will unmount + - when mounting, we do know the dev and need this function to use it in the + comparison (for multiple fs's with the same mountpoint) */ + void read_proc_mounts(struct mount_options *mo) { FILE *file; @@ -165,6 +171,9 @@ char type[PATH_MAX]; char opts[PATH_MAX]; char device[PATH_MAX]; + char save_line[PATH_MAX]; + char save_opts[PATH_MAX]; + char save_device[PATH_MAX]; int found = 0; file = fopen("/proc/mounts", "r"); @@ -176,20 +185,31 @@ continue; if (strcmp(path, mo->dir)) continue; + if (mo->dev[0] && strcmp(device, mo->dev)) + continue; if (strcmp(type, fsname)) die("%s is not a %s filesystem\n", mo->dir, fsname); - strncpy(mo->dev, device, PATH_MAX); - strncpy(mo->opts, opts, PATH_MAX); - strncpy(mo->proc_entry, line, PATH_MAX); + /* when there is an input dev specified (mount), we should get + only one matching line; when there is no input dev specified + (umount), we want the _last_ matching line */ + + strncpy(save_device, device, PATH_MAX); + strncpy(save_opts, opts, PATH_MAX); + strncpy(save_line, line, PATH_MAX); found = 1; - break; } fclose(file); if (!found) die("can't find /proc/mounts entry for directory %s\n", mo->dir); + else { + strncpy(mo->dev, save_device, PATH_MAX); + strncpy(mo->opts, save_opts, PATH_MAX); + strncpy(mo->proc_entry, save_line, PATH_MAX); + } + log_debug("read_proc_mounts: device = \"%s\"", mo->dev); log_debug("read_proc_mounts: opts = \"%s\"", mo->opts); }