Skip to content

Commit

Permalink
Add snapdev dataset property to control visibility of zvol snapshot d…
Browse files Browse the repository at this point in the history
…evices
  • Loading branch information
edillmann committed Feb 20, 2013
1 parent 73a046c commit e1a0f01
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ typedef enum {
ZFS_PROP_REFRATIO,
ZFS_PROP_WRITTEN,
ZFS_PROP_CLONES,
ZFS_PROP_SNAPDEV,
ZFS_NUM_PROPS
} zfs_prop_t;

Expand Down
6 changes: 6 additions & 0 deletions include/sys/zfs_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ extern "C" {
#define ZFS_SNAPDIR_HIDDEN 0
#define ZFS_SNAPDIR_VISIBLE 1

/*
* Property values for snapdev
*/
#define ZFS_SNAPDEV_HIDDEN 0
#define ZFS_SNAPDEV_VISIBLE 1

/*
* Field manipulation macros for the drr_versioninfo field of the
* send stream header.
Expand Down
1 change: 1 addition & 0 deletions include/sys/zvol.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern int zvol_remove_minor(const char *);
extern void zvol_remove_minors(const char *);
extern int zvol_set_volsize(const char *, uint64_t);
extern int zvol_set_volblocksize(const char *, uint64_t);
extern int zvol_set_snapdev(const char *, uint64_t);

extern int zvol_init(void);
extern void zvol_fini(void);
Expand Down
11 changes: 11 additions & 0 deletions man/man8/zfs.8
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,17 @@ When the \fBsharenfs\fR property is changed for a dataset, the dataset and any c
Provide a hint to ZFS about handling of synchronous requests in this dataset. If \fBlogbias\fR is set to \fBlatency\fR (the default), ZFS will use pool log devices (if configured) to handle the requests at low latency. If \fBlogbias\fR is set to \fBthroughput\fR, ZFS will not use configured pool log devices. ZFS will instead optimize synchronous operations for global pool throughput and efficient use of resources.
.RE

.sp
.ne 2
.mk
.na
\fB\fBsnapdev\fR=\fBhidden\fR | \fBvisible\fR\fR
.ad
.sp .6
.RS 4n
Controls whether the snapshots devices of zvol's are hidden or visible. The default value is \fBhidden\fR.
.RE

.sp
.ne 2
.mk
Expand Down
9 changes: 9 additions & 0 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ zfs_prop_init(void)
{ NULL }
};

static zprop_index_t snapdev_table[] = {
{ "hidden", ZFS_SNAPDEV_HIDDEN },
{ "visible", ZFS_SNAPDEV_VISIBLE },
{ NULL }
};

static zprop_index_t acl_inherit_table[] = {
{ "discard", ZFS_ACL_DISCARD },
{ "noallow", ZFS_ACL_NOALLOW },
Expand Down Expand Up @@ -217,6 +223,9 @@ zfs_prop_init(void)
zprop_register_index(ZFS_PROP_SNAPDIR, "snapdir", ZFS_SNAPDIR_HIDDEN,
PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
"hidden | visible", "SNAPDIR", snapdir_table);
zprop_register_index(ZFS_PROP_SNAPDEV, "snapdev", ZFS_SNAPDEV_HIDDEN,
PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME,
"hidden | visible", "SNAPDEV", snapdev_table);
zprop_register_index(ZFS_PROP_ACLINHERIT, "aclinherit",
ZFS_ACL_RESTRICTED, PROP_INHERIT, ZFS_TYPE_FILESYSTEM,
"discard | noallow | restricted | passthrough | passthrough-x",
Expand Down
3 changes: 3 additions & 0 deletions module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,9 @@ zfs_prop_set_special(const char *dsname, zprop_source_t source,
case ZFS_PROP_VOLSIZE:
err = zvol_set_volsize(dsname, intval);
break;
case ZFS_PROP_SNAPDEV:
err = zvol_set_snapdev(dsname, intval);
break;
case ZFS_PROP_VERSION:
{
zfs_sb_t *zsb;
Expand Down
58 changes: 55 additions & 3 deletions module/zfs/zvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,14 +1287,17 @@ zvol_free(zvol_state_t *zv)
}

static int
__zvol_create_minor(const char *name)
__zvol_create_minor(const char *name, int filter_snaps)
{
zvol_state_t *zv;
objset_t *os;
dmu_object_info_t *doi;
uint64_t volsize;
uint64_t snapdev;
unsigned minor = 0;
int error = 0;
char *parent;
char *atp;

ASSERT(MUTEX_HELD(&zvol_state_lock));

Expand All @@ -1304,6 +1307,21 @@ __zvol_create_minor(const char *name)
goto out;
}

if (filter_snaps) {
parent = kmem_alloc(MAXPATHLEN, KM_SLEEP);
(void) strlcpy(parent, name, MAXPATHLEN);

if ((atp = strrchr(parent, '@')) != NULL) {
*atp = '\0';
if ((dsl_prop_get_integer(parent, "snapdev", &snapdev, NULL) == 0)
&& (snapdev == ZFS_SNAPDEV_HIDDEN)) {
kmem_free(parent, MAXPATHLEN);
return 0;
}
}
kmem_free(parent, MAXPATHLEN);
}

doi = kmem_alloc(sizeof(dmu_object_info_t), KM_SLEEP);

error = dmu_objset_own(name, DMU_OST_ZVOL, B_TRUE, zvol_tag, &os);
Expand Down Expand Up @@ -1383,7 +1401,7 @@ zvol_create_minor(const char *name)
int error;

mutex_enter(&zvol_state_lock);
error = __zvol_create_minor(name);
error = __zvol_create_minor(name, TRUE);
mutex_exit(&zvol_state_lock);

return (error);
Expand Down Expand Up @@ -1431,7 +1449,7 @@ zvol_create_minors_cb(spa_t *spa, uint64_t dsobj,
if (strchr(dsname, '/') == NULL)
return 0;

(void) __zvol_create_minor(dsname);
(void) __zvol_create_minor(dsname, TRUE);
return (0);
}

Expand Down Expand Up @@ -1499,6 +1517,40 @@ zvol_remove_minors(const char *pool)
kmem_free(str, MAXNAMELEN);
}

static int
snapdev_snapshot_changed_cb(const char *dsname, void *arg) {
uint64_t snapdev = *(uint64_t *) arg;

if (strchr(dsname, '@') == NULL) {
return 0;
}

This comment has been minimized.

Copy link
@edillmann

edillmann Feb 21, 2013

Author Owner

I should remote this {}


switch (snapdev) {
case ZFS_SNAPDEV_VISIBLE:
mutex_enter(&zvol_state_lock);
(void) __zvol_create_minor(dsname, FALSE);
mutex_exit(&zvol_state_lock);
break;
case ZFS_SNAPDEV_HIDDEN:
(void) zvol_remove_minor(dsname);
break;
}
return 0;
}

int
zvol_set_snapdev(const char *dsname, uint64_t snapdev) {
/* Inheritance and range checking should have been done by now */
ASSERT(snapdev == ZFS_SNAPDEV_HIDDEN || snapdev == ZFS_SNAPDEV_VISIBLE);

(void) dmu_objset_find((char *) dsname, snapdev_snapshot_changed_cb,
&snapdev, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
/* caller should continue to modify snapdev property */
return (-1);

}


int
zvol_init(void)
{
Expand Down

0 comments on commit e1a0f01

Please sign in to comment.