Commit c23bf227 authored by Umer Saleem's avatar Umer Saleem
Browse files

Set immutable flag on auto-generated dataset mountpoints

Signed-off-by: default avatarUmer Saleem <usaleem@ixsystems.com>
No related merge requests found
Showing with 41 additions and 0 deletions
+41 -0
......@@ -82,6 +82,7 @@
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/dsl_crypt.h>
#include <linux/fs.h>
#include <libzfs.h>
......@@ -363,6 +364,34 @@ zfs_add_options(zfs_handle_t *zhp, char *options, int len)
return (error);
}
static int
zfs_mount_set_uchg(const char *mountpoint)
{
int fd, r;
uint32_t attrs;
fd = open(mountpoint, (O_RDONLY|O_NONBLOCK|O_NOFOLLOW));
if (fd < 0)
return -1;
printf("Mountpoint %s opened!\n", mountpoint);
r = ioctl(fd, FS_IOC_GETFLAGS, &attrs);
if (r < 0)
goto out;
printf("Attributes before: 0x%x\n", attrs);
attrs |= FS_IMMUTABLE_FL;
r = ioctl(fd, FS_IOC_SETFLAGS, &attrs);
if (r < 0)
goto out;
attrs = -1;
r = ioctl(fd, FS_IOC_GETFLAGS, &attrs);
if (r < 0)
goto out;
printf("Attributes after: 0x%x\n", attrs);
out:
close(fd);
return r;
}
int
zfs_mount(zfs_handle_t *zhp, const char *options, int flags)
{
......@@ -391,6 +420,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
libzfs_handle_t *hdl = zhp->zfs_hdl;
uint64_t keystatus;
int remount = 0, rc;
boolean_t set_uchg = B_FALSE;
if (options == NULL) {
(void) strlcpy(mntopts, MNTOPT_DEFAULTS, sizeof (mntopts));
......@@ -495,6 +525,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
mountpoint));
}
set_uchg = B_TRUE;
}
/*
......@@ -561,6 +592,16 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags,
/* add the mounted entry into our cache */
libzfs_mnttab_add(hdl, zfs_get_name(zhp), mountpoint, mntopts);
if (set_uchg) {
if (zfs_mount_set_uchg(mountpoint) < 0) {
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
dgettext(TEXT_DOMAIN, "cannot set immuteable"
"flag on auto generated mountpoint '%s' of "
"mount '%s'"), mountpoint , zhp->zfs_name));
}
}
return (0);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment