Whamcloud - gitweb
LU-5456 hsm: hold inode mutex around ll_setattr_raw()
[fs/lustre-release.git] / libsysio / include / fs.h
1 /*
2  *    This Cplant(TM) source code is the property of Sandia National
3  *    Laboratories.
4  *
5  *    This Cplant(TM) source code is copyrighted by Sandia National
6  *    Laboratories.
7  *
8  *    The redistribution of this Cplant(TM) source code is subject to the
9  *    terms of the GNU Lesser General Public License
10  *    (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
11  *
12  *    Cplant(TM) Copyright 1998-2003 Sandia Corporation. 
13  *    Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14  *    license for use of this work by or on behalf of the US Government.
15  *    Export of this program may require a license from the United States
16  *    Government.
17  */
18
19 /*
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  * 
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  * 
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  * Questions or comments about this library should be sent to:
35  *
36  * Lee Ward
37  * Sandia National Laboratories, New Mexico
38  * P.O. Box 5800
39  * Albuquerque, NM 87185-1110
40  *
41  * lee@sandia.gov
42  */
43
44 /*
45  * File system or volume support.
46  */
47 #ifndef SYSIO_FS_H_
48 #define SYSIO_FS_H_
49
50 #include <sys/queue.h>
51
52 struct filesys;
53
54 struct pnode;
55 struct mount;
56
57 /*
58  * File system switch operations.
59  */
60 struct fssw_ops {
61         int     (*fsswop_mount)(const char *source,
62                                 unsigned flags,
63                                 const void *data,
64                                 struct pnode *tocover,
65                                 struct mount **mntp);
66 };
67
68 /*
69  * File system switch entry record.
70  *
71  * Each available file system or volume access driver is represented by
72  * one of these switch entries in the switch.
73  */
74 struct fsswent {
75         const char *fssw_name;                          /* entry name */
76         LIST_ENTRY(fsswent) fssw_link;                  /* link to next */
77         struct fssw_ops fssw_ops;                       /* operations */
78 };
79
80 /*
81  * Init file system switch entry record.
82  */
83 #define FSSWENT_INIT(fsswent, name, ops) \
84         do { \
85                 (fsswent)->fssw_name = (name); \
86                 (fsswent)->fssw_ops = (ops); \
87         } while (0)
88
89 struct inode;
90
91 /*
92  * File system operations.
93  */
94 struct filesys_ops {
95         void    (*fsop_gone)(struct filesys *);
96 };
97
98 /*
99  * Define the desired size of the file system record's inode table. This should
100  * probably be something fancy that tries to use up a system page, or the
101  * like. I'm not feeling adventurous right now though. It is prime though.
102  * That should help out the hash.
103  */
104 #ifndef FS_ITBLSIZ
105 #define FS_ITBLSIZ      503
106 #endif
107
108 /*
109  * Inode list head record.
110  */
111 LIST_HEAD(itable_entry, inode);
112
113 /*
114  * A filesys record is maintained for each active file system or volume.
115  */
116 struct filesys {
117         dev_t   fs_dev;                                 /* device ID */
118         unsigned fs_ref;                                /* soft ref count */
119         unsigned fs_flags;                              /* flags (see below) */
120         struct filesys_ops fs_ops;                      /* operations */
121         void    *fs_private;                            /* driver data */
122         struct itable_entry fs_itbl[FS_ITBLSIZ];        /* inodes hash */
123         unsigned long fs_id;                            /* ID */
124         size_t  fs_bsize;                               /* block size */
125 };
126
127 #define FS_F_RO                 0x01                    /* read-only */
128
129 /*
130  * Init file system record.
131  */
132 #define FS_INIT(fs, flags, ops, private) \
133         do { \
134                 size_t  __i; \
135                 struct itable_entry *__head; \
136  \
137                 (fs)->fs_ref = 1; \
138                 (fs)->fs_flags = (flags); \
139                 (fs)->fs_ops = *(ops); \
140                 (fs)->fs_private = (private); \
141                 __i = FS_ITBLSIZ; \
142                 __head = (fs)->fs_itbl; \
143                 do { \
144                         LIST_INIT(__head); \
145                         __head++; \
146                 } while (--__i); \
147         } while (0)
148
149 /*
150  * Reference file system record.
151  */
152 #define FS_REF(fs) \
153         do { \
154                 ++(fs)->fs_ref; \
155                 assert((fs)->fs_ref); \
156         } while (0)
157
158 /*
159  * Release reference to file system record.
160  */
161 #define FS_RELE(fs) \
162         do { \
163                 assert((fs)->fs_ref); \
164                 if (!--(fs)->fs_ref) \
165                         _sysio_fs_gone(fs); \
166         } while (0)
167
168 extern struct fsswent *_sysio_fssw_lookup(const char *name);
169 extern int _sysio_fssw_register(const char *name, struct fssw_ops *ops);
170 extern char *incore_dir_template;
171 extern struct filesys * _sysio_fs_new(struct filesys_ops *ops,
172                                       unsigned mask,
173                                       void *private);
174 extern void _sysio_fs_gone(struct filesys *fs);
175 #ifdef ZERO_SUM_MEMORY
176 extern void _sysio_fssw_shutdown(void);
177 #endif
178
179 #endif /* SYSIO_FS_H_ */