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