zfs_fuid.h revision e0d35c4478bf9fd4080951b5b9d1f9a38948ba69
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
bda89588bd7667394a834e8a9a34612cce2ae9c3jp * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifndef _SYS_FS_ZFS_FUID_H
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define _SYS_FS_ZFS_FUID_H
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef _KERNEL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/kidmap.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/sid.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/dmu.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/zfs_vfsops.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marks#include <sys/avl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marks#ifdef __cplusplus
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marksextern "C" {
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marks#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef enum {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ZFS_OWNER,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ZFS_GROUP,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ZFS_ACE_USER,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ZFS_ACE_GROUP
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} zfs_fuid_type_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
4c841f6070b4f88f9dc008de526b313bbebd4e32marks/*
4c841f6070b4f88f9dc008de526b313bbebd4e32marks * Estimate space needed for one more fuid table entry.
4c841f6070b4f88f9dc008de526b313bbebd4e32marks * for now assume its current size + 1K
4c841f6070b4f88f9dc008de526b313bbebd4e32marks */
4c841f6070b4f88f9dc008de526b313bbebd4e32marks#define FUID_SIZE_ESTIMATE(z) (z->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define FUID_INDEX(x) (x >> 32)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define FUID_RID(x) (x & 0xffffffff)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define FUID_ENCODE(idx, rid) ((idx << 32) | rid)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FUIDs cause problems for the intent log
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * we need to replay the creation of the FUID,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * but we can't count on the idmapper to be around
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and during replay the FUID index may be different than
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * before. Also, if an ACL has 100 ACEs and 12 different
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domains we don't want to log 100 domain strings, but rather
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * just the unique 12.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The FUIDs in the log will index into
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domain string table and the bottom half will be the rid.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Used for mapping ephemeral uid/gid during ACL setting to FUIDs
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef struct zfs_fuid {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw list_node_t z_next;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t z_id; /* uid/gid being converted to fuid */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t z_domidx; /* index in AVL domain table */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t z_logfuid; /* index for domain in log */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} zfs_fuid_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* list of unique domains */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef struct zfs_fuid_domain {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw list_node_t z_next;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t z_domidx; /* AVL tree idx */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const char *z_domain; /* domain string */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} zfs_fuid_domain_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FUID information necessary for logging create, setattr, and setacl.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef struct zfs_fuid_info {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw list_t z_fuids;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw list_t z_domains;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t z_fuid_owner;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint64_t z_fuid_group;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char **z_domain_table; /* Used during replay */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t z_fuid_cnt; /* How many fuids in z_fuids */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t z_domain_cnt; /* How many domains */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t z_domain_str_sz; /* len of domain strings z_domain list */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} zfs_fuid_info_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef _KERNEL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstruct znode;
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marksextern uid_t zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern void zfs_fuid_destroy(zfsvfs_t *);
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marksextern uint64_t zfs_fuid_create_cred(zfsvfs_t *, zfs_fuid_type_t,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw dmu_tx_t *, cred_t *, zfs_fuid_info_t **);
bda89588bd7667394a834e8a9a34612cce2ae9c3jpextern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw dmu_tx_t *, zfs_fuid_info_t **);
bda89588bd7667394a834e8a9a34612cce2ae9c3jpextern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr, uid_t *uid,
bda89588bd7667394a834e8a9a34612cce2ae9c3jp uid_t *gid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern void zfs_fuid_info_free();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69markschar *zfs_fuid_idx_domain(avl_tree_t *, uint32_t);
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marksuint64_t zfs_fuid_table_load(objset_t *, uint64_t, avl_tree_t *, avl_tree_t *);
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marksvoid zfs_fuid_table_destroy(avl_tree_t *, avl_tree_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef __cplusplus
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif /* _SYS_FS_ZFS_FUID_H */