Whamcloud - gitweb
LU-1346 libcfs: replace libcfs wrappers with kernel API
[fs/lustre-release.git] / lustre / osd-zfs / udmu.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * Copyright (c) 2011, 2012 Whamcloud, Inc.
32  * Use is subject to license terms.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  *
38  * lustre/osd-zfs/udmu.h
39  *
40  * Author: Alex Tomas <alex@clusterfs.com>
41  * Author: Atul Vidwansa <atul.vidwansa@sun.com>
42  * Author: Manoj Joseph <manoj.joseph@sun.com>
43  */
44
45 #ifndef _DMU_H
46 #define _DMU_H
47
48 #include <sys/zap.h>
49 #include <sys/vnode.h>
50 #include <sys/mode.h>
51 #include <sys/sa.h>
52
53 #include <lustre/lustre_user.h>
54
55 typedef struct udmu_objset {
56         struct objset   *os;
57         uint64_t        root;  /* id of root znode */
58         spinlock_t      lock;  /* protects objects below */
59         uint64_t        objects; /* in-core counter of objects */
60         /* SA attr mapping->id,
61          * name is the same as in ZFS to use defines SA_ZPL_...*/
62         sa_attr_type_t *z_attr_table;
63 } udmu_objset_t;
64
65 #ifndef _SYS_TXG_H
66 #define TXG_WAIT        1ULL
67 #define TXG_NOWAIT      2ULL
68 #endif
69
70 #define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj)
71
72 /* Statfs space reservation for grant, fragmentation, and unlink space. */
73 #define OSD_STATFS_RESERVED_BLKS  (1ULL << (22 - SPA_MAXBLOCKSHIFT)) /* 4MB */
74 #define OSD_STATFS_RESERVED_SHIFT (7)         /* reserve 0.78% of all space */
75
76 /* Statfs {minimum, safe estimate, and maximum} dnodes per block */
77 #define OSD_DNODE_MIN_BLKSHIFT (SPA_MAXBLOCKSHIFT - DNODE_SHIFT) /* 17-9 =8 */
78 #define OSD_DNODE_EST_BLKSHIFT (SPA_MAXBLOCKSHIFT - 12)          /* 17-12=5 */
79 #define OSD_DNODE_EST_COUNT    1024
80
81 #define OSD_GRANT_FOR_LOCAL_OIDS (2ULL << 20) /* 2MB for last_rcvd, ... */
82
83 void udmu_init(void);
84 void udmu_fini(void);
85
86 /* udmu object-set API */
87 int udmu_objset_open(char *osname, udmu_objset_t *uos);
88 void udmu_objset_close(udmu_objset_t *uos);
89 int udmu_objset_statfs(udmu_objset_t *uos, struct obd_statfs *osfs);
90 uint64_t udmu_objset_user_iused(udmu_objset_t *uos, uint64_t uidbytes);
91 int udmu_objset_root(udmu_objset_t *uos, dmu_buf_t **dbp, void *tag);
92 uint64_t udmu_get_txg(udmu_objset_t *uos, dmu_tx_t *tx);
93 int udmu_blk_insert_cost(void);
94
95 /* buf must have at least MAXNAMELEN bytes */
96 void udmu_objset_name_get(udmu_objset_t *uos, char *buf);
97
98 /* get/set ZFS user properties */
99 int udmu_userprop_set_str(udmu_objset_t *uos, const char *prop_name,
100                           const char *val);
101 int udmu_userprop_get_str(udmu_objset_t *uos, const char *prop_name, char *buf,
102                           size_t buf_size);
103
104 /* zap cursor apis */
105 int udmu_zap_cursor_init(zap_cursor_t **zc, udmu_objset_t *uos,
106                 uint64_t zapobj, uint64_t hash);
107
108 void udmu_zap_cursor_fini(zap_cursor_t *zc);
109
110 void udmu_zap_cursor_advance(zap_cursor_t *zc);
111
112 uint64_t udmu_zap_cursor_serialize(zap_cursor_t *zc);
113
114 int udmu_zap_cursor_move_to_key(zap_cursor_t *zc, const char *name);
115
116 /* Commit callbacks */
117 int udmu_object_is_zap(dmu_buf_t *);
118
119 #endif /* _DMU_H */