From 0fd95094fddbfd131c02a81dcb04b43af6742d78 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 5 Dec 2008 10:33:53 -0800 Subject: [PATCH 1/7] Refresh linux-have-zvol --- .topdeps | 4 +--- .topmsg | 17 ++--------------- zfs/lib/libzfs/libzfs_dataset.c | 10 ++++++++++ zfs/lib/libzfs/libzfs_pool.c | 2 ++ zfs/lib/libzpool/zvol.c | 19 ++++++++++++++++++- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.topdeps b/.topdeps index 607c231780..7f16cbcdd5 100644 --- a/.topdeps +++ b/.topdeps @@ -1,3 +1 @@ -gcc-branch -fix-branch -feature-branch +zfs-branch diff --git a/.topmsg b/.topmsg index e9722e1075..5143e12acd 100644 --- a/.topmsg +++ b/.topmsg @@ -1,19 +1,6 @@ From: Brian Behlendorf -Subject: [PATCH] zfs branch +Subject: [PATCH] linux have zvol -Merged result of all changes which are relevant to both Solaris -and Linux builds of the ZFS code. These are changes where there -is a reasonable chance they will be accepted upstream. - -Additionally, since this is effectively the root of the linux -ZFS tree the core linux build system is added here. This -includes autogen.sh, configure.ac, m4 macros, some scripts/*, -and makefiles for all the core ZFS components. Linux-only -features which require tweaks to the build system should appear -on the relevant topic branches. All autotools products which -result from autogen.sh are commited to the linux-configure-branch. - -This branch also contains the META, ChangeLog, AUTHORS, -README, and GIT files. +Use ZVOL if HAVE_ZVOL defined Signed-off-by: Brian Behlendorf diff --git a/zfs/lib/libzfs/libzfs_dataset.c b/zfs/lib/libzfs/libzfs_dataset.c index 3f49652abb..c2c34ed176 100644 --- a/zfs/lib/libzfs/libzfs_dataset.c +++ b/zfs/lib/libzfs/libzfs_dataset.c @@ -3981,6 +3981,11 @@ zvol_create_link(libzfs_handle_t *hdl, const char *dataset) static int zvol_create_link_common(libzfs_handle_t *hdl, const char *dataset, int ifexists) { +#if !defined(HAVE_ZVOL) + return (zfs_standard_error_fmt(hdl, ENOTSUP, + dgettext(TEXT_DOMAIN, "cannot create device links " + "for '%s'"), dataset)); +#else zfs_cmd_t zc = { 0 }; di_devlink_handle_t dhdl; priv_set_t *priv_effective; @@ -4069,6 +4074,7 @@ zvol_create_link_common(libzfs_handle_t *hdl, const char *dataset, int ifexists) } return (0); +#endif } /* @@ -4205,6 +4211,9 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp) int zfs_iscsi_perm_check(libzfs_handle_t *hdl, char *dataset, ucred_t *cred) { +#if !defined(HAVE_ZVOL) + return (ENOTSUP); +#else zfs_cmd_t zc = { 0 }; nvlist_t *nvp; gid_t gid; @@ -4246,6 +4255,7 @@ zfs_iscsi_perm_check(libzfs_handle_t *hdl, char *dataset, ucred_t *cred) error = ioctl(hdl->libzfs_fd, ZFS_IOC_ISCSI_PERM_CHECK, &zc); nvlist_free(nvp); return (error); +#endif } int diff --git a/zfs/lib/libzfs/libzfs_pool.c b/zfs/lib/libzfs/libzfs_pool.c index ae4b19adba..123123f7ba 100644 --- a/zfs/lib/libzfs/libzfs_pool.c +++ b/zfs/lib/libzfs/libzfs_pool.c @@ -2087,6 +2087,7 @@ int zpool_iter_zvol(zpool_handle_t *zhp, int (*cb)(const char *, void *), void *data) { +#ifdef HAVE_ZVOL libzfs_handle_t *hdl = zhp->zpool_hdl; char (*paths)[MAXPATHLEN]; size_t size = 4; @@ -2178,6 +2179,7 @@ zpool_iter_zvol(zpool_handle_t *zhp, int (*cb)(const char *, void *), err: free(paths); (void) close(base); +#endif return (-1); } diff --git a/zfs/lib/libzpool/zvol.c b/zfs/lib/libzpool/zvol.c index 4e993060ce..e686816af6 100644 --- a/zfs/lib/libzpool/zvol.c +++ b/zfs/lib/libzpool/zvol.c @@ -76,6 +76,11 @@ #include #include +#ifdef HAVE_SPL +#include +#include +#endif + #include "zfs_namecheck.h" static void *zvol_state; @@ -159,10 +164,22 @@ zvol_check_volsize(uint64_t volsize, uint64_t blocksize) if (volsize % blocksize != 0) return (EINVAL); -#ifdef _ILP32 +#ifdef HAVE_SPL + if (volsize % 512 != 0) + return (EINVAL); + + /* + * On Linux, the maximum allowed block device size depends on the size + * of sector_t. + */ + if (fls64(volsize / 512 - 1) > NBBY * sizeof (sector_t)) + return (EOVERFLOW); + +#elif defined(_ILP32) if (volsize - 1 > SPEC_MAXOFFSET_T) return (EOVERFLOW); #endif + return (0); } From 2f4b12b228c08b03374cd4aab1f7e049e1e06992 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 22 Dec 2008 12:37:43 -0800 Subject: [PATCH 2/7] Add HAVE_ZVOL changes --- module/zfs/zfs_ioctl.c | 27 ++++++++++++++++++++++++++- module/zfs/zvol.c | 12 ++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index b77ee4da38..d9f43a61a4 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -1812,7 +1812,11 @@ zfs_ioc_get_fsacl(zfs_cmd_t *zc) static int zfs_ioc_create_minor(zfs_cmd_t *zc) { +#ifdef HAVE_ZVOL return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip))); +#else + return (ENOTSUP); +#endif /* HAVE_ZVOL */ } /* @@ -1824,7 +1828,11 @@ zfs_ioc_create_minor(zfs_cmd_t *zc) static int zfs_ioc_remove_minor(zfs_cmd_t *zc) { +#ifdef HAVE_ZVOL return (zvol_remove_minor(zc->zc_name)); +#else + return (ENOTSUP); +#endif /* HAVE_ZVOL */ } /* @@ -2037,9 +2045,11 @@ zfs_ioc_create(zfs_cmd_t *zc) cbfunc = zfs_create_cb; break; +#ifdef HAVE_ZVOL case DMU_OST_ZVOL: cbfunc = zvol_create_cb; break; +#endif /* HAVE_ZVOL */ default: cbfunc = NULL; @@ -2090,6 +2100,7 @@ zfs_ioc_create(zfs_cmd_t *zc) return (EINVAL); } +#ifdef HAVE_ZVOL if (type == DMU_OST_ZVOL) { uint64_t volsize, volblocksize; @@ -2119,7 +2130,9 @@ zfs_ioc_create(zfs_cmd_t *zc) nvlist_free(nvprops); return (error); } - } else if (type == DMU_OST_ZFS) { + } else +#endif /* HAVE_ZVOL */ + if (type == DMU_OST_ZFS) { int error; /* @@ -2952,8 +2965,10 @@ zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) uint_t vec; int error, rc; +#ifdef HAVE_ZVOL if (getminor(dev) != 0) return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp)); +#endif vec = cmd - ZFS_IOC; ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip)); @@ -3065,6 +3080,7 @@ zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) * so most of the standard driver entry points are in zvol.c. */ static struct cb_ops zfs_cb_ops = { +#ifdef HAVE_ZVOL zvol_open, /* open */ zvol_close, /* close */ zvol_strategy, /* strategy */ @@ -3072,6 +3088,15 @@ static struct cb_ops zfs_cb_ops = { zvol_dump, /* dump */ zvol_read, /* read */ zvol_write, /* write */ +#else + nodev, /* open */ + nodev, /* close */ + nodev, /* strategy */ + nodev, /* print */ + nodev, /* dump */ + nodev, /* read */ + nodev, /* write */ +#endif /* HAVE_ZVOL */ zfsdev_ioctl, /* ioctl */ nodev, /* devmap */ nodev, /* mmap */ diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index e686816af6..462faf689b 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -37,6 +37,8 @@ * run before opening and using a device. */ +#ifdef HAVE_ZVOL + #include #include #include @@ -1737,3 +1739,13 @@ zvol_dump_fini(zvol_state_t *zv) return (0); } + +#else + +int +zvol_busy(void) +{ + return DDI_FAILURE; +} + +#endif /* HAVE_ZVOL */ From b7217f525fa0fbdc6e7f6baa7ae23bbe9b82dd0f Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 22 Dec 2008 14:52:15 -0800 Subject: [PATCH 3/7] Fix typo --- module/zfs/zvol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index 462faf689b..da29947130 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -1745,7 +1745,7 @@ zvol_dump_fini(zvol_state_t *zv) int zvol_busy(void) { - return DDI_FAILURE; + return (0); } #endif /* HAVE_ZVOL */ From 7902b5fdf12005a537208ed524e2cc03c6f0f4a2 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 9 Jan 2009 11:16:01 -0800 Subject: [PATCH 4/7] Add HAVE_ZVOL wrappers --- module/zfs/zvol.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index da29947130..1a045c0952 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -1495,21 +1495,29 @@ zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) int zvol_busy(void) { +#ifdef HAVE_ZVOL return (zvol_minors != 0); +#else + return 0; +#endif /* HAVE_ZVOL */ } void zvol_init(void) { +#ifdef HAVE_ZVOL VERIFY(ddi_soft_state_init(&zvol_state, sizeof (zvol_state_t), 1) == 0); mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL); +#endif /* HAVE_ZVOL */ } void zvol_fini(void) { +#ifdef HAVE_ZVOL mutex_destroy(&zvol_state_lock); ddi_soft_state_fini(&zvol_state); +#endif /* HAVE_ZVOL */ } static boolean_t From 9ef637b05731bcb4bef492fe30eaa5c7dc6aa8db Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 9 Jan 2009 14:28:50 -0800 Subject: [PATCH 5/7] Add minimum needed zvol bits --- module/zfs/zvol.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index 1a045c0952..e4cff1feae 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -37,8 +37,6 @@ * run before opening and using a device. */ -#ifdef HAVE_ZVOL - #include #include #include @@ -85,6 +83,7 @@ #include "zfs_namecheck.h" +#ifdef HAVE_ZVOL static void *zvol_state; #define ZVOL_DUMPSIZE "dumpsize" @@ -156,6 +155,7 @@ zvol_size_changed(zvol_state_t *zv, major_t maj) spec_size_invalidate(dev, VBLK); spec_size_invalidate(dev, VCHR); } +#endif /* HAVE_ZVOL */ int zvol_check_volsize(uint64_t volsize, uint64_t blocksize) @@ -196,6 +196,7 @@ zvol_check_volblocksize(uint64_t volblocksize) return (0); } +#ifdef HAVE_ZVOL static void zvol_readonly_changed_cb(void *arg, uint64_t newval) { @@ -206,6 +207,7 @@ zvol_readonly_changed_cb(void *arg, uint64_t newval) else zv->zv_flags &= ~ZVOL_RDONLY; } +#endif /* HAVE_ZVOL */ int zvol_get_stats(objset_t *os, nvlist_t *nv) @@ -231,6 +233,7 @@ zvol_get_stats(objset_t *os, nvlist_t *nv) return (error); } +#ifdef HAVE_ZVOL /* * Find a free minor number. */ @@ -1491,6 +1494,7 @@ zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) mutex_exit(&zvol_state_lock); return (error); } +#endif /* HAVE_ZVOL */ int zvol_busy(void) @@ -1520,6 +1524,7 @@ zvol_fini(void) #endif /* HAVE_ZVOL */ } +#ifdef HAVE_ZVOL static boolean_t zvol_is_swap(zvol_state_t *zv) { @@ -1747,13 +1752,4 @@ zvol_dump_fini(zvol_state_t *zv) return (0); } - -#else - -int -zvol_busy(void) -{ - return (0); -} - #endif /* HAVE_ZVOL */ From 2f2ae376e88b5ccb9616b54c367e194e0b540b36 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 9 Jan 2009 16:08:18 -0800 Subject: [PATCH 6/7] ifdef out some zvol specific ioctls --- module/zfs/zfs_ioctl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index 25c31f9032..c4ac3f86ae 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -1516,6 +1516,7 @@ zfs_set_prop_nvlist(const char *name, nvlist_t *nvl) return (error); break; +#ifdef HAVE_ZVOL case ZFS_PROP_VOLSIZE: if ((error = nvpair_value_uint64(elem, &intval)) != 0 || (error = zvol_set_volsize(name, @@ -1528,6 +1529,11 @@ zfs_set_prop_nvlist(const char *name, nvlist_t *nvl) (error = zvol_set_volblocksize(name, intval)) != 0) return (error); break; +#else + case ZFS_PROP_VOLSIZE: + case ZFS_PROP_VOLBLOCKSIZE: + return (ENOTSUP); +#endif /* HAVE_ZVOL */ case ZFS_PROP_VERSION: if ((error = nvpair_value_uint64(elem, &intval)) != 0 || From 7c5b7d2a940f07d0a6e4a018962cc934451366e0 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 16 Jan 2009 14:52:35 -0800 Subject: [PATCH 7/7] This should always be success when zvol support is disabled --- lib/libzfs/libzfs_pool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 05659552b2..ee352a4290 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -2195,7 +2195,7 @@ err: free(paths); (void) close(base); #endif - return (-1); + return (0); } typedef struct zvol_cb {