View | Details | Raw Unified | Return to bug 251906 | Differences between
and this patch

Collapse All | Expand All

(-)b/usr.sbin/autofs/automount.c (-12 / +52 lines)
Lines 63-86 __FBSDID("$FreeBSD$"); Link Here
63
static int
63
static int
64
unmount_by_statfs(const struct statfs *sb, bool force)
64
unmount_by_statfs(const struct statfs *sb, bool force)
65
{
65
{
66
	int error;
67
68
	if ((error = unmount_automount(&sb->f_fsid, force ? MNT_FORCE : 0)) != 0)
69
		log_warn("cannot unmount %s (FSID:%d:%d)",
70
		    sb->f_mntonname, sb->f_fsid.val[0], sb->f_fsid.val[1]);
71
72
	return (error);
73
}
74
75
76
static int
77
unmount_by_umount(const fsid_t *fsid, int flags)
78
{
79
	FILE *f;
80
	char fsid_str[sizeof(*fsid)*2+1];
81
	size_t i;
82
83
	/* umount(8) expects the file system ID to be in hexadecimal format */
84
	for (i = 0; i < sizeof(*fsid); i++)
85
		snprintf(fsid_str+(i*2), sizeof(fsid_str) - (i*2),
86
		    "%02x", ((const u_char *)fsid)[i]);
87
88
	if (flags & MNT_FORCE)
89
		f = auto_popen("umount", "-f", fsid_str, NULL);
90
	else
91
		f = auto_popen("umount", fsid_str, NULL);
92
93
	assert(f != NULL);
94
	return (auto_pclose(f));
95
}
96
97
/*
98
 * Unmount a filesystem. Default to umount(8) and fallback to unmount(3).
99
 */
100
int
101
unmount_automount(const fsid_t *fsid, int flags)
102
{
103
	int error;
66
	char *fsid_str;
104
	char *fsid_str;
67
	int error, ret, flags;
68
105
69
	ret = asprintf(&fsid_str, "FSID:%d:%d",
106
	/* need to find reference where FSID:0:0 is error */
70
	    sb->f_fsid.val[0], sb->f_fsid.val[1]);
107
	if (fsid->val[0] == 0 || fsid->val[1] == 0)
71
	if (ret < 0)
108
		return (EACCES);
109
110
	/* any debug or warnings will be logged from auto_pclose() */
111
	if ((error = unmount_by_umount(fsid, flags)) == 0)
112
		return (0);
113
114
	if (asprintf(&fsid_str, "FSID:%d:%d", fsid->val[0], fsid->val[1]) < 0)
72
		log_err(1, "asprintf");
115
		log_err(1, "asprintf");
73
116
74
	log_debugx("unmounting %s using %s", sb->f_mntonname, fsid_str);
117
	flags |= MNT_BYFSID;
118
	if ((error = unmount(fsid_str, flags)) == 0)
119
		return (0);
75
120
76
	flags = MNT_BYFSID;
121
	log_debugx("cannot unmount (%s): %s", fsid_str, strerror(errno));
77
	if (force)
78
		flags |= MNT_FORCE;
79
	error = unmount(fsid_str, flags);
80
	free(fsid_str);
81
	if (error != 0)
82
		log_warn("cannot unmount %s", sb->f_mntonname);
83
122
123
	free(fsid_str);
84
	return (error);
124
	return (error);
85
}
125
}
86
126
(-)b/usr.sbin/autofs/autounmountd.c (-18 / +4 lines)
Lines 154-178 refresh_automounted(void) Link Here
154
static int
154
static int
155
unmount_by_fsid(const fsid_t fsid, const char *mountpoint)
155
unmount_by_fsid(const fsid_t fsid, const char *mountpoint)
156
{
156
{
157
	char *fsid_str;
157
	int error;
158
	int error, ret;
159
160
	ret = asprintf(&fsid_str, "FSID:%d:%d", fsid.val[0], fsid.val[1]);
161
	if (ret < 0)
162
		log_err(1, "asprintf");
163
164
	error = unmount(fsid_str, MNT_NONBUSY | MNT_BYFSID);
165
	if (error != 0) {
166
		if (errno == EBUSY) {
167
			log_debugx("cannot unmount %s (%s): %s",
168
			    mountpoint, fsid_str, strerror(errno));
169
		} else {
170
			log_warn("cannot unmount %s (%s)",
171
			    mountpoint, fsid_str);
172
		}
173
	}
174
158
175
	free(fsid_str);
159
	if ((error = unmount_automount(&fsid, MNT_NONBUSY)) != 0)
160
		log_warn("cannot unmount %s (FSID:%d:%d)",
161
		    mountpoint, fsid.val[0], fsid.val[1]);
176
162
177
	return (error);
163
	return (error);
178
}
164
}
(-)b/usr.sbin/autofs/common.h (+3 lines)
Lines 33-38 Link Here
33
#ifndef AUTOMOUNTD_H
33
#ifndef AUTOMOUNTD_H
34
#define	AUTOMOUNTD_H
34
#define	AUTOMOUNTD_H
35
35
36
#include <sys/mount.h>
36
#include <sys/queue.h>
37
#include <sys/queue.h>
37
#include <stdbool.h>
38
#include <stdbool.h>
38
39
Lines 104-109 int main_autounmountd(int argc, char **argv); Link Here
104
FILE	*auto_popen(const char *argv0, ...);
105
FILE	*auto_popen(const char *argv0, ...);
105
int	auto_pclose(FILE *iop);
106
int	auto_pclose(FILE *iop);
106
107
108
int unmount_automount(const fsid_t *fsid, int flags);
109
107
/*
110
/*
108
 * lex(1) stuff.
111
 * lex(1) stuff.
109
 */
112
 */

Return to bug 251906