VFS: Wrap with HAVE_SHARE
[zfs.git] / module / zfs / zfs_ioctl.c
index 99287e4..17f3ff6 100644 (file)
@@ -170,7 +170,7 @@ history_str_get(zfs_cmd_t *zc)
        if (zc->zc_history == 0)
                return (NULL);
 
-       buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
+       buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP | KM_NODEBUG);
        if (copyinstr((void *)(uintptr_t)zc->zc_history,
            buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
                history_str_free(buf);
@@ -592,7 +592,7 @@ zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
        return (error);
 }
 
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
 static int
 zfs_secpolicy_deleg_share(zfs_cmd_t *zc, cred_t *cr)
 {
@@ -616,12 +616,12 @@ zfs_secpolicy_deleg_share(zfs_cmd_t *zc, cred_t *cr)
        return (dsl_deleg_access(zc->zc_name,
            ZFS_DELEG_PERM_SHARE, cr));
 }
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 
 int
 zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
 {
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
        if (!INGLOBALZONE(curproc))
                return (EPERM);
 
@@ -632,13 +632,13 @@ zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
        }
 #else
        return (ENOTSUP);
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 }
 
 int
 zfs_secpolicy_smb_acl(zfs_cmd_t *zc, cred_t *cr)
 {
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
        if (!INGLOBALZONE(curproc))
                return (EPERM);
 
@@ -649,7 +649,7 @@ zfs_secpolicy_smb_acl(zfs_cmd_t *zc, cred_t *cr)
        }
 #else
        return (ENOTSUP);
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 }
 
 static int
@@ -1027,7 +1027,7 @@ get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
        if (size == 0)
                return (EINVAL);
 
-       packed = kmem_alloc(size, KM_SLEEP);
+       packed = kmem_alloc(size, KM_SLEEP | KM_NODEBUG);
 
        if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
            iflag)) != 0) {
@@ -1093,7 +1093,7 @@ put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
        if (size > zc->zc_nvlist_dst_size) {
                error = ENOMEM;
        } else {
-               packed = kmem_alloc(size, KM_SLEEP);
+               packed = kmem_alloc(size, KM_SLEEP | KM_NODEBUG);
                VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
                    KM_SLEEP) == 0);
                if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
@@ -1292,6 +1292,9 @@ zfs_ioc_pool_import(zfs_cmd_t *zc)
                        error = err;
        }
 
+       if (error == 0)
+               zvol_create_minors(zc->zc_name);
+
        nvlist_free(config);
 
        if (props)
@@ -2179,8 +2182,7 @@ zfs_prop_set_special(const char *dsname, zprop_source_t source,
                err = dsl_dataset_set_reservation(dsname, source, intval);
                break;
        case ZFS_PROP_VOLSIZE:
-               err = zvol_set_volsize(dsname, ddi_driver_major(zfs_dip),
-                   intval);
+               err = zvol_set_volsize(dsname, intval);
                break;
        case ZFS_PROP_VERSION:
        {
@@ -2654,6 +2656,30 @@ zfs_ioc_pool_get_props(zfs_cmd_t *zc)
 
 /*
  * inputs:
+ * zc_name              name of volume
+ *
+ * outputs:             none
+ */
+static int
+zfs_ioc_create_minor(zfs_cmd_t *zc)
+{
+       return (zvol_create_minor(zc->zc_name));
+}
+
+/*
+ * inputs:
+ * zc_name              name of volume
+ *
+ * outputs:             none
+ */
+static int
+zfs_ioc_remove_minor(zfs_cmd_t *zc)
+{
+       return (zvol_remove_minor(zc->zc_name));
+}
+
+/*
+ * inputs:
  * zc_name             name of filesystem
  * zc_nvlist_src{_size}        nvlist of delegated permissions
  * zc_perm_action      allow/unallow flag
@@ -3281,6 +3307,7 @@ static int
 zfs_ioc_rename(zfs_cmd_t *zc)
 {
        boolean_t recursive = zc->zc_cookie & 1;
+       int err;
 
        zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
        if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
@@ -3294,13 +3321,18 @@ zfs_ioc_rename(zfs_cmd_t *zc)
         */
        if (!recursive && strchr(zc->zc_name, '@') != NULL &&
            zc->zc_objset_type == DMU_OST_ZFS) {
-               int err = zfs_unmount_snap(zc->zc_name, NULL);
+               err = zfs_unmount_snap(zc->zc_name, NULL);
                if (err)
                        return (err);
        }
-       if (zc->zc_objset_type == DMU_OST_ZVOL)
+
+       err = dmu_objset_rename(zc->zc_name, zc->zc_value, recursive);
+       if ((err == 0) && (zc->zc_objset_type == DMU_OST_ZVOL)) {
                (void) zvol_remove_minor(zc->zc_name);
-       return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
+               (void) zvol_create_minor(zc->zc_value);
+       }
+
+       return (err);
 }
 
 static int
@@ -4173,7 +4205,7 @@ zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
  * the first file system is shared.
  * Neither sharefs, nfs or smbsrv are unloadable modules.
  */
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
 int (*znfsexport_fs)(void *arg);
 int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
 int (*zsmbexport_fs)(void *arg, boolean_t add_share);
@@ -4205,12 +4237,12 @@ zfs_init_sharefs()
        }
        return (0);
 }
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 
 static int
 zfs_ioc_share(zfs_cmd_t *zc)
 {
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
        int error;
        int opcode;
 
@@ -4302,7 +4334,7 @@ zfs_ioc_share(zfs_cmd_t *zc)
        return (error);
 #else
        return (ENOTSUP);
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 }
 
 ace_t full_access[] = {
@@ -4419,7 +4451,7 @@ zfs_ioc_diff(zfs_cmd_t *zc)
 /*
  * Remove all ACL files in shares dir
  */
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
 static int
 zfs_smb_acl_purge(znode_t *dzp)
 {
@@ -4438,12 +4470,12 @@ zfs_smb_acl_purge(znode_t *dzp)
        zap_cursor_fini(&zc);
        return (error);
 }
-#endif /* HAVE ZPL */
+#endif /* HAVE SHARE */
 
 static int
 zfs_ioc_smb_acl(zfs_cmd_t *zc)
 {
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
        vnode_t *vp;
        znode_t *dzp;
        vnode_t *resourcevp = NULL;
@@ -4568,7 +4600,7 @@ zfs_ioc_smb_acl(zfs_cmd_t *zc)
        return (error);
 #else
        return (ENOTSUP);
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 }
 
 /*
@@ -4715,11 +4747,12 @@ zfs_ioc_events_next(zfs_cmd_t *zc)
                return (error);
 
        do {
-               error = zfs_zevent_next(ze, &event, &dropped);
+               error = zfs_zevent_next(ze, &event,
+                       &zc->zc_nvlist_dst_size, &dropped);
                if (event != NULL) {
                        zc->zc_cookie = dropped;
                        error = put_nvlist(zc, event);
-                       nvlist_free(event);
+                       nvlist_free(event);
                }
 
                if (zc->zc_guid & ZEVENT_NONBLOCK)
@@ -4805,6 +4838,10 @@ static zfs_ioc_vec_t zfs_ioc_vec[] = {
            POOL_CHECK_SUSPENDED },
        { zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE,
            POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY },
+       { zfs_ioc_create_minor, zfs_secpolicy_config, DATASET_NAME, B_FALSE,
+           POOL_CHECK_NONE },
+       { zfs_ioc_remove_minor, zfs_secpolicy_config, DATASET_NAME, B_FALSE,
+           POOL_CHECK_NONE },
        { zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE,
            POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY },
        { zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE,
@@ -5051,7 +5088,7 @@ zfsdev_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
        if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
                return (-EINVAL);
 
-       zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
+       zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP | KM_NODEBUG);
 
        error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
        if (error != 0)
@@ -5111,7 +5148,7 @@ zfsdev_compat_ioctl(struct file *filp, unsigned cmd, unsigned long arg)
         return zfsdev_ioctl(filp, cmd, arg);
 }
 #else
-#define zfs_compat_ioctl   NULL
+#define zfsdev_compat_ioctl   NULL
 #endif
 
 static const struct file_operations zfsdev_fops = {
@@ -5184,12 +5221,12 @@ _init(void)
        if ((error = zfs_attach()) != 0)
                goto out2;
 
-#ifdef HAVE_ZPL
        tsd_create(&zfs_fsyncer_key, NULL);
        tsd_create(&rrw_tsd_key, NULL);
 
+#ifdef HAVE_SHARE
        mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
-#endif /* HAVE_ZPL */
+#endif /* HAVE_SHARE */
 
        printk(KERN_NOTICE "ZFS: Loaded ZFS Filesystem v%s%s\n",
               ZFS_META_VERSION, ZFS_DEBUG_STR);
@@ -5214,7 +5251,7 @@ _fini(void)
        zvol_fini();
        zfs_fini();
        spa_fini();
-#ifdef HAVE_ZPL
+#ifdef HAVE_SHARE
        if (zfs_nfsshare_inited)
                (void) ddi_modclose(nfs_mod);
        if (zfs_smbshare_inited)
@@ -5223,8 +5260,8 @@ _fini(void)
                (void) ddi_modclose(sharefs_mod);
 
        mutex_destroy(&zfs_share_lock);
+#endif /* HAVE_SHARE */
        tsd_destroy(&zfs_fsyncer_key);
-#endif /* HAVE_ZPL */
 
        printk(KERN_NOTICE "ZFS: Unloaded ZFS Filesystem v%s%s\n",
               ZFS_META_VERSION, ZFS_DEBUG_STR);