All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Dickson <SteveD@redhat.com>
To: nfs@lists.sourceforge.net
Subject: [PATCH 07/11] nfs-utils: mount: Fixed -o remount
Date: Mon, 26 Feb 2007 06:18:32 -0500	[thread overview]
Message-ID: <45E2C208.7020804@RedHat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2: patch-07.dif --]
[-- Type: text/x-patch, Size: 3621 bytes --]

commit d507c76527acc3415395cd70cc08d02e32dbe181
Author: Steve Dickson <steved@redhat.com>
Date:   Sat Feb 24 15:56:54 2007 -0500

    Stop remounts (i.e. -o remount) from dropping core.
    
    Signed-off-by: Steve Dickson <steved@redhat.com>

diff --git a/utils/mount/mount.c b/utils/mount/mount.c
index 8440055..00aee61 100644
--- a/utils/mount/mount.c
+++ b/utils/mount/mount.c
@@ -163,16 +163,29 @@ static char * fix_opts_string (int flags, const char *extra_opts) {
 	return new_opts;
 }
 
-void copy_mntent(struct mntent *ment, nfs_mntent_t *nment)
+static inline void dup_mntent(struct mntent *ment, nfs_mntent_t *nment)
 {
 	/* Not sure why nfs_mntent_t should exist */
-	strcpy(nment->mnt_fsname, ment->mnt_fsname);
-	strcpy(nment->mnt_dir, ment->mnt_dir);
-	strcpy(nment->mnt_type, ment->mnt_type);
-	strcpy(nment->mnt_opts, ment->mnt_opts);
+	nment->mnt_fsname = strdup(ment->mnt_fsname);
+	nment->mnt_dir = strdup(ment->mnt_dir);
+	nment->mnt_type = strdup(ment->mnt_type);
+	nment->mnt_opts = strdup(ment->mnt_opts);
 	nment->mnt_freq = ment->mnt_freq;
 	nment->mnt_passno = ment->mnt_passno;
 }
+static inline void 
+free_mntent(nfs_mntent_t *ment, int remount)
+{
+	free(ment->mnt_fsname);
+	free(ment->mnt_dir);
+	free(ment->mnt_type);
+	/* 
+	 * Note: free(ment->mnt_opts) happens in discard_mntentchn()
+	 * via update_mtab() on remouts
+	 */
+	 if (!remount)
+	 	free(ment->mnt_opts);
+}
 
 int add_mtab(char *fsname, char *mount_point, char *fstype, int flags, char *opts, int freq, int passno)
 {
@@ -189,8 +202,9 @@ int add_mtab(char *fsname, char *mount_point, char *fstype, int flags, char *opt
 	if(flags & MS_REMOUNT) {
 		nfs_mntent_t nment;
 		
-		copy_mntent(&ment, &nment);
+		dup_mntent(&ment, &nment);
 		update_mtab(nment.mnt_dir, &nment);
+		free_mntent(&nment, 1);
 		return 0;
 	}
 
@@ -337,10 +351,11 @@ static void mount_error(char *node)
 			fprintf(stderr, "%s: %s\n", progname, strerror(errno));
 	}
 }
+#define NFS_MOUNT_VERS_DEFAULT 3
 
 int main(int argc, char *argv[])
 {
-	int c, flags = 0, nfs_mount_vers = 0, mnt_err = 1, fake = 0;
+	int c, flags = 0, nfs_mount_vers, mnt_err = 1, fake = 0;
 	char *spec, *mount_point, *extra_opts = NULL;
 	char *mount_opts = NULL, *p;
 	struct mntentchn *mc;
@@ -371,6 +386,10 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 
+	nfs_mount_vers = NFS_MOUNT_VERS_DEFAULT;
+	if (!strcmp(progname, "mount.nfs4"))
+		nfs_mount_vers = 4;
+
 	while ((c = getopt_long (argc - 2, argv + 2, "rt:vVwfno:hs",
 				longopts, NULL)) != -1) {
 		switch (c) {
@@ -461,9 +480,9 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	if (!strcmp(progname, "mount.nfs4") || nfs_mount_vers == 4) {
-		nfs_mount_vers = 4;
-		mnt_err = nfs4mount(spec, mount_point, &flags, &extra_opts, &mount_opts, 0);
+	if (nfs_mount_vers == 4) {
+		mnt_err = nfs4mount(spec, mount_point, &flags, 
+			&extra_opts, &mount_opts, 0);
 	}
 	else {
 		if (!strcmp(progname, "mount.nfs")) {
@@ -471,21 +490,19 @@ int main(int argc, char *argv[])
 					&extra_opts, &mount_opts, &nfs_mount_vers, 0);
 		}
 	}
-
 	if (fake)
 		return 0;
 	if (mnt_err)
 		exit(EX_FAIL);
 
-	if(!(flags & MS_REMOUNT)) {
-		mnt_err = do_mount_syscall(spec, mount_point,
-				nfs_mount_vers == 4 ? "nfs4" : "nfs", flags, mount_opts);
+	mnt_err = do_mount_syscall(spec, mount_point,
+			nfs_mount_vers == 4 ? "nfs4" : "nfs", flags, mount_opts);
 
-		if(mnt_err) {
-			mount_error(mount_point);
-			exit(EX_FAIL);
-		}
+	if(mnt_err) {
+		mount_error(mount_point);
+		exit(EX_FAIL);
 	}
+
 	if(!nomtab) {
 		add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
 			 flags, extra_opts, 0, 0);

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 140 bytes --]

_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

             reply	other threads:[~2007-02-26 11:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-26 11:18 Steve Dickson [this message]
2007-02-27  6:19 ` [PATCH 07/11] nfs-utils: mount: Fixed -o remount Neil Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45E2C208.7020804@RedHat.com \
    --to=steved@redhat.com \
    --cc=nfs@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.