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/*
b38741657f2b4824e5595acf790b1d2eb9d761f0John Harres * Copyright 2010 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#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 */
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens#define FUID_SIZE_ESTIMATE(z) ((z)->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens#define FUID_INDEX(x) ((x) >> 32)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens#define FUID_RID(x) ((x) & 0xffffffff)
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens#define FUID_ENCODE(idx, rid) (((uint64_t)(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);
b38741657f2b4824e5595acf790b1d2eb9d761f0John Harresextern void zfs_fuid_node_add(zfs_fuid_info_t **, const char *, uint32_t,
b38741657f2b4824e5595acf790b1d2eb9d761f0John Harres uint64_t, uint64_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,
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum cred_t *, zfs_fuid_info_t **);
bda89588bd7667394a834e8a9a34612cce2ae9c3jpextern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum zfs_fuid_info_t **);
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaumextern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr,
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaum uid_t *uid, uid_t *gid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaumextern void zfs_fuid_info_free(zfs_fuid_info_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaumvoid zfs_fuid_sync(zfsvfs_t *, dmu_tx_t *);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensextern int zfs_fuid_find_by_domain(zfsvfs_t *, const char *domain,
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens char **retdomain, boolean_t addok);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensextern const char *zfs_fuid_find_by_idx(zfsvfs_t *zfsvfs, uint32_t idx);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrensextern void zfs_fuid_txhold(zfsvfs_t *zfsvfs, dmu_tx_t *tx);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69markschar *zfs_fuid_idx_domain(avl_tree_t *, uint32_t);
89459e17032b6bb1d59eebd2b7c0d06859d4657cMark Shellenbaumvoid zfs_fuid_avl_tree_create(avl_tree_t *, avl_tree_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 */