* Rewritten for Linux by:
* Rohan Puri <rohan.puri15@gmail.com>
* Brian Behlendorf <behlendorf1@llnl.gov>
+ * Copyright (c) 2013 by Delphix. All rights reserved.
*/
/*
static zfs_snapentry_t *
zfsctl_sep_alloc(void)
{
- return kmem_zalloc(sizeof (zfs_snapentry_t), KM_SLEEP);
+ return (kmem_zalloc(sizeof (zfs_snapentry_t), KM_SLEEP));
}
void
void
zfsctl_inode_destroy(struct inode *ip)
{
- return;
}
/*
zsb->z_ctldir = zfsctl_inode_alloc(zsb, ZFSCTL_INO_ROOT,
&zpl_fops_root, &zpl_ops_root);
if (zsb->z_ctldir == NULL)
- return (ENOENT);
+ return (SET_ERROR(ENOENT));
return (0);
#else
- return (EOPNOTSUPP);
+ return (SET_ERROR(EOPNOTSUPP));
#endif /* CONFIG_64BIT */
}
if (fidp->fid_len < SHORT_FID_LEN) {
fidp->fid_len = SHORT_FID_LEN;
ZFS_EXIT(zsb);
- return (ENOSPC);
+ return (SET_ERROR(ENOSPC));
}
zfid = (zfid_short_t *)fidp;
objset_t *os = ITOZSB(ip)->z_os;
if (snapshot_namecheck(name, NULL, NULL) != 0)
- return (EILSEQ);
+ return (SET_ERROR(EILSEQ));
dmu_objset_name(os, zname);
if ((strlen(zname) + 1 + strlen(name)) >= len)
- return (ENAMETOOLONG);
+ return (SET_ERROR(ENAMETOOLONG));
(void) strcat(zname, "@");
(void) strcat(zname, name);
return (0);
}
+/*
+ * Gets the full dataset name that corresponds to the given snapshot name
+ * Example:
+ * zfsctl_snapshot_zname("snap1") -> "mypool/myfs@snap1"
+ */
static int
zfsctl_snapshot_zpath(struct path *path, int len, char *zpath)
{
path_len = path_buffer + len - 1 - path_ptr;
if (path_len > len) {
- error = EFAULT;
+ error = SET_ERROR(EFAULT);
goto out;
}
}
if (*ipp == NULL)
- error = ENOENT;
+ error = SET_ERROR(ENOENT);
ZFS_EXIT(zsb);
(*ipp)->i_flags |= S_AUTOMOUNT;
#endif /* HAVE_AUTOMOUNT */
} else {
- error = ENOENT;
+ error = SET_ERROR(ENOENT);
}
ZFS_EXIT(zsb);
* Cannot move snapshots out of the snapdir.
*/
if (sdip != tdip) {
- error = EINVAL;
+ error = SET_ERROR(EINVAL);
goto out;
}
dsname = kmem_alloc(MAXNAMELEN, KM_SLEEP);
if (snapshot_namecheck(dirname, NULL, NULL) != 0) {
- error = EILSEQ;
+ error = SET_ERROR(EILSEQ);
goto out;
}
* best effort. In the case where it does fail, perhaps because
* it's in use, the unmount will fail harmlessly.
*/
-#define SET_UNMOUNT_CMD \
+#define SET_UNMOUNT_CMD \
"exec 0</dev/null " \
" 1>/dev/null " \
" 2>/dev/null; " \
* converted to the more sensible EBUSY.
*/
if (error)
- error = EBUSY;
+ error = SET_ERROR(EBUSY);
/*
* This was the result of a manual unmount, cancel the delayed work
else
zfsctl_sep_free(sep);
} else {
- error = ENOENT;
+ error = SET_ERROR(ENOENT);
}
mutex_exit(&zsb->z_ctldir_lock);
return ((*count > 0) ? EEXIST : 0);
}
-#define SET_MOUNT_CMD \
+#define MOUNT_BUSY 0x80 /* Mount failed due to EBUSY (from mntent.h) */
+
+#define SET_MOUNT_CMD \
"exec 0</dev/null " \
" 1>/dev/null " \
" 2>/dev/null; " \
* function is marked GPL-only and cannot be used. On error we
* careful to log the real error to the console and return EISDIR
* to safely abort the automount. This should be very rare.
+ *
+ * If the user mode helper happens to return EBUSY, a concurrent
+ * mount is already in progress in which case the error is ignored.
+ * Take note that if the program was executed successfully the return
+ * value from call_usermodehelper() will be (exitcode << 8 + signal).
*/
argv[2] = kmem_asprintf(SET_MOUNT_CMD, full_name, full_path);
error = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
strfree(argv[2]);
- if (error) {
+ if (error && !(error & MOUNT_BUSY << 8)) {
printk("ZFS: Unable to automount %s at %s: %d\n",
full_name, full_path, error);
- error = EISDIR;
+ error = SET_ERROR(EISDIR);
goto error;
}
+ error = 0;
mutex_enter(&zsb->z_ctldir_lock);
/*
deactivate_super(sbp);
}
} else {
- error = EINVAL;
+ error = SET_ERROR(EINVAL);
}
out:
mutex_exit(&zsb->z_ctldir_lock);
if (zsb->z_shares_dir == 0) {
ZFS_EXIT(zsb);
- return (ENOTSUP);
+ return (SET_ERROR(ENOTSUP));
}
error = zfs_zget(zsb, zsb->z_shares_dir, &dzp);