Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159270313
D27801.id81862.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D27801.id81862.diff
View Options
Index: usr.sbin/autofs/automount.c
===================================================================
--- usr.sbin/autofs/automount.c
+++ usr.sbin/autofs/automount.c
@@ -63,24 +63,64 @@
static int
unmount_by_statfs(const struct statfs *sb, bool force)
{
+ int error;
+
+ if ((error = unmount_automount(&sb->f_fsid, force ? MNT_FORCE : 0)) != 0)
+ log_warn("cannot unmount %s (FSID:%d:%d)",
+ sb->f_mntonname, sb->f_fsid.val[0], sb->f_fsid.val[1]);
+
+ return (error);
+}
+
+
+static int
+unmount_by_umount(const fsid_t *fsid, int flags)
+{
+ FILE *f;
+ char fsid_str[sizeof(*fsid)*2+1];
+ size_t i;
+
+ /* umount(8) expects the file system ID to be in hexadecimal format */
+ for (i = 0; i < sizeof(*fsid); i++)
+ snprintf(fsid_str+(i*2), sizeof(fsid_str) - (i*2),
+ "%02x", ((const u_char *)fsid)[i]);
+
+ if (flags & MNT_FORCE)
+ f = auto_popen("umount", "-f", fsid_str, NULL);
+ else
+ f = auto_popen("umount", fsid_str, NULL);
+
+ assert(f != NULL);
+ return (auto_pclose(f));
+}
+
+/*
+ * Unmount a filesystem. Default to umount(8) and fallback to unmount(3).
+ */
+int
+unmount_automount(const fsid_t *fsid, int flags)
+{
+ int error;
char *fsid_str;
- int error, ret, flags;
- ret = asprintf(&fsid_str, "FSID:%d:%d",
- sb->f_fsid.val[0], sb->f_fsid.val[1]);
- if (ret < 0)
+ /* need to find reference where FSID:0:0 is error */
+ if (fsid->val[0] == 0 || fsid->val[1] == 0)
+ return (EACCES);
+
+ /* any debug or warnings will be logged from auto_pclose() */
+ if ((error = unmount_by_umount(fsid, flags)) == 0)
+ return (0);
+
+ if (asprintf(&fsid_str, "FSID:%d:%d", fsid->val[0], fsid->val[1]) < 0)
log_err(1, "asprintf");
- log_debugx("unmounting %s using %s", sb->f_mntonname, fsid_str);
+ flags |= MNT_BYFSID;
+ if ((error = unmount(fsid_str, flags)) == 0)
+ return (0);
- flags = MNT_BYFSID;
- if (force)
- flags |= MNT_FORCE;
- error = unmount(fsid_str, flags);
- free(fsid_str);
- if (error != 0)
- log_warn("cannot unmount %s", sb->f_mntonname);
+ log_debugx("cannot unmount (%s): %s", fsid_str, strerror(errno));
+ free(fsid_str);
return (error);
}
Index: usr.sbin/autofs/autounmountd.c
===================================================================
--- usr.sbin/autofs/autounmountd.c
+++ usr.sbin/autofs/autounmountd.c
@@ -154,25 +154,11 @@
static int
unmount_by_fsid(const fsid_t fsid, const char *mountpoint)
{
- char *fsid_str;
- int error, ret;
-
- ret = asprintf(&fsid_str, "FSID:%d:%d", fsid.val[0], fsid.val[1]);
- if (ret < 0)
- log_err(1, "asprintf");
-
- error = unmount(fsid_str, MNT_NONBUSY | MNT_BYFSID);
- if (error != 0) {
- if (errno == EBUSY) {
- log_debugx("cannot unmount %s (%s): %s",
- mountpoint, fsid_str, strerror(errno));
- } else {
- log_warn("cannot unmount %s (%s)",
- mountpoint, fsid_str);
- }
- }
+ int error;
- free(fsid_str);
+ if ((error = unmount_automount(&fsid, MNT_NONBUSY)) != 0)
+ log_warn("cannot unmount %s (FSID:%d:%d)",
+ mountpoint, fsid.val[0], fsid.val[1]);
return (error);
}
Index: usr.sbin/autofs/common.h
===================================================================
--- usr.sbin/autofs/common.h
+++ usr.sbin/autofs/common.h
@@ -33,6 +33,7 @@
#ifndef AUTOMOUNTD_H
#define AUTOMOUNTD_H
+#include <sys/mount.h>
#include <sys/queue.h>
#include <stdbool.h>
@@ -104,6 +105,8 @@
FILE *auto_popen(const char *argv0, ...);
int auto_pclose(FILE *iop);
+int unmount_automount(const fsid_t *fsid, int flags);
+
/*
* lex(1) stuff.
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jun 13, 4:11 AM (10 h, 54 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33920048
Default Alt Text
D27801.id81862.diff (3 KB)
Attached To
Mode
D27801: automount(8): try umount(8) before unmount(3)
Attached
Detach File
Event Timeline
Log In to Comment