Fix gcc array subscript above bounds warning
[zfs.git] / module / zfs / zfs_ctldir.c
index 1923934..a667340 100644 (file)
  */
 int zfs_expire_snapshot = ZFSCTL_EXPIRE_SNAPSHOT;
 
+/*
+ * Dedicated task queue for unmounting snapshots.
+ */
+static taskq_t *zfs_expire_taskq;
+
 static zfs_snapentry_t *
 zfsctl_sep_alloc(void)
 {
@@ -112,16 +117,15 @@ zfsctl_sep_free(zfs_snapentry_t *sep)
 static void
 zfsctl_expire_snapshot(void *data)
 {
-       zfs_snapentry_t *sep;
-       zfs_sb_t *zsb;
+       zfs_snapentry_t *sep = (zfs_snapentry_t *)data;
+       zfs_sb_t *zsb = ITOZSB(sep->se_inode);
        int error;
 
-       sep = spl_get_work_data(data, zfs_snapentry_t, se_work.work);
-       zsb = ITOZSB(sep->se_inode);
-
        error = zfsctl_unmount_snapshot(zsb, sep->se_name, MNT_EXPIRE);
        if (error == EBUSY)
-               schedule_delayed_work(&sep->se_work, zfs_expire_snapshot * HZ);
+               sep->se_taskqid = taskq_dispatch_delay(zfs_expire_taskq,
+                   zfsctl_expire_snapshot, sep, TQ_SLEEP,
+                   ddi_get_lbolt() + zfs_expire_snapshot * HZ);
 }
 
 int
@@ -225,13 +229,13 @@ zfsctl_inode_alloc(zfs_sb_t *zsb, uint64_t id,
  * Lookup the inode with given id, it will be allocated if needed.
  */
 static struct inode *
-zfsctl_inode_lookup(zfs_sb_t *zsb, unsigned long id,
+zfsctl_inode_lookup(zfs_sb_t *zsb, uint64_t id,
     const struct file_operations *fops, const struct inode_operations *ops)
 {
        struct inode *ip = NULL;
 
        while (ip == NULL) {
-               ip = ilookup(zsb->z_sb, id);
+               ip = ilookup(zsb->z_sb, (unsigned long)id);
                if (ip)
                        break;
 
@@ -267,10 +271,14 @@ zfsctl_inode_inactive(struct inode *ip)
  * therefore checks against a vfs_count of 2 instead of 1.  This reference
  * is removed when the ctldir is destroyed in the unmount.  All other entities
  * under the '.zfs' directory are created dynamically as needed.
+ *
+ * Because the dynamically created '.zfs' directory entries assume the use
+ * of 64-bit inode numbers this support must be disabled on 32-bit systems.
  */
 int
 zfsctl_create(zfs_sb_t *zsb)
 {
+#if defined(CONFIG_64BIT)
        ASSERT(zsb->z_ctldir == NULL);
 
        zsb->z_ctldir = zfsctl_inode_alloc(zsb, ZFSCTL_INO_ROOT,
@@ -279,6 +287,9 @@ zfsctl_create(zfs_sb_t *zsb)
                return (ENOENT);
 
        return (0);
+#else
+       return (EOPNOTSUPP);
+#endif /* CONFIG_64BIT */
 }
 
 /*
@@ -654,7 +665,7 @@ zfsctl_snapdir_inactive(struct inode *ip)
 
                if (sep->se_inode == ip) {
                        avl_remove(&zsb->z_ctldir_snaps, sep);
-                       cancel_delayed_work_sync(&sep->se_work);
+                       taskq_cancel_id(zfs_expire_taskq, sep->se_taskqid);
                        zfsctl_sep_free(sep);
                        break;
                }
@@ -674,7 +685,7 @@ zfsctl_snapdir_inactive(struct inode *ip)
        "exec 0</dev/null " \
        "     1>/dev/null " \
        "     2>/dev/null; " \
-       "umount -t zfs -n %s%s"
+       "umount -t zfs -n '%s%s'"
 
 static int
 __zfsctl_unmount_snapshot(zfs_snapentry_t *sep, int flags)
@@ -701,7 +712,8 @@ __zfsctl_unmount_snapshot(zfs_snapentry_t *sep, int flags)
         * to prevent zfsctl_expire_snapshot() from attempting a unmount.
         */
        if ((error == 0) && !(flags & MNT_EXPIRE))
-               cancel_delayed_work(&sep->se_work);
+               taskq_cancel_id(zfs_expire_taskq, sep->se_taskqid);
+
 
        return (error);
 }
@@ -774,7 +786,7 @@ zfsctl_unmount_snapshots(zfs_sb_t *zsb, int flags, int *count)
        "exec 0</dev/null " \
        "     1>/dev/null " \
        "     2>/dev/null; " \
-       "mount -t zfs -n %s %s"
+       "mount -t zfs -n '%s' '%s'"
 
 int
 zfsctl_mount_snapshot(struct path *path, int flags)
@@ -830,7 +842,7 @@ zfsctl_mount_snapshot(struct path *path, int flags)
        sep = avl_find(&zsb->z_ctldir_snaps, &search, NULL);
        if (sep) {
                avl_remove(&zsb->z_ctldir_snaps, sep);
-               cancel_delayed_work_sync(&sep->se_work);
+               taskq_cancel_id(zfs_expire_taskq, sep->se_taskqid);
                zfsctl_sep_free(sep);
        }
 
@@ -840,8 +852,9 @@ zfsctl_mount_snapshot(struct path *path, int flags)
        sep->se_inode = ip;
        avl_add(&zsb->z_ctldir_snaps, sep);
 
-        spl_init_delayed_work(&sep->se_work, zfsctl_expire_snapshot, sep);
-       schedule_delayed_work(&sep->se_work, zfs_expire_snapshot * HZ);
+       sep->se_taskqid = taskq_dispatch_delay(zfs_expire_taskq,
+           zfsctl_expire_snapshot, sep, TQ_SLEEP,
+           ddi_get_lbolt() + zfs_expire_snapshot * HZ);
 
        mutex_exit(&zsb->z_ctldir_lock);
 error:
@@ -913,8 +926,8 @@ zfsctl_lookup_objset(struct super_block *sb, uint64_t objsetid, zfs_sb_t **zsbp)
                 * race cannot occur to an expired mount point because
                 * we hold the zsb->z_ctldir_lock to prevent the race.
                 */
-               sbp = sget(&zpl_fs_type, zfsctl_test_super,
-                   zfsctl_set_super, &id);
+               sbp = zpl_sget(&zpl_fs_type, zfsctl_test_super,
+                   zfsctl_set_super, 0, &id);
                if (IS_ERR(sbp)) {
                        error = -PTR_ERR(sbp);
                } else {
@@ -945,7 +958,7 @@ zfsctl_shares_lookup(struct inode *dip, char *name, struct inode **ipp,
 
        if (zsb->z_shares_dir == 0) {
                ZFS_EXIT(zsb);
-               return (-ENOTSUP);
+               return (ENOTSUP);
        }
 
        error = zfs_zget(zsb, zsb->z_shares_dir, &dzp);
@@ -970,6 +983,8 @@ zfsctl_shares_lookup(struct inode *dip, char *name, struct inode **ipp,
 void
 zfsctl_init(void)
 {
+       zfs_expire_taskq = taskq_create("z_unmount", 1, maxclsyspri,
+           1, 8, TASKQ_PREPOPULATE);
 }
 
 /*
@@ -979,6 +994,7 @@ zfsctl_init(void)
 void
 zfsctl_fini(void)
 {
+       taskq_destroy(zfs_expire_taskq);
 }
 
 module_param(zfs_expire_snapshot, int, 0644);