From 1aa89f17c70efe4d27da7ba4dd1e4ed101a38474 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 5 Feb 2008 20:49:52 +0000 Subject: [PATCH] * Implement a mountctl() op for setting export control on a filesystem. * Adjust mountd to try to use the mountctl() op BEFORE calling a UFS-style mount() to set export ops for a filesystem. * Add a prototype for the mountctl() system call in sys/mountctl.h * Cleanup WARNS for the mountctl utility. --- sbin/mountctl/Makefile | 3 +-- sbin/mountctl/mountctl.c | 16 ++++++++-------- sbin/mountd/mountd.c | 25 +++++++++++++++++++++---- sys/kern/vfs_subr.c | 11 ++++++----- sys/sys/mount.h | 6 +++--- sys/sys/mountctl.h | 21 ++++++++++++++++----- 6 files changed, 55 insertions(+), 27 deletions(-) diff --git a/sbin/mountctl/Makefile b/sbin/mountctl/Makefile index 00e43980c3..c4a748fd13 100644 --- a/sbin/mountctl/Makefile +++ b/sbin/mountctl/Makefile @@ -1,9 +1,8 @@ # -# $DragonFly: src/sbin/mountctl/Makefile,v 1.2 2006/10/17 00:55:42 pavalos Exp $ +# $DragonFly: src/sbin/mountctl/Makefile,v 1.3 2008/02/05 20:49:50 dillon Exp $ PROG= mountctl SRCS= mountctl.c MAN= mountctl.8 -WARNS?= 1 .include diff --git a/sbin/mountctl/mountctl.c b/sbin/mountctl/mountctl.c index 254431eb4a..7717829691 100644 --- a/sbin/mountctl/mountctl.c +++ b/sbin/mountctl/mountctl.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/mountctl/mountctl.c,v 1.9 2007/11/25 01:28:23 swildner Exp $ + * $DragonFly: src/sbin/mountctl/mountctl.c,v 1.10 2008/02/05 20:49:50 dillon Exp $ */ /* * This utility implements the userland mountctl command which is used to @@ -51,7 +51,7 @@ #include #include -static volatile void usage(void); +static void usage(void); static void parse_option_keyword(const char *opt, const char **wopt, const char **xopt); static int64_t getsize(const char *str); @@ -456,7 +456,8 @@ mountctl_scan(void (*func)(const char *, const char *, int, void *), } static void -mountctl_list(const char *keyword, const char *mountpt, int __unused fd, void *info) +mountctl_list(const char *keyword __unused, const char *mountpt, + int fd __unused, void *info) { struct mountctl_journal_ret_status *rstat = info; @@ -559,13 +560,14 @@ mountctl_delete(const char *keyword, const char *mountpt, } static void -mountctl_modify(const char *keyword, const char *mountpt, int fd, void __unused *info) +mountctl_modify(const char *keyword __unused, const char *mountpt __unused, + int fd __unused, void *info __unused) { fprintf(stderr, "modify not yet implemented\n"); } -static volatile void +static void usage(void) { printf( @@ -582,7 +584,7 @@ usage(void) static int64_t getsize(const char *str) { - const char *suffix; + char *suffix; int64_t val; val = strtoll(str, &suffix, 0); @@ -615,8 +617,6 @@ static const char * numtostr(int64_t num) { static char buf[64]; - int n; - double v = num; if (num < 1024) snprintf(buf, sizeof(buf), "%lld", num); diff --git a/sbin/mountd/mountd.c b/sbin/mountd/mountd.c index 9db8f6eeb3..33ec51c976 100644 --- a/sbin/mountd/mountd.c +++ b/sbin/mountd/mountd.c @@ -36,11 +36,12 @@ * @(#) Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved. * @(#)mountd.c 8.15 (Berkeley) 5/1/95 * $FreeBSD: src/sbin/mountd/mountd.c,v 1.39.2.5 2002/09/13 15:57:43 joerg Exp $ - * $DragonFly: src/sbin/mountd/mountd.c,v 1.8 2005/11/06 12:43:47 swildner Exp $ + * $DragonFly: src/sbin/mountd/mountd.c,v 1.9 2008/02/05 20:49:51 dillon Exp $ */ #include #include +#include #include #include #include @@ -745,8 +746,12 @@ get_exportlist(void) struct msdosfs_args da; struct ntfs_args na; } targs; + struct export_args export; - if (!strcmp(fsp->f_fstypename, "mfs") || + export.ex_flags = MNT_DELEXPORT; + if (mountctl(fsp->f_mntonname, MOUNTCTL_SET_EXPORT, -1, + &export, sizeof(export), NULL, 0) == 0) { + } else if (!strcmp(fsp->f_fstypename, "mfs") || !strcmp(fsp->f_fstypename, "ufs") || !strcmp(fsp->f_fstypename, "msdos") || !strcmp(fsp->f_fstypename, "ntfs") || @@ -1615,8 +1620,20 @@ do_mount(struct exportlist *ep, struct grouplist *grp, int exflags, * Also, needs to know how to export all types of local * exportable file systems and not just "ufs". */ - while (mount(fsb->f_fstypename, dirp, - fsb->f_flags | MNT_UPDATE, (caddr_t)&args) < 0) { + for (;;) { + int r; + + r = mountctl(fsb->f_mntonname, MOUNTCTL_SET_EXPORT, + -1, + &args.ua.export, sizeof(args.ua.export), + NULL, 0); + if (r < 0 && errno == EOPNOTSUPP) { + r = mount(fsb->f_fstypename, dirp, + fsb->f_flags | MNT_UPDATE, + (caddr_t)&args); + } + if (r >= 0) + break; if (cp) *cp-- = savedc; else diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 4d0d9ab8c1..dca6f9e4b6 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.110 2008/01/05 14:02:38 swildner Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.111 2008/02/05 20:49:49 dillon Exp $ */ /* @@ -128,7 +128,7 @@ SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RW, static void vfs_free_addrlist (struct netexport *nep); static int vfs_free_netcred (struct radix_node *rn, void *w); static int vfs_hang_addrlist (struct mount *mp, struct netexport *nep, - struct export_args *argp); + const struct export_args *argp); extern int dev_ref_debug; @@ -1590,7 +1590,7 @@ vfs_umountall_callback(struct mount *mp, void *data) */ static int vfs_hang_addrlist(struct mount *mp, struct netexport *nep, - struct export_args *argp) + const struct export_args *argp) { struct netcred *np; struct radix_node_head *rnh; @@ -1693,7 +1693,8 @@ vfs_free_addrlist(struct netexport *nep) } int -vfs_export(struct mount *mp, struct netexport *nep, struct export_args *argp) +vfs_export(struct mount *mp, struct netexport *nep, + const struct export_args *argp) { int error; @@ -1725,7 +1726,7 @@ vfs_export(struct mount *mp, struct netexport *nep, struct export_args *argp) */ int vfs_setpublicfs(struct mount *mp, struct netexport *nep, - struct export_args *argp) + const struct export_args *argp) { int error; struct vnode *rvp; diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 3cd907929f..c19322ed2c 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -32,7 +32,7 @@ * * @(#)mount.h 8.21 (Berkeley) 5/20/95 * $FreeBSD: src/sys/sys/mount.h,v 1.89.2.7 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/sys/mount.h,v 1.37 2007/12/30 20:02:57 hasso Exp $ + * $DragonFly: src/sys/sys/mount.h,v 1.38 2008/02/05 20:49:52 dillon Exp $ */ #ifndef _SYS_MOUNT_H_ @@ -519,14 +519,14 @@ extern char *mountrootfsname; */ int dounmount (struct mount *, int); int vfs_setpublicfs /* set publicly exported fs */ - (struct mount *, struct netexport *, struct export_args *); + (struct mount *, struct netexport *, const struct export_args *); int vfs_lock (struct mount *); /* lock a vfs */ void vfs_msync (struct mount *, int); void vfs_unlock (struct mount *); /* unlock a vfs */ int vfs_busy (struct mount *, int); void vfs_bufstats(void); int vfs_export /* process mount export info */ - (struct mount *, struct netexport *, struct export_args *); + (struct mount *, struct netexport *, const struct export_args *); struct netcred *vfs_export_lookup /* lookup host in fs export list */ (struct mount *, struct netexport *, struct sockaddr *); int vfs_allocate_syncvnode (struct mount *); diff --git a/sys/sys/mountctl.h b/sys/sys/mountctl.h index 303f7c3b7c..dee9bcef98 100644 --- a/sys/sys/mountctl.h +++ b/sys/sys/mountctl.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/mountctl.h,v 1.13 2006/05/20 02:42:13 dillon Exp $ + * $DragonFly: src/sys/sys/mountctl.h,v 1.14 2008/02/05 20:49:52 dillon Exp $ */ #ifndef _SYS_MOUNTCTL_H_ @@ -64,10 +64,6 @@ #define JIDMAX 32 /* id string buf[] size (incls \0) */ -/* - * Data structures for the journaling API - */ - #define MOUNTCTL_INSTALL_VFS_JOURNAL 1 #define MOUNTCTL_REMOVE_VFS_JOURNAL 2 #define MOUNTCTL_RESYNC_VFS_JOURNAL 3 @@ -79,6 +75,12 @@ #define MOUNTCTL_RESYNC_BLK_JOURNAL 10 #define MOUNTCTL_STATUS_BLK_JOURNAL 11 +#define MOUNTCTL_SET_EXPORT 16 /* sys/mount.h:export_args */ + +/* + * Data structures for the journaling API + */ + struct mountctl_install_journal { char id[JIDMAX]; int flags; /* journaling flags */ @@ -264,6 +266,15 @@ void jrecord_file_data(struct jrecord *jrec, struct vnode *vp, MALLOC_DECLARE(M_JOURNAL); MALLOC_DECLARE(M_JFIFO); +#else + +#include + +__BEGIN_DECLS +int mountctl (const char *path, int op, int fd, void *ctl, int ctllen, + void *buf, int buflen); +__END_DECLS + #endif /* kernel */ #endif /* header */ -- 2.41.0