Whamcloud - gitweb
LU-1934 ofd: implement precreate batching
[fs/lustre-release.git] / libsysio / include / sysio-cmn.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-2006 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  * System IO common information.
46  */
47
48 #if !defined(__IS_UNUSED) && defined(__GNUC__)
49 #define __IS_UNUSED     __attribute__ ((unused))
50 #else
51 #define __IS_UNUSED
52 #endif
53
54 /*
55  * Define internal file-offset type and it's maximum value.
56  */
57 #ifdef _LARGEFILE64_SOURCE
58 #define _SYSIO_OFF_T                    off64_t
59 #ifdef LLONG_MAX
60 #define _SYSIO_OFF_T_MAX                (LLONG_MAX)
61 #else
62 /*
63  * Don't have LLONG_MAX before C99. We'll need to define it ourselves.
64  */
65 #define _SYSIO_OFF_T_MAX                (9223372036854775807LL)
66 #endif
67 #else
68 #define _SYSIO_OFF_T                    off_t
69 #define _SYSIO_OFF_T_MAX                LONG_MAX
70 #endif
71
72 /*
73  * Internally, all file status is carried in the 64-bit capable
74  * structure.
75  */
76 #ifdef _LARGEFILE64_SOURCE
77 #define intnl_xtvec xtvec64
78 #else
79 #define intnl_xtvec xtvec
80 #endif
81 struct intnl_xtvec;
82
83 struct iovec;
84
85 /*
86  * Symbol composition.
87  */
88 #define _PREPEND_HELPER(p, x) \
89         p ## x
90 #define PREPEND(p, x) \
91         _PREPEND_HELPER(p, x)
92
93 /*
94  * SYSIO name label macros
95  */
96 #ifndef SYSIO_INTERFACE_NAME
97 #ifdef SYSIO_LABEL_NAMES
98 #define SYSIO_INTERFACE_NAME(x) \
99         PREPEND(SYSIO_LABEL_NAMES, x)
100 #else
101 #define SYSIO_INTERFACE_NAME(x) x
102 #endif /* SYSIO_LABEL_NAMES */
103 #endif /* !SYSIO_INTERFACE_NAME */
104
105 /* for debugging */
106 #if 0
107 #define ASSERT(cond)                                                    \
108         if (!(cond)) {                                                  \
109                 printf("ASSERTION(" #cond ") failed: " __FILE__ ":"     \
110                         __FUNCTION__ ":%d\n", __LINE__);                \
111                 abort();                                                \
112         }
113
114 #define ERROR(fmt, a...)                                                \
115         do {                                                            \
116                 printf("ERROR(" __FILE__ ":%d):" fmt, __LINE__, ##a);   \
117         while(0)
118
119 #else
120 #define ERROR(fmt)      do{}while(0)
121 #define ASSERT          do{}while(0)
122 #endif
123
124 /*
125  * SYSIO interface frame macros
126  *
127  * + DISPLAY_BLOCK; Allocates storage on the stack for use by the set of
128  *      macros.
129  * + ENTER; Performs entry point work
130  * + RETURN; Returns a value and performs exit point work
131  *
132  * NB: For RETURN, the arguments are the return value and value for errno.
133  * If the value for errno is non-zero then that value, *negated*, is set
134  * into errno.
135  */
136 #define SYSIO_INTERFACE_DISPLAY_BLOCK \
137         int _saved_errno;
138 #define SYSIO_INTERFACE_ENTER \
139         do { \
140                 _saved_errno = errno; \
141                 SYSIO_ENTER; \
142         } while (0)
143 #define SYSIO_INTERFACE_RETURN(rtn, err) \
144         do { \
145                 SYSIO_LEAVE; \
146                 errno = (err) ? -(err) : _saved_errno; \
147                 return (rtn); \
148         } while(0) 
149
150 /* Interface enter/leave hook functions  */
151 #ifdef SYSIO_TRACING
152 extern void *_sysio_entry_trace_q;
153 extern void *_sysio_exit_trace_q;
154
155 extern void *_sysio_register_trace(void *q,
156                                    void (*)(const char *file,
157                                             const char *func,
158                                             int line,
159                                             void *data),
160                                    void *data,
161                                    void (*destructor)(void *data));
162 extern void _sysio_remove_trace(void *q, void *p);
163 extern void _sysio_run_trace_q(void *q,
164                                const char *file,
165                                const char *func,
166                                int line);
167 #define SYSIO_ENTER                                                     \
168         do { \
169                 _sysio_run_trace_q(_sysio_entry_trace_q,                \
170                                    __FILE__, __func__, __LINE__);       \
171         } while (0)
172
173
174 #define SYSIO_LEAVE                                                     \
175         do { \
176                 _sysio_run_trace_q(_sysio_exit_trace_q,                 \
177                                    __FILE__, __func__, __LINE__);       \
178         } while (0)
179 #else
180 #define SYSIO_ENTER                                                     \
181         do { } while (0)
182 #define SYSIO_LEAVE                                                     \
183         do { } while (0)
184 #endif
185
186 /* Accounting for IO stats; Read and write character count. */
187 #if defined(REDSTORM)
188 #define _SYSIO_UPDACCT(w, cc) \
189         do { \
190                 if ((cc) < 0) \
191                         break; \
192                 if (w) \
193                         _add_iostats(0, (size_t )(cc)); \
194                 else \
195                         _add_iostats((size_t )(cc), 0); \
196         } while(0)
197 #else
198 #define _SYSIO_UPDACCT(w, cc)
199 #endif
200
201 extern ssize_t _sysio_validx(const struct intnl_xtvec *xtv, size_t xtvlen,
202                              const struct iovec *iov, size_t iovlen,
203                              _SYSIO_OFF_T limit);
204 extern ssize_t _sysio_enumerate_extents(const struct intnl_xtvec *xtv,
205                                         size_t xtvlen,
206                                         const struct iovec *iov,
207                                         size_t iovlen,
208                                         ssize_t (*f)(const struct iovec *,
209                                                      int,
210                                                      _SYSIO_OFF_T,
211                                                      ssize_t,
212                                                      void *),
213                                         void *arg);
214 extern ssize_t _sysio_enumerate_iovec(const struct iovec *iov,
215                                       size_t count,
216                                       _SYSIO_OFF_T off,
217                                       ssize_t limit,
218                                       ssize_t (*f)(void *,
219                                                    size_t,
220                                                    _SYSIO_OFF_T,
221                                                    void *),
222                                       void *arg);
223 extern ssize_t _sysio_doio(const struct intnl_xtvec *xtv, size_t xtvlen,
224                            const struct iovec *iov, size_t iovlen,
225                            ssize_t (*f)(void *, size_t, _SYSIO_OFF_T, void *),
226                            void *arg);