xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zfs_fuid.h (revision d321a33cdd896e6b211d113a33698dd76e89b861)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_FS_ZFS_FUID_H
27 #define	_SYS_FS_ZFS_FUID_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/isa_defs.h>
32 #include <sys/types32.h>
33 #ifdef _KERNEL
34 #include <sys/kidmap.h>
35 #include <sys/sid.h>
36 #include <sys/dmu.h>
37 #include <sys/zfs_vfsops.h>
38 #endif
39 
40 #ifdef _KERNEL
41 typedef struct zfs_fuid_hdl {
42 	idmap_get_handle_t	*z_hdl;
43 	boolean_t		z_map_needed; /* is mapping required */
44 	idmap_stat		z_status; /* needed for kidmap interface */
45 } zfs_fuid_hdl_t;
46 
47 typedef enum {
48 	ZFS_OWNER,
49 	ZFS_GROUP,
50 	ZFS_ACE_USER,
51 	ZFS_ACE_GROUP
52 } zfs_fuid_type_t;
53 
54 #endif
55 
56 /*
57  * Estimate space needed for one more fuid table entry.
58  * for now assume its current size + 1K
59  */
60 #define	FUID_SIZE_ESTIMATE(z) (z->z_fuid_size + (SPA_MINBLOCKSIZE << 1))
61 
62 #define	FUID_INDEX(x)	(x >> 32)
63 #define	FUID_RID(x)	(x & 0xffffffff)
64 #define	FUID_ENCODE(idx, rid) ((idx << 32) | rid)
65 /*
66  * FUIDs cause problems for the intent log
67  * we need to replay the creation of the FUID,
68  * but we can't count on the idmapper to be around
69  * and during replay the FUID index may be different than
70  * before.  Also, if an ACL has 100 ACEs and 12 different
71  * domains we don't want to log 100 domain strings, but rather
72  * just the unique 12.
73  */
74 
75 /*
76  * The FUIDs in the log will index into
77  * domain string table and the bottom half will be the rid.
78  * Used for mapping ephemeral uid/gid during ACL setting to FUIDs
79  */
80 typedef struct zfs_fuid {
81 	list_node_t 	z_next;
82 	uint64_t 	z_id;		/* uid/gid being converted to fuid */
83 	uint64_t	z_domidx;	/* index in AVL domain table */
84 	uint64_t	z_logfuid;	/* index for domain in log */
85 } zfs_fuid_t;
86 
87 /* list of unique domains */
88 typedef struct zfs_fuid_domain {
89 	list_node_t	z_next;
90 	uint64_t	z_domidx;	/* AVL tree idx */
91 	const char	*z_domain;	/* domain string */
92 } zfs_fuid_domain_t;
93 
94 /*
95  * FUID information necessary for logging create, setattr, and setacl.
96  */
97 typedef struct zfs_fuid_info {
98 	list_t	z_fuids;
99 	list_t	z_domains;
100 	uint64_t z_fuid_owner;
101 	uint64_t z_fuid_group;
102 	char **z_domain_table;  /* Used during replay */
103 	uint32_t z_fuid_cnt;	/* How many fuids in z_fuids */
104 	uint32_t z_domain_cnt;	/* How many domains */
105 	size_t	z_domain_str_sz; /* len of domain strings z_domain list */
106 } zfs_fuid_info_t;
107 
108 #ifdef _KERNEL
109 struct znode;
110 extern void zfs_fuid_map_id(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
111     uid_t *);
112 extern void zfs_fuid_destroy(zfsvfs_t *);
113 extern uint64_t zfs_fuid_create_cred(zfsvfs_t *, uint64_t, zfs_fuid_type_t,
114     dmu_tx_t *, cred_t *, zfs_fuid_info_t **);
115 extern uint64_t zfs_fuid_create(zfsvfs_t *, uint64_t, cred_t *, zfs_fuid_type_t,
116     dmu_tx_t *, zfs_fuid_info_t **);
117 extern void zfs_fuid_queue_map_id(zfsvfs_t *zfsvfs, zfs_fuid_hdl_t *,
118     uint64_t, cred_t *, zfs_fuid_type_t, uid_t *);
119 extern void zfs_fuid_map_ids(struct znode *zp, cred_t *cr, uid_t *uid,
120     uid_t *gid);
121 extern void zfs_fuid_get_mappings(zfs_fuid_hdl_t *);
122 extern char *zfs_fuid_find_by_idx(zfsvfs_t *, uint64_t);
123 int zfs_fuid_find_by_domain(zfsvfs_t *, const char *, char **, dmu_tx_t *);
124 extern zfs_fuid_info_t *zfs_fuid_info_alloc(void);
125 extern void zfs_fuid_info_free();
126 extern boolean_t zfs_groupmember(zfsvfs_t *, uint64_t, cred_t *);
127 
128 #endif
129 
130 #ifdef	__cplusplus
131 extern "C" {
132 #endif
133 
134 #ifdef	__cplusplus
135 }
136 #endif
137 
138 #endif	/* _SYS_FS_ZFS_FUID_H */
139