0d5773b0b3d91a364b3a2be0a8e2af3bcb21f0d3
[zfs.git] / zfs / lib / libudmu / include / udmu.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2006 Cluster File Systems, Inc.
5  *   Author: Alex Tomas <alex@clusterfs.com>
6  *   Author: Atul Vidwansa <atul.vidwansa@sun.com>
7  *   Author: Manoj Joseph <manoj.joseph@sun.com>
8  *
9  *   This file is part of the Lustre file system, http://www.lustre.org
10  *   Lustre is a trademark of Cluster File Systems, Inc.
11  *
12  *   You may have signed or agreed to another license before downloading
13  *   this software.  If so, you are bound by the terms and conditions
14  *   of that agreement, and the following does not apply to you.  See the
15  *   LICENSE file included with this distribution for more information.
16  *
17  *   If you did not agree to a different license, then this copy of Lustre
18  *   is open source software; you can redistribute it and/or modify it
19  *   under the terms of version 2 of the GNU General Public License as
20  *   published by the Free Software Foundation.
21  *
22  *   In either case, Lustre is distributed in the hope that it will be
23  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  *   license text for more details.
26  */
27
28 #ifndef _DMU_H
29 #define _DMU_H
30
31 #ifdef  __cplusplus
32 extern "C" {
33 #endif
34
35 #include <stdint.h>
36
37 #define LUSTRE_ZPL_VERSION 1ULL
38
39 #ifndef AT_TYPE
40 #define AT_TYPE    0x0001
41 #define AT_MODE    0x0002
42 #define AT_UID     0x0004
43 #define AT_GID     0x0008
44 #define AT_FSID    0x0010
45 #define AT_NODEID  0x0020
46 #define AT_NLINK   0x0040
47 #define AT_SIZE    0x0080
48 #define AT_ATIME   0x0100
49 #define AT_MTIME   0x0200
50 #define AT_CTIME   0x0400
51 #define AT_RDEV    0x0800
52 #define AT_BLKSIZE 0x1000
53 #define AT_NBLOCKS 0x2000
54 #define AT_SEQ     0x8000
55 #endif
56
57 #define ACCESSED                (AT_ATIME)
58 #define STATE_CHANGED           (AT_CTIME)
59 #define CONTENT_MODIFIED        (AT_MTIME | AT_CTIME)
60
61 #define LOOKUP_DIR              0x01    /* want parent dir vp */
62 #define LOOKUP_XATTR            0x02    /* lookup up extended attr dir */
63 #define CREATE_XATTR_DIR        0x04    /* Create extended attr dir */
64
65 #define S_IFDOOR        0xD000  /* door */
66 #define S_IFPORT        0xE000  /* event port */
67
68 struct statvfs64;
69
70 /* Data structures required for Solaris ZFS compatability */
71 #if !defined(__sun__)
72
73 #ifndef _SOL_SYS_TIME_H
74 typedef struct timespec timestruc_t;
75 #endif
76
77 #endif
78
79 typedef enum vtype {
80         VNON    = 0,
81         VREG    = 1,
82         VDIR    = 2,
83         VBLK    = 3,
84         VCHR    = 4,
85         VLNK    = 5,
86         VFIFO   = 6,
87         VDOOR   = 7,
88         VPROC   = 8,
89         VSOCK   = 9,
90         VPORT   = 10,
91         VBAD    = 11
92 } vtype_t;
93
94 typedef struct vnattr {
95         unsigned int    va_mask;        /* bit-mask of attributes */
96         vtype_t         va_type;        /* vnode type (for create) */
97         mode_t          va_mode;        /* file access mode */
98         uid_t           va_uid;         /* owner user id */
99         gid_t           va_gid;         /* owner group id */
100         dev_t           va_fsid;        /* file system id (dev for now) */
101         unsigned long long va_nodeid;   /* node id */
102         nlink_t         va_nlink;       /* number of references to file */
103         off_t           va_size;        /* file size in bytes */
104         timestruc_t     va_atime;       /* time of last access */
105         timestruc_t     va_mtime;       /* time of last modification */
106         timestruc_t     va_ctime;       /* time of last status change */
107         dev_t           va_rdev;        /* device the file represents */
108         unsigned int    va_blksize;     /* fundamental block size */
109         unsigned int    va_blkbits;
110         unsigned long long va_nblocks;  /* # of blocks allocated */
111         unsigned int    va_seq;         /* sequence number */
112 } vnattr_t;
113
114 typedef struct udmu_objset {
115         struct objset *os;
116         struct zilog *zilog;
117         uint64_t root;  /* id of root znode */
118         uint64_t unlinkedobj;
119 } udmu_objset_t;
120
121
122 /* definitions from dmu.h */
123 #ifndef _SYS_DMU_H
124
125 typedef struct objset objset_t;
126 typedef struct dmu_tx dmu_tx_t;
127 typedef struct dmu_buf dmu_buf_t;
128
129 #define DMU_NEW_OBJECT  (-1ULL)
130 #define DMU_OBJECT_END  (-1ULL)
131
132 #endif
133
134 #ifndef _SYS_TXG_H
135 #define TXG_WAIT        1ULL
136 #define TXG_NOWAIT      2ULL
137 #endif
138
139 #define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj)
140
141 #define FTAG ((char *)__func__)
142
143 void udmu_init();
144
145 void udmu_fini();
146
147 void udmu_debug(int level);
148
149 /* udmu object-set API */
150
151 int udmu_objset_open(char *osname, char *import_dir, int import, int force, udmu_objset_t *uos);
152
153 void udmu_objset_close(udmu_objset_t *uos, int export_pool);
154
155 int udmu_objset_statvfs(udmu_objset_t *uos, struct statvfs64 *statp);
156
157 int udmu_objset_root(udmu_objset_t *uos, dmu_buf_t **dbp, void *tag);
158
159 void udmu_wait_synced(udmu_objset_t *uos, dmu_tx_t *tx);
160
161 /* udmu ZAP API */
162
163 int udmu_zap_lookup(udmu_objset_t *uos, dmu_buf_t *zap_db, const char *name,
164                     void *value, int value_size, int intsize);
165
166 void udmu_zap_create(udmu_objset_t *uos, dmu_buf_t **zap_dbp, dmu_tx_t *tx, void *tag);
167
168 int udmu_zap_insert(udmu_objset_t *uos, dmu_buf_t *zap_db, dmu_tx_t *tx,
169                     const char *name, void *value, int len);
170
171 int udmu_zap_delete(udmu_objset_t *uos, dmu_buf_t *zap_db, dmu_tx_t *tx,
172                     const char *name);
173
174 /* udmu object API */
175
176 void udmu_object_create(udmu_objset_t *uos, dmu_buf_t **dbp, dmu_tx_t *tx, void *tag);
177
178 int udmu_object_get_dmu_buf(udmu_objset_t *uos, uint64_t object,
179                             dmu_buf_t **dbp, void *tag);
180
181 void udmu_object_put_dmu_buf(dmu_buf_t *db, void *tag);
182
183 uint64_t udmu_object_get_id(dmu_buf_t *db);
184
185 int udmu_object_read(udmu_objset_t *uos, dmu_buf_t *db, uint64_t offset,
186                      uint64_t size, void *buf);
187
188 void udmu_object_write(udmu_objset_t *uos, dmu_buf_t *db, struct dmu_tx *tx,
189                       uint64_t offset, uint64_t size, void *buf);
190
191 void udmu_object_getattr(dmu_buf_t *db, vnattr_t *vap);
192
193 void udmu_object_setattr(dmu_buf_t *db, dmu_tx_t *tx, vnattr_t *vap);
194
195 void udmu_object_punch(udmu_objset_t *uos, dmu_buf_t *db, dmu_tx_t *tx,
196                       uint64_t offset, uint64_t len);
197
198 int udmu_object_delete(udmu_objset_t *uos, dmu_buf_t **db, dmu_tx_t *tx, void *tag);
199
200 /*udmu transaction API */
201
202 dmu_tx_t *udmu_tx_create(udmu_objset_t *uos);
203
204 void udmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len);
205
206 void udmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off,
207     uint64_t len);
208
209 void udmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, char *name);
210
211 void udmu_tx_hold_bonus(dmu_tx_t *tx, uint64_t object);
212
213 void udmu_tx_abort(dmu_tx_t *tx);
214
215 int udmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how);
216
217 void udmu_tx_wait(dmu_tx_t *tx);
218
219 int udmu_indblk_overhead(dmu_buf_t *db, unsigned long *used,
220                          unsigned long *overhead);
221
222 void udmu_tx_commit(dmu_tx_t *tx);
223
224 void * udmu_tx_cb_create(size_t bytes);
225
226 int udmu_tx_cb_add(dmu_tx_t *tx, void *func, void *data);
227
228 int udmu_tx_cb_destroy(void *data);
229
230 int udmu_object_is_zap(dmu_buf_t *);
231
232 int udmu_indblk_overhead(dmu_buf_t *db, unsigned long *used, unsigned 
233                                 long *overhead);
234
235 int udmu_get_blocksize(dmu_buf_t *db, long *blksz);
236
237 #ifdef  __cplusplus
238 }
239 #endif
240
241 #endif /* _DMU_H */