mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-05-25 16:04:59 +03:00
cred: properly pass and test creds on other threads (#17273)
### Background Various admin operations will be invoked by some userspace task, but the work will be done on a separate kernel thread at a later time. Snapshots are an example, which are triggered through zfs_ioc_snapshot() -> dsl_dataset_snapshot(), but the actual work is from a task dispatched to dp_sync_taskq. Many such tasks end up in dsl_enforce_ds_ss_limits(), where various limits and permissions are enforced. Among other things, it is necessary to ensure that the invoking task (that is, the user) has permission to do things. We can't simply check if the running task has permission; it is a privileged kernel thread, which can do anything. However, in the general case it's not safe to simply query the task for its permissions at the check time, as the task may not exist any more, or its permissions may have changed since it was first invoked. So instead, we capture the permissions by saving CRED() in the user task, and then using it for the check through the secpolicy_* functions. ### Current implementation The current code calls CRED() to get the credential, which gets a pointer to the cred_t inside the current task and passes it to the worker task. However, it doesn't take a reference to the cred_t, and so expects that it won't change, and that the task continues to exist. In practice that is always the case, because we don't let the calling task return from the kernel until the work is done. For Linux, we also take a reference to the current task, because the Linux credential APIs for the most part do not check an arbitrary credential, but rather, query what a task can do. See secpolicy_zfs_proc(). Again, we don't take a reference on the task, just a pointer to it. ### Changes We change to calling crhold() on the task credential, and crfree() when we're done with it. This ensures it stays alive and unchanged for the duration of the call. On the Linux side, we change the main policy checking function priv_policy_ns() to use override_creds()/revert_creds() if necessary to make the provided credential active in the current task, allowing the standard task-permission APIs to do the needed check. Since the task pointer is no longer required, this lets us entirely remove secpolicy_zfs_proc() and the need to carry a task pointer around as well. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <robn@despairlabs.com> Reviewed-by: Pavel Snajdr <snajpa@snajpa.net> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Kyle Evans <kevans@FreeBSD.org> Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
parent
ba17cedf65
commit
c8fa39b46c
@ -39,7 +39,6 @@ struct znode;
|
|||||||
|
|
||||||
int secpolicy_nfs(cred_t *cr);
|
int secpolicy_nfs(cred_t *cr);
|
||||||
int secpolicy_zfs(cred_t *crd);
|
int secpolicy_zfs(cred_t *crd);
|
||||||
int secpolicy_zfs_proc(cred_t *cr, proc_t *proc);
|
|
||||||
int secpolicy_sys_config(cred_t *cr, int checkonly);
|
int secpolicy_sys_config(cred_t *cr, int checkonly);
|
||||||
int secpolicy_zinject(cred_t *cr);
|
int secpolicy_zinject(cred_t *cr);
|
||||||
int secpolicy_fs_unmount(cred_t *cr, struct mount *vfsp);
|
int secpolicy_fs_unmount(cred_t *cr, struct mount *vfsp);
|
||||||
|
@ -52,7 +52,6 @@ int secpolicy_vnode_setids_setgids(const cred_t *, gid_t, zidmap_t *,
|
|||||||
struct user_namespace *);
|
struct user_namespace *);
|
||||||
int secpolicy_zinject(const cred_t *);
|
int secpolicy_zinject(const cred_t *);
|
||||||
int secpolicy_zfs(const cred_t *);
|
int secpolicy_zfs(const cred_t *);
|
||||||
int secpolicy_zfs_proc(const cred_t *, proc_t *);
|
|
||||||
void secpolicy_setid_clear(vattr_t *, cred_t *);
|
void secpolicy_setid_clear(vattr_t *, cred_t *);
|
||||||
int secpolicy_setid_setsticky_clear(struct inode *, vattr_t *,
|
int secpolicy_setid_setsticky_clear(struct inode *, vattr_t *,
|
||||||
const vattr_t *, cred_t *, zidmap_t *, struct user_namespace *);
|
const vattr_t *, cred_t *, zidmap_t *, struct user_namespace *);
|
||||||
|
@ -60,7 +60,6 @@ typedef struct dmu_recv_cookie {
|
|||||||
uint64_t drc_ivset_guid;
|
uint64_t drc_ivset_guid;
|
||||||
void *drc_owner;
|
void *drc_owner;
|
||||||
cred_t *drc_cred;
|
cred_t *drc_cred;
|
||||||
proc_t *drc_proc;
|
|
||||||
nvlist_t *drc_begin_nvl;
|
nvlist_t *drc_begin_nvl;
|
||||||
|
|
||||||
objset_t *drc_os;
|
objset_t *drc_os;
|
||||||
|
@ -284,7 +284,6 @@ typedef struct dsl_dataset_promote_arg {
|
|||||||
uint64_t used, comp, uncomp, unique, cloneusedsnap, originusedsnap;
|
uint64_t used, comp, uncomp, unique, cloneusedsnap, originusedsnap;
|
||||||
nvlist_t *err_ds;
|
nvlist_t *err_ds;
|
||||||
cred_t *cr;
|
cred_t *cr;
|
||||||
proc_t *proc;
|
|
||||||
} dsl_dataset_promote_arg_t;
|
} dsl_dataset_promote_arg_t;
|
||||||
|
|
||||||
typedef struct dsl_dataset_rollback_arg {
|
typedef struct dsl_dataset_rollback_arg {
|
||||||
@ -299,7 +298,6 @@ typedef struct dsl_dataset_snapshot_arg {
|
|||||||
nvlist_t *ddsa_props;
|
nvlist_t *ddsa_props;
|
||||||
nvlist_t *ddsa_errors;
|
nvlist_t *ddsa_errors;
|
||||||
cred_t *ddsa_cr;
|
cred_t *ddsa_cr;
|
||||||
proc_t *ddsa_proc;
|
|
||||||
} dsl_dataset_snapshot_arg_t;
|
} dsl_dataset_snapshot_arg_t;
|
||||||
|
|
||||||
typedef struct dsl_dataset_rename_snapshot_arg {
|
typedef struct dsl_dataset_rename_snapshot_arg {
|
||||||
@ -459,7 +457,7 @@ int dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
|
|||||||
void dsl_dataset_clone_swap_sync_impl(dsl_dataset_t *clone,
|
void dsl_dataset_clone_swap_sync_impl(dsl_dataset_t *clone,
|
||||||
dsl_dataset_t *origin_head, dmu_tx_t *tx);
|
dsl_dataset_t *origin_head, dmu_tx_t *tx);
|
||||||
int dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
|
int dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
|
||||||
dmu_tx_t *tx, boolean_t recv, uint64_t cnt, cred_t *cr, proc_t *proc);
|
dmu_tx_t *tx, boolean_t recv, uint64_t cnt, cred_t *cr);
|
||||||
void dsl_dataset_snapshot_sync_impl(dsl_dataset_t *ds, const char *snapname,
|
void dsl_dataset_snapshot_sync_impl(dsl_dataset_t *ds, const char *snapname,
|
||||||
dmu_tx_t *tx);
|
dmu_tx_t *tx);
|
||||||
|
|
||||||
|
@ -185,11 +185,11 @@ int dsl_dir_set_reservation(const char *ddname, zprop_source_t source,
|
|||||||
uint64_t reservation);
|
uint64_t reservation);
|
||||||
int dsl_dir_activate_fs_ss_limit(const char *);
|
int dsl_dir_activate_fs_ss_limit(const char *);
|
||||||
int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *,
|
int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *,
|
||||||
cred_t *, proc_t *);
|
cred_t *);
|
||||||
void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *);
|
void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *);
|
||||||
int dsl_dir_rename(const char *oldname, const char *newname);
|
int dsl_dir_rename(const char *oldname, const char *newname);
|
||||||
int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
|
int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
|
||||||
uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *, proc_t *);
|
uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *);
|
||||||
boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
|
boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
|
||||||
void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
|
void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
|
||||||
uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
|
uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
|
||||||
|
@ -76,7 +76,6 @@ typedef struct zcp_run_info {
|
|||||||
* rather than the 'current' thread's.
|
* rather than the 'current' thread's.
|
||||||
*/
|
*/
|
||||||
cred_t *zri_cred;
|
cred_t *zri_cred;
|
||||||
proc_t *zri_proc;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The tx in which this channel program is running.
|
* The tx in which this channel program is running.
|
||||||
|
@ -632,6 +632,9 @@ extern void delay(clock_t ticks);
|
|||||||
#define kcred NULL
|
#define kcred NULL
|
||||||
#define CRED() NULL
|
#define CRED() NULL
|
||||||
|
|
||||||
|
#define crhold(cr) ((void)cr)
|
||||||
|
#define crfree(cr) ((void)cr)
|
||||||
|
|
||||||
#define ptob(x) ((x) * PAGESIZE)
|
#define ptob(x) ((x) * PAGESIZE)
|
||||||
|
|
||||||
#define NN_DIVISOR_1000 (1U << 0)
|
#define NN_DIVISOR_1000 (1U << 0)
|
||||||
@ -744,7 +747,6 @@ extern int zfs_secpolicy_rename_perms(const char *from, const char *to,
|
|||||||
cred_t *cr);
|
cred_t *cr);
|
||||||
extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
|
extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
|
||||||
extern int secpolicy_zfs(const cred_t *cr);
|
extern int secpolicy_zfs(const cred_t *cr);
|
||||||
extern int secpolicy_zfs_proc(const cred_t *cr, proc_t *proc);
|
|
||||||
extern zoneid_t getzoneid(void);
|
extern zoneid_t getzoneid(void);
|
||||||
|
|
||||||
/* SID stuff */
|
/* SID stuff */
|
||||||
|
@ -918,13 +918,6 @@ secpolicy_zfs(const cred_t *cr)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
secpolicy_zfs_proc(const cred_t *cr, proc_t *proc)
|
|
||||||
{
|
|
||||||
(void) cr, (void) proc;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ksiddomain_t *
|
ksiddomain_t *
|
||||||
ksid_lookupdomain(const char *dom)
|
ksid_lookupdomain(const char *dom)
|
||||||
{
|
{
|
||||||
|
@ -52,13 +52,6 @@ secpolicy_zfs(cred_t *cr)
|
|||||||
return (priv_check_cred(cr, PRIV_VFS_MOUNT));
|
return (priv_check_cred(cr, PRIV_VFS_MOUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
secpolicy_zfs_proc(cred_t *cr, proc_t *proc)
|
|
||||||
{
|
|
||||||
|
|
||||||
return (priv_check_cred(cr, PRIV_VFS_MOUNT));
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
secpolicy_sys_config(cred_t *cr, int checkonly __unused)
|
secpolicy_sys_config(cred_t *cr, int checkonly __unused)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||||
* Copyright 2013, Joyent, Inc. All rights reserved.
|
* Copyright 2013, Joyent, Inc. All rights reserved.
|
||||||
* Copyright (C) 2016 Lawrence Livermore National Security, LLC.
|
* Copyright (C) 2016 Lawrence Livermore National Security, LLC.
|
||||||
|
* Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
|
||||||
*
|
*
|
||||||
* For Linux the vast majority of this enforcement is already handled via
|
* For Linux the vast majority of this enforcement is already handled via
|
||||||
* the standard Linux VFS permission checks. However certain administrative
|
* the standard Linux VFS permission checks. However certain administrative
|
||||||
@ -35,28 +36,32 @@
|
|||||||
#include <linux/security.h>
|
#include <linux/security.h>
|
||||||
#include <linux/vfs_compat.h>
|
#include <linux/vfs_compat.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* The passed credentials cannot be directly verified because Linux only
|
|
||||||
* provides and interface to check the *current* process credentials. In
|
|
||||||
* order to handle this the capable() test is only run when the passed
|
|
||||||
* credentials match the current process credentials or the kcred. In
|
|
||||||
* all other cases this function must fail and return the passed err.
|
|
||||||
*/
|
|
||||||
static int
|
static int
|
||||||
priv_policy_ns(const cred_t *cr, int capability, int err,
|
priv_policy_ns(const cred_t *cr, int capability, int err,
|
||||||
struct user_namespace *ns)
|
struct user_namespace *ns)
|
||||||
{
|
{
|
||||||
if (cr != CRED() && (cr != kcred))
|
/*
|
||||||
return (err);
|
* The passed credentials cannot be directly verified because Linux
|
||||||
|
* only provides an interface to check the *current* process
|
||||||
|
* credentials. In order to handle this we check if the passed in
|
||||||
|
* creds match the current process credentials or the kcred. If not,
|
||||||
|
* we swap the passed credentials into the current task, perform the
|
||||||
|
* check, and then revert it before returning.
|
||||||
|
*/
|
||||||
|
const cred_t *old =
|
||||||
|
(cr != CRED() && cr != kcred) ? override_creds(cr) : NULL;
|
||||||
|
|
||||||
#if defined(CONFIG_USER_NS)
|
#if defined(CONFIG_USER_NS)
|
||||||
if (!(ns ? ns_capable(ns, capability) : capable(capability)))
|
if (ns ? ns_capable(ns, capability) : capable(capability))
|
||||||
#else
|
#else
|
||||||
if (!capable(capability))
|
if (capable(capability))
|
||||||
#endif
|
#endif
|
||||||
return (err);
|
err = 0;
|
||||||
|
|
||||||
return (0);
|
if (old)
|
||||||
|
revert_creds(old);
|
||||||
|
|
||||||
|
return (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -249,19 +254,6 @@ secpolicy_zfs(const cred_t *cr)
|
|||||||
return (priv_policy(cr, CAP_SYS_ADMIN, EACCES));
|
return (priv_policy(cr, CAP_SYS_ADMIN, EACCES));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Equivalent to secpolicy_zfs(), but works even if the cred_t is not that of
|
|
||||||
* the current process. Takes both cred_t and proc_t so that this can work
|
|
||||||
* easily on all platforms.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
secpolicy_zfs_proc(const cred_t *cr, proc_t *proc)
|
|
||||||
{
|
|
||||||
if (!has_capability(proc, CAP_SYS_ADMIN))
|
|
||||||
return (EACCES);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
secpolicy_setid_clear(vattr_t *vap, cred_t *cr)
|
secpolicy_setid_clear(vattr_t *vap, cred_t *cr)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
* Copyright (c) 2019, Klara Inc.
|
* Copyright (c) 2019, Klara Inc.
|
||||||
* Copyright (c) 2019, Allan Jude
|
* Copyright (c) 2019, Allan Jude
|
||||||
* Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
|
* Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
|
||||||
|
* Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Portions Copyright 2010 Robert Milkowski */
|
/* Portions Copyright 2010 Robert Milkowski */
|
||||||
@ -68,6 +69,7 @@
|
|||||||
#include <sys/vdev_impl.h>
|
#include <sys/vdev_impl.h>
|
||||||
#include <sys/arc.h>
|
#include <sys/arc.h>
|
||||||
#include <cityhash.h>
|
#include <cityhash.h>
|
||||||
|
#include <sys/cred.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Needed to close a window in dnode_move() that allows the objset to be freed
|
* Needed to close a window in dnode_move() that allows the objset to be freed
|
||||||
@ -1179,7 +1181,6 @@ dmu_objset_create_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp,
|
|||||||
typedef struct dmu_objset_create_arg {
|
typedef struct dmu_objset_create_arg {
|
||||||
const char *doca_name;
|
const char *doca_name;
|
||||||
cred_t *doca_cred;
|
cred_t *doca_cred;
|
||||||
proc_t *doca_proc;
|
|
||||||
void (*doca_userfunc)(objset_t *os, void *arg,
|
void (*doca_userfunc)(objset_t *os, void *arg,
|
||||||
cred_t *cr, dmu_tx_t *tx);
|
cred_t *cr, dmu_tx_t *tx);
|
||||||
void *doca_userarg;
|
void *doca_userarg;
|
||||||
@ -1223,7 +1224,7 @@ dmu_objset_create_check(void *arg, dmu_tx_t *tx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL,
|
error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL,
|
||||||
doca->doca_cred, doca->doca_proc);
|
doca->doca_cred);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dsl_dir_rele(pdd, FTAG);
|
dsl_dir_rele(pdd, FTAG);
|
||||||
return (error);
|
return (error);
|
||||||
@ -1350,9 +1351,11 @@ dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
|
|||||||
dmu_objset_create_arg_t doca;
|
dmu_objset_create_arg_t doca;
|
||||||
dsl_crypto_params_t tmp_dcp = { 0 };
|
dsl_crypto_params_t tmp_dcp = { 0 };
|
||||||
|
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
doca.doca_name = name;
|
doca.doca_name = name;
|
||||||
doca.doca_cred = CRED();
|
doca.doca_cred = cr;
|
||||||
doca.doca_proc = curproc;
|
|
||||||
doca.doca_flags = flags;
|
doca.doca_flags = flags;
|
||||||
doca.doca_userfunc = func;
|
doca.doca_userfunc = func;
|
||||||
doca.doca_userarg = arg;
|
doca.doca_userarg = arg;
|
||||||
@ -1374,6 +1377,9 @@ dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
|
|||||||
|
|
||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
zvol_create_minor(name);
|
zvol_create_minor(name);
|
||||||
|
|
||||||
|
crfree(cr);
|
||||||
|
|
||||||
return (rv);
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1381,7 +1387,6 @@ typedef struct dmu_objset_clone_arg {
|
|||||||
const char *doca_clone;
|
const char *doca_clone;
|
||||||
const char *doca_origin;
|
const char *doca_origin;
|
||||||
cred_t *doca_cred;
|
cred_t *doca_cred;
|
||||||
proc_t *doca_proc;
|
|
||||||
} dmu_objset_clone_arg_t;
|
} dmu_objset_clone_arg_t;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1409,7 +1414,7 @@ dmu_objset_clone_check(void *arg, dmu_tx_t *tx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL,
|
error = dsl_fs_ss_limit_check(pdd, 1, ZFS_PROP_FILESYSTEM_LIMIT, NULL,
|
||||||
doca->doca_cred, doca->doca_proc);
|
doca->doca_cred);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dsl_dir_rele(pdd, FTAG);
|
dsl_dir_rele(pdd, FTAG);
|
||||||
return (SET_ERROR(EDQUOT));
|
return (SET_ERROR(EDQUOT));
|
||||||
@ -1465,10 +1470,12 @@ dmu_objset_clone(const char *clone, const char *origin)
|
|||||||
{
|
{
|
||||||
dmu_objset_clone_arg_t doca;
|
dmu_objset_clone_arg_t doca;
|
||||||
|
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
doca.doca_clone = clone;
|
doca.doca_clone = clone;
|
||||||
doca.doca_origin = origin;
|
doca.doca_origin = origin;
|
||||||
doca.doca_cred = CRED();
|
doca.doca_cred = cr;
|
||||||
doca.doca_proc = curproc;
|
|
||||||
|
|
||||||
int rv = dsl_sync_task(clone,
|
int rv = dsl_sync_task(clone,
|
||||||
dmu_objset_clone_check, dmu_objset_clone_sync, &doca,
|
dmu_objset_clone_check, dmu_objset_clone_sync, &doca,
|
||||||
@ -1477,6 +1484,8 @@ dmu_objset_clone(const char *clone, const char *origin)
|
|||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
zvol_create_minor(clone);
|
zvol_create_minor(clone);
|
||||||
|
|
||||||
|
crfree(cr);
|
||||||
|
|
||||||
return (rv);
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
* Copyright (c) 2019, Allan Jude
|
* Copyright (c) 2019, Allan Jude
|
||||||
* Copyright (c) 2019 Datto Inc.
|
* Copyright (c) 2019 Datto Inc.
|
||||||
* Copyright (c) 2022 Axcient.
|
* Copyright (c) 2022 Axcient.
|
||||||
|
* Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/arc.h>
|
#include <sys/arc.h>
|
||||||
@ -68,6 +69,7 @@
|
|||||||
#include <sys/zfs_vfsops.h>
|
#include <sys/zfs_vfsops.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/zfs_file.h>
|
#include <sys/zfs_file.h>
|
||||||
|
#include <sys/cred.h>
|
||||||
|
|
||||||
static uint_t zfs_recv_queue_length = SPA_MAXBLOCKSIZE;
|
static uint_t zfs_recv_queue_length = SPA_MAXBLOCKSIZE;
|
||||||
static uint_t zfs_recv_queue_ff = 20;
|
static uint_t zfs_recv_queue_ff = 20;
|
||||||
@ -145,7 +147,6 @@ typedef struct dmu_recv_begin_arg {
|
|||||||
const char *drba_origin;
|
const char *drba_origin;
|
||||||
dmu_recv_cookie_t *drba_cookie;
|
dmu_recv_cookie_t *drba_cookie;
|
||||||
cred_t *drba_cred;
|
cred_t *drba_cred;
|
||||||
proc_t *drba_proc;
|
|
||||||
dsl_crypto_params_t *drba_dcp;
|
dsl_crypto_params_t *drba_dcp;
|
||||||
} dmu_recv_begin_arg_t;
|
} dmu_recv_begin_arg_t;
|
||||||
|
|
||||||
@ -411,7 +412,7 @@ recv_begin_check_existing_impl(dmu_recv_begin_arg_t *drba, dsl_dataset_t *ds,
|
|||||||
* against that limit.
|
* against that limit.
|
||||||
*/
|
*/
|
||||||
error = dsl_fs_ss_limit_check(ds->ds_dir, 1, ZFS_PROP_SNAPSHOT_LIMIT,
|
error = dsl_fs_ss_limit_check(ds->ds_dir, 1, ZFS_PROP_SNAPSHOT_LIMIT,
|
||||||
NULL, drba->drba_cred, drba->drba_proc);
|
NULL, drba->drba_cred);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
@ -750,16 +751,14 @@ dmu_recv_begin_check(void *arg, dmu_tx_t *tx)
|
|||||||
* filesystems and increment those counts during begin_sync).
|
* filesystems and increment those counts during begin_sync).
|
||||||
*/
|
*/
|
||||||
error = dsl_fs_ss_limit_check(ds->ds_dir, 1,
|
error = dsl_fs_ss_limit_check(ds->ds_dir, 1,
|
||||||
ZFS_PROP_FILESYSTEM_LIMIT, NULL,
|
ZFS_PROP_FILESYSTEM_LIMIT, NULL, drba->drba_cred);
|
||||||
drba->drba_cred, drba->drba_proc);
|
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dsl_dataset_rele(ds, FTAG);
|
dsl_dataset_rele(ds, FTAG);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
error = dsl_fs_ss_limit_check(ds->ds_dir, 1,
|
error = dsl_fs_ss_limit_check(ds->ds_dir, 1,
|
||||||
ZFS_PROP_SNAPSHOT_LIMIT, NULL,
|
ZFS_PROP_SNAPSHOT_LIMIT, NULL, drba->drba_cred);
|
||||||
drba->drba_cred, drba->drba_proc);
|
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dsl_dataset_rele(ds, FTAG);
|
dsl_dataset_rele(ds, FTAG);
|
||||||
return (error);
|
return (error);
|
||||||
@ -1265,6 +1264,9 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
dmu_recv_begin_arg_t drba = { 0 };
|
dmu_recv_begin_arg_t drba = { 0 };
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
memset(drc, 0, sizeof (dmu_recv_cookie_t));
|
memset(drc, 0, sizeof (dmu_recv_cookie_t));
|
||||||
drc->drc_drr_begin = drr_begin;
|
drc->drc_drr_begin = drr_begin;
|
||||||
drc->drc_drrb = &drr_begin->drr_u.drr_begin;
|
drc->drc_drrb = &drr_begin->drr_u.drr_begin;
|
||||||
@ -1273,8 +1275,7 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
drc->drc_force = force;
|
drc->drc_force = force;
|
||||||
drc->drc_heal = heal;
|
drc->drc_heal = heal;
|
||||||
drc->drc_resumable = resumable;
|
drc->drc_resumable = resumable;
|
||||||
drc->drc_cred = CRED();
|
drc->drc_cred = cr;
|
||||||
drc->drc_proc = curproc;
|
|
||||||
drc->drc_clone = (origin != NULL);
|
drc->drc_clone = (origin != NULL);
|
||||||
|
|
||||||
if (drc->drc_drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
|
if (drc->drc_drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
|
||||||
@ -1286,6 +1287,8 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
(void) fletcher_4_incremental_native(drr_begin,
|
(void) fletcher_4_incremental_native(drr_begin,
|
||||||
sizeof (dmu_replay_record_t), &drc->drc_cksum);
|
sizeof (dmu_replay_record_t), &drc->drc_cksum);
|
||||||
} else {
|
} else {
|
||||||
|
crfree(cr);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
return (SET_ERROR(EINVAL));
|
return (SET_ERROR(EINVAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,9 +1305,11 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
* upper limit. Systems with less than 1GB of RAM will see a lower
|
* upper limit. Systems with less than 1GB of RAM will see a lower
|
||||||
* limit from `arc_all_memory() / 4`.
|
* limit from `arc_all_memory() / 4`.
|
||||||
*/
|
*/
|
||||||
if (payloadlen > (MIN((1U << 28), arc_all_memory() / 4)))
|
if (payloadlen > (MIN((1U << 28), arc_all_memory() / 4))) {
|
||||||
return (E2BIG);
|
crfree(cr);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
|
return (SET_ERROR(E2BIG));
|
||||||
|
}
|
||||||
|
|
||||||
if (payloadlen != 0) {
|
if (payloadlen != 0) {
|
||||||
void *payload = vmem_alloc(payloadlen, KM_SLEEP);
|
void *payload = vmem_alloc(payloadlen, KM_SLEEP);
|
||||||
@ -1320,6 +1325,8 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
payload);
|
payload);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
vmem_free(payload, payloadlen);
|
vmem_free(payload, payloadlen);
|
||||||
|
crfree(cr);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
err = nvlist_unpack(payload, payloadlen, &drc->drc_begin_nvl,
|
err = nvlist_unpack(payload, payloadlen, &drc->drc_begin_nvl,
|
||||||
@ -1328,6 +1335,8 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
kmem_free(drc->drc_next_rrd,
|
kmem_free(drc->drc_next_rrd,
|
||||||
sizeof (*drc->drc_next_rrd));
|
sizeof (*drc->drc_next_rrd));
|
||||||
|
crfree(cr);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1337,8 +1346,7 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
|
|
||||||
drba.drba_origin = origin;
|
drba.drba_origin = origin;
|
||||||
drba.drba_cookie = drc;
|
drba.drba_cookie = drc;
|
||||||
drba.drba_cred = CRED();
|
drba.drba_cred = drc->drc_cred;
|
||||||
drba.drba_proc = curproc;
|
|
||||||
|
|
||||||
if (drc->drc_featureflags & DMU_BACKUP_FEATURE_RESUMING) {
|
if (drc->drc_featureflags & DMU_BACKUP_FEATURE_RESUMING) {
|
||||||
err = dsl_sync_task(tofs,
|
err = dsl_sync_task(tofs,
|
||||||
@ -1373,6 +1381,8 @@ dmu_recv_begin(const char *tofs, const char *tosnap,
|
|||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
kmem_free(drc->drc_next_rrd, sizeof (*drc->drc_next_rrd));
|
kmem_free(drc->drc_next_rrd, sizeof (*drc->drc_next_rrd));
|
||||||
nvlist_free(drc->drc_begin_nvl);
|
nvlist_free(drc->drc_begin_nvl);
|
||||||
|
crfree(cr);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
}
|
}
|
||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
@ -3527,6 +3537,8 @@ out:
|
|||||||
*/
|
*/
|
||||||
dmu_recv_cleanup_ds(drc);
|
dmu_recv_cleanup_ds(drc);
|
||||||
nvlist_free(drc->drc_keynvl);
|
nvlist_free(drc->drc_keynvl);
|
||||||
|
crfree(drc->drc_cred);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
objlist_destroy(drc->drc_ignore_objlist);
|
objlist_destroy(drc->drc_ignore_objlist);
|
||||||
@ -3601,8 +3613,7 @@ dmu_recv_end_check(void *arg, dmu_tx_t *tx)
|
|||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
error = dsl_dataset_snapshot_check_impl(origin_head,
|
error = dsl_dataset_snapshot_check_impl(origin_head,
|
||||||
drc->drc_tosnap, tx, B_TRUE, 1,
|
drc->drc_tosnap, tx, B_TRUE, 1, drc->drc_cred);
|
||||||
drc->drc_cred, drc->drc_proc);
|
|
||||||
dsl_dataset_rele(origin_head, FTAG);
|
dsl_dataset_rele(origin_head, FTAG);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
@ -3610,8 +3621,7 @@ dmu_recv_end_check(void *arg, dmu_tx_t *tx)
|
|||||||
error = dsl_destroy_head_check_impl(drc->drc_ds, 1);
|
error = dsl_destroy_head_check_impl(drc->drc_ds, 1);
|
||||||
} else {
|
} else {
|
||||||
error = dsl_dataset_snapshot_check_impl(drc->drc_ds,
|
error = dsl_dataset_snapshot_check_impl(drc->drc_ds,
|
||||||
drc->drc_tosnap, tx, B_TRUE, 1,
|
drc->drc_tosnap, tx, B_TRUE, 1, drc->drc_cred);
|
||||||
drc->drc_cred, drc->drc_proc);
|
|
||||||
}
|
}
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
@ -3823,6 +3833,10 @@ dmu_recv_end(dmu_recv_cookie_t *drc, void *owner)
|
|||||||
zvol_create_minor(snapname);
|
zvol_create_minor(snapname);
|
||||||
kmem_strfree(snapname);
|
kmem_strfree(snapname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crfree(drc->drc_cred);
|
||||||
|
drc->drc_cred = NULL;
|
||||||
|
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
* Copyright (c) 2019, Klara Inc.
|
* Copyright (c) 2019, Klara Inc.
|
||||||
* Copyright (c) 2019, Allan Jude
|
* Copyright (c) 2019, Allan Jude
|
||||||
* Copyright (c) 2020 The FreeBSD Foundation [1]
|
* Copyright (c) 2020 The FreeBSD Foundation [1]
|
||||||
|
* Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
|
||||||
*
|
*
|
||||||
* [1] Portions of this software were developed by Allan Jude
|
* [1] Portions of this software were developed by Allan Jude
|
||||||
* under sponsorship from the FreeBSD Foundation.
|
* under sponsorship from the FreeBSD Foundation.
|
||||||
@ -1518,7 +1519,7 @@ dsl_dataset_snapshot_reserve_space(dsl_dataset_t *ds, dmu_tx_t *tx)
|
|||||||
|
|
||||||
int
|
int
|
||||||
dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
|
dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
|
||||||
dmu_tx_t *tx, boolean_t recv, uint64_t cnt, cred_t *cr, proc_t *proc)
|
dmu_tx_t *tx, boolean_t recv, uint64_t cnt, cred_t *cr)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
@ -1563,7 +1564,7 @@ dsl_dataset_snapshot_check_impl(dsl_dataset_t *ds, const char *snapname,
|
|||||||
*/
|
*/
|
||||||
if (cnt != 0 && cr != NULL) {
|
if (cnt != 0 && cr != NULL) {
|
||||||
error = dsl_fs_ss_limit_check(ds->ds_dir, cnt,
|
error = dsl_fs_ss_limit_check(ds->ds_dir, cnt,
|
||||||
ZFS_PROP_SNAPSHOT_LIMIT, NULL, cr, proc);
|
ZFS_PROP_SNAPSHOT_LIMIT, NULL, cr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
@ -1664,7 +1665,7 @@ dsl_dataset_snapshot_check(void *arg, dmu_tx_t *tx)
|
|||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
error = dsl_fs_ss_limit_check(ds->ds_dir, cnt,
|
error = dsl_fs_ss_limit_check(ds->ds_dir, cnt,
|
||||||
ZFS_PROP_SNAPSHOT_LIMIT, NULL,
|
ZFS_PROP_SNAPSHOT_LIMIT, NULL,
|
||||||
ddsa->ddsa_cr, ddsa->ddsa_proc);
|
ddsa->ddsa_cr);
|
||||||
dsl_dataset_rele(ds, FTAG);
|
dsl_dataset_rele(ds, FTAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1702,7 +1703,7 @@ dsl_dataset_snapshot_check(void *arg, dmu_tx_t *tx)
|
|||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
/* passing 0/NULL skips dsl_fs_ss_limit_check */
|
/* passing 0/NULL skips dsl_fs_ss_limit_check */
|
||||||
error = dsl_dataset_snapshot_check_impl(ds,
|
error = dsl_dataset_snapshot_check_impl(ds,
|
||||||
atp + 1, tx, B_FALSE, 0, NULL, NULL);
|
atp + 1, tx, B_FALSE, 0, NULL);
|
||||||
dsl_dataset_rele(ds, FTAG);
|
dsl_dataset_rele(ds, FTAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1976,11 +1977,13 @@ dsl_dataset_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t *errors)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
ddsa.ddsa_snaps = snaps;
|
ddsa.ddsa_snaps = snaps;
|
||||||
ddsa.ddsa_props = props;
|
ddsa.ddsa_props = props;
|
||||||
ddsa.ddsa_errors = errors;
|
ddsa.ddsa_errors = errors;
|
||||||
ddsa.ddsa_cr = CRED();
|
ddsa.ddsa_cr = cr;
|
||||||
ddsa.ddsa_proc = curproc;
|
|
||||||
|
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
error = dsl_sync_task(firstname, dsl_dataset_snapshot_check,
|
error = dsl_sync_task(firstname, dsl_dataset_snapshot_check,
|
||||||
@ -1988,6 +1991,8 @@ dsl_dataset_snapshot(nvlist_t *snaps, nvlist_t *props, nvlist_t *errors)
|
|||||||
fnvlist_num_pairs(snaps) * 3, ZFS_SPACE_CHECK_NORMAL);
|
fnvlist_num_pairs(snaps) * 3, ZFS_SPACE_CHECK_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crfree(cr);
|
||||||
|
|
||||||
if (suspended != NULL) {
|
if (suspended != NULL) {
|
||||||
for (pair = nvlist_next_nvpair(suspended, NULL); pair != NULL;
|
for (pair = nvlist_next_nvpair(suspended, NULL); pair != NULL;
|
||||||
pair = nvlist_next_nvpair(suspended, pair)) {
|
pair = nvlist_next_nvpair(suspended, pair)) {
|
||||||
@ -2028,7 +2033,7 @@ dsl_dataset_snapshot_tmp_check(void *arg, dmu_tx_t *tx)
|
|||||||
|
|
||||||
/* NULL cred means no limit check for tmp snapshot */
|
/* NULL cred means no limit check for tmp snapshot */
|
||||||
error = dsl_dataset_snapshot_check_impl(ds, ddsta->ddsta_snapname,
|
error = dsl_dataset_snapshot_check_impl(ds, ddsta->ddsta_snapname,
|
||||||
tx, B_FALSE, 0, NULL, NULL);
|
tx, B_FALSE, 0, NULL);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dsl_dataset_rele(ds, FTAG);
|
dsl_dataset_rele(ds, FTAG);
|
||||||
return (error);
|
return (error);
|
||||||
@ -3496,7 +3501,7 @@ dsl_dataset_promote_check(void *arg, dmu_tx_t *tx)
|
|||||||
|
|
||||||
/* Check that there is enough space and limit headroom here */
|
/* Check that there is enough space and limit headroom here */
|
||||||
err = dsl_dir_transfer_possible(origin_ds->ds_dir, hds->ds_dir,
|
err = dsl_dir_transfer_possible(origin_ds->ds_dir, hds->ds_dir,
|
||||||
0, ss_mv_cnt, ddpa->used, ddpa->cr, ddpa->proc);
|
0, ss_mv_cnt, ddpa->used, ddpa->cr);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@ -3932,15 +3937,19 @@ dsl_dataset_promote(const char *name, char *conflsnap)
|
|||||||
if (error != 0)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
ddpa.ddpa_clonename = name;
|
ddpa.ddpa_clonename = name;
|
||||||
ddpa.err_ds = fnvlist_alloc();
|
ddpa.err_ds = fnvlist_alloc();
|
||||||
ddpa.cr = CRED();
|
ddpa.cr = cr;
|
||||||
ddpa.proc = curproc;
|
|
||||||
|
|
||||||
error = dsl_sync_task(name, dsl_dataset_promote_check,
|
error = dsl_sync_task(name, dsl_dataset_promote_check,
|
||||||
dsl_dataset_promote_sync, &ddpa,
|
dsl_dataset_promote_sync, &ddpa,
|
||||||
2 + numsnaps, ZFS_SPACE_CHECK_RESERVED);
|
2 + numsnaps, ZFS_SPACE_CHECK_RESERVED);
|
||||||
|
|
||||||
|
crfree(cr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the first conflicting snapshot found.
|
* Return the first conflicting snapshot found.
|
||||||
*/
|
*/
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
|
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
|
||||||
* Copyright (c) 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
|
* Copyright (c) 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
|
||||||
* Copyright (c) 2023 Hewlett Packard Enterprise Development LP.
|
* Copyright (c) 2023 Hewlett Packard Enterprise Development LP.
|
||||||
|
* Copyright (c) 2025, Rob Norris <robn@despairlabs.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/dmu.h>
|
#include <sys/dmu.h>
|
||||||
@ -759,7 +760,7 @@ typedef enum {
|
|||||||
|
|
||||||
static enforce_res_t
|
static enforce_res_t
|
||||||
dsl_enforce_ds_ss_limits(dsl_dir_t *dd, zfs_prop_t prop,
|
dsl_enforce_ds_ss_limits(dsl_dir_t *dd, zfs_prop_t prop,
|
||||||
cred_t *cr, proc_t *proc)
|
cred_t *cr)
|
||||||
{
|
{
|
||||||
enforce_res_t enforce = ENFORCE_ALWAYS;
|
enforce_res_t enforce = ENFORCE_ALWAYS;
|
||||||
uint64_t obj;
|
uint64_t obj;
|
||||||
@ -774,16 +775,8 @@ dsl_enforce_ds_ss_limits(dsl_dir_t *dd, zfs_prop_t prop,
|
|||||||
if (crgetzoneid(cr) != GLOBAL_ZONEID)
|
if (crgetzoneid(cr) != GLOBAL_ZONEID)
|
||||||
return (ENFORCE_ALWAYS);
|
return (ENFORCE_ALWAYS);
|
||||||
|
|
||||||
/*
|
if (secpolicy_zfs(cr) == 0)
|
||||||
* We are checking the saved credentials of the user process, which is
|
|
||||||
* not the current process. Note that we can't use secpolicy_zfs(),
|
|
||||||
* because it only works if the cred is that of the current process (on
|
|
||||||
* Linux).
|
|
||||||
*/
|
|
||||||
if (secpolicy_zfs_proc(cr, proc) == 0)
|
|
||||||
return (ENFORCE_NEVER);
|
return (ENFORCE_NEVER);
|
||||||
#else
|
|
||||||
(void) proc;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((obj = dsl_dir_phys(dd)->dd_head_dataset_obj) == 0)
|
if ((obj = dsl_dir_phys(dd)->dd_head_dataset_obj) == 0)
|
||||||
@ -817,7 +810,7 @@ dsl_enforce_ds_ss_limits(dsl_dir_t *dd, zfs_prop_t prop,
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
dsl_fs_ss_limit_check(dsl_dir_t *dd, uint64_t delta, zfs_prop_t prop,
|
dsl_fs_ss_limit_check(dsl_dir_t *dd, uint64_t delta, zfs_prop_t prop,
|
||||||
dsl_dir_t *ancestor, cred_t *cr, proc_t *proc)
|
dsl_dir_t *ancestor, cred_t *cr)
|
||||||
{
|
{
|
||||||
objset_t *os = dd->dd_pool->dp_meta_objset;
|
objset_t *os = dd->dd_pool->dp_meta_objset;
|
||||||
uint64_t limit, count;
|
uint64_t limit, count;
|
||||||
@ -849,7 +842,7 @@ dsl_fs_ss_limit_check(dsl_dir_t *dd, uint64_t delta, zfs_prop_t prop,
|
|||||||
* are allowed to change the limit on the current dataset, but there
|
* are allowed to change the limit on the current dataset, but there
|
||||||
* is another limit in the tree above.
|
* is another limit in the tree above.
|
||||||
*/
|
*/
|
||||||
enforce = dsl_enforce_ds_ss_limits(dd, prop, cr, proc);
|
enforce = dsl_enforce_ds_ss_limits(dd, prop, cr);
|
||||||
if (enforce == ENFORCE_NEVER)
|
if (enforce == ENFORCE_NEVER)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
@ -893,7 +886,7 @@ dsl_fs_ss_limit_check(dsl_dir_t *dd, uint64_t delta, zfs_prop_t prop,
|
|||||||
|
|
||||||
if (dd->dd_parent != NULL)
|
if (dd->dd_parent != NULL)
|
||||||
err = dsl_fs_ss_limit_check(dd->dd_parent, delta, prop,
|
err = dsl_fs_ss_limit_check(dd->dd_parent, delta, prop,
|
||||||
ancestor, cr, proc);
|
ancestor, cr);
|
||||||
|
|
||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
@ -1916,7 +1909,6 @@ typedef struct dsl_dir_rename_arg {
|
|||||||
const char *ddra_oldname;
|
const char *ddra_oldname;
|
||||||
const char *ddra_newname;
|
const char *ddra_newname;
|
||||||
cred_t *ddra_cred;
|
cred_t *ddra_cred;
|
||||||
proc_t *ddra_proc;
|
|
||||||
} dsl_dir_rename_arg_t;
|
} dsl_dir_rename_arg_t;
|
||||||
|
|
||||||
typedef struct dsl_valid_rename_arg {
|
typedef struct dsl_valid_rename_arg {
|
||||||
@ -2095,8 +2087,7 @@ dsl_dir_rename_check(void *arg, dmu_tx_t *tx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error = dsl_dir_transfer_possible(dd->dd_parent,
|
error = dsl_dir_transfer_possible(dd->dd_parent,
|
||||||
newparent, fs_cnt, ss_cnt, myspace,
|
newparent, fs_cnt, ss_cnt, myspace, ddra->ddra_cred);
|
||||||
ddra->ddra_cred, ddra->ddra_proc);
|
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
dsl_dir_rele(newparent, FTAG);
|
dsl_dir_rele(newparent, FTAG);
|
||||||
dsl_dir_rele(dd, FTAG);
|
dsl_dir_rele(dd, FTAG);
|
||||||
@ -2213,22 +2204,27 @@ dsl_dir_rename_sync(void *arg, dmu_tx_t *tx)
|
|||||||
int
|
int
|
||||||
dsl_dir_rename(const char *oldname, const char *newname)
|
dsl_dir_rename(const char *oldname, const char *newname)
|
||||||
{
|
{
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
dsl_dir_rename_arg_t ddra;
|
dsl_dir_rename_arg_t ddra;
|
||||||
|
|
||||||
ddra.ddra_oldname = oldname;
|
ddra.ddra_oldname = oldname;
|
||||||
ddra.ddra_newname = newname;
|
ddra.ddra_newname = newname;
|
||||||
ddra.ddra_cred = CRED();
|
ddra.ddra_cred = cr;
|
||||||
ddra.ddra_proc = curproc;
|
|
||||||
|
|
||||||
return (dsl_sync_task(oldname,
|
int err = dsl_sync_task(oldname,
|
||||||
dsl_dir_rename_check, dsl_dir_rename_sync, &ddra,
|
dsl_dir_rename_check, dsl_dir_rename_sync, &ddra,
|
||||||
3, ZFS_SPACE_CHECK_RESERVED));
|
3, ZFS_SPACE_CHECK_RESERVED);
|
||||||
|
|
||||||
|
crfree(cr);
|
||||||
|
return (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
|
dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
|
||||||
uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space,
|
uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space,
|
||||||
cred_t *cr, proc_t *proc)
|
cred_t *cr)
|
||||||
{
|
{
|
||||||
dsl_dir_t *ancestor;
|
dsl_dir_t *ancestor;
|
||||||
int64_t adelta;
|
int64_t adelta;
|
||||||
@ -2242,11 +2238,11 @@ dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
|
|||||||
return (SET_ERROR(ENOSPC));
|
return (SET_ERROR(ENOSPC));
|
||||||
|
|
||||||
err = dsl_fs_ss_limit_check(tdd, fs_cnt, ZFS_PROP_FILESYSTEM_LIMIT,
|
err = dsl_fs_ss_limit_check(tdd, fs_cnt, ZFS_PROP_FILESYSTEM_LIMIT,
|
||||||
ancestor, cr, proc);
|
ancestor, cr);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
return (err);
|
return (err);
|
||||||
err = dsl_fs_ss_limit_check(tdd, ss_cnt, ZFS_PROP_SNAPSHOT_LIMIT,
|
err = dsl_fs_ss_limit_check(tdd, ss_cnt, ZFS_PROP_SNAPSHOT_LIMIT,
|
||||||
ancestor, cr, proc);
|
ancestor, cr);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
return (err);
|
return (err);
|
||||||
|
|
||||||
|
@ -1141,12 +1141,14 @@ zcp_eval(const char *poolname, const char *program, boolean_t sync,
|
|||||||
}
|
}
|
||||||
VERIFY3U(3, ==, lua_gettop(state));
|
VERIFY3U(3, ==, lua_gettop(state));
|
||||||
|
|
||||||
|
cred_t *cr = CRED();
|
||||||
|
crhold(cr);
|
||||||
|
|
||||||
runinfo.zri_state = state;
|
runinfo.zri_state = state;
|
||||||
runinfo.zri_allocargs = &allocargs;
|
runinfo.zri_allocargs = &allocargs;
|
||||||
runinfo.zri_outnvl = outnvl;
|
runinfo.zri_outnvl = outnvl;
|
||||||
runinfo.zri_result = 0;
|
runinfo.zri_result = 0;
|
||||||
runinfo.zri_cred = CRED();
|
runinfo.zri_cred = cr;
|
||||||
runinfo.zri_proc = curproc;
|
|
||||||
runinfo.zri_timed_out = B_FALSE;
|
runinfo.zri_timed_out = B_FALSE;
|
||||||
runinfo.zri_canceled = B_FALSE;
|
runinfo.zri_canceled = B_FALSE;
|
||||||
runinfo.zri_sync = sync;
|
runinfo.zri_sync = sync;
|
||||||
@ -1165,6 +1167,8 @@ zcp_eval(const char *poolname, const char *program, boolean_t sync,
|
|||||||
}
|
}
|
||||||
lua_close(state);
|
lua_close(state);
|
||||||
|
|
||||||
|
crfree(cr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create device minor nodes for any new zvols.
|
* Create device minor nodes for any new zvols.
|
||||||
*/
|
*/
|
||||||
|
@ -193,7 +193,6 @@ zcp_synctask_promote(lua_State *state, boolean_t sync, nvlist_t *err_details)
|
|||||||
ddpa.ddpa_clonename = dsname;
|
ddpa.ddpa_clonename = dsname;
|
||||||
ddpa.err_ds = err_details;
|
ddpa.err_ds = err_details;
|
||||||
ddpa.cr = ri->zri_cred;
|
ddpa.cr = ri->zri_cred;
|
||||||
ddpa.proc = ri->zri_proc;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there was a snapshot name conflict, then err_ds will be filled
|
* If there was a snapshot name conflict, then err_ds will be filled
|
||||||
@ -277,7 +276,6 @@ zcp_synctask_snapshot(lua_State *state, boolean_t sync, nvlist_t *err_details)
|
|||||||
ddsa.ddsa_errors = NULL;
|
ddsa.ddsa_errors = NULL;
|
||||||
ddsa.ddsa_props = NULL;
|
ddsa.ddsa_props = NULL;
|
||||||
ddsa.ddsa_cr = ri->zri_cred;
|
ddsa.ddsa_cr = ri->zri_cred;
|
||||||
ddsa.ddsa_proc = ri->zri_proc;
|
|
||||||
ddsa.ddsa_snaps = fnvlist_alloc();
|
ddsa.ddsa_snaps = fnvlist_alloc();
|
||||||
fnvlist_add_boolean(ddsa.ddsa_snaps, dsname);
|
fnvlist_add_boolean(ddsa.ddsa_snaps, dsname);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user