blob: 85f611fe05365f888cd5fb86aa462837a0f2ba52 [file] [log] [blame]
Mike Marshallf7ab0932015-07-17 10:38:11 -04001#include <linux/types.h>
Guenter Roeck81b784b2015-08-01 18:29:37 -07002#include <linux/spinlock_types.h>
Mike Marshallf7ab0932015-07-17 10:38:11 -04003#include <linux/slab.h>
Mike Marshall2c590d52015-07-24 10:37:15 -04004#include <linux/ioctl.h>
Mike Marshallf7ab0932015-07-17 10:38:11 -04005
6extern struct client_debug_mask *cdm_array;
7extern char *debug_help_string;
8extern int help_string_initialized;
9extern struct dentry *debug_dir;
10extern struct dentry *help_file_dentry;
11extern struct dentry *client_debug_dentry;
12extern const struct file_operations debug_help_fops;
13extern int client_all_index;
14extern int client_verbose_index;
15extern int cdm_element_count;
16#define DEBUG_HELP_STRING_SIZE 4096
17#define HELP_STRING_UNINITIALIZED \
18 "Client Debug Keywords are unknown until the first time\n" \
19 "the client is started after boot.\n"
20#define ORANGEFS_KMOD_DEBUG_HELP_FILE "debug-help"
21#define ORANGEFS_KMOD_DEBUG_FILE "kernel-debug"
22#define ORANGEFS_CLIENT_DEBUG_FILE "client-debug"
23#define PVFS2_VERBOSE "verbose"
24#define PVFS2_ALL "all"
25
26/* pvfs2-config.h ***********************************************************/
27#define PVFS2_VERSION_MAJOR 2
28#define PVFS2_VERSION_MINOR 9
29#define PVFS2_VERSION_SUB 0
30
31/* khandle stuff ***********************************************************/
32
33/*
34 * The 2.9 core will put 64 bit handles in here like this:
35 * 1234 0000 0000 5678
36 * The 3.0 and beyond cores will put 128 bit handles in here like this:
37 * 1234 5678 90AB CDEF
38 * The kernel module will always use the first four bytes and
39 * the last four bytes as an inum.
40 */
41struct pvfs2_khandle {
42 unsigned char u[16];
43} __aligned(8);
44
45/*
46 * kernel version of an object ref.
47 */
48struct pvfs2_object_kref {
49 struct pvfs2_khandle khandle;
50 __s32 fs_id;
51 __s32 __pad1;
52};
53
54/*
55 * compare 2 khandles assumes little endian thus from large address to
56 * small address
57 */
58static inline int PVFS_khandle_cmp(const struct pvfs2_khandle *kh1,
59 const struct pvfs2_khandle *kh2)
60{
61 int i;
62
63 for (i = 15; i >= 0; i--) {
64 if (kh1->u[i] > kh2->u[i])
65 return 1;
66 if (kh1->u[i] < kh2->u[i])
67 return -1;
68 }
69
70 return 0;
71}
72
Mike Marshallf7ab0932015-07-17 10:38:11 -040073static inline void PVFS_khandle_to(const struct pvfs2_khandle *kh,
74 void *p, int size)
75{
Mike Marshallf7ab0932015-07-17 10:38:11 -040076
77 memset(p, 0, size);
Mike Marshall50e01582015-09-29 11:17:26 -040078 memcpy(p, kh->u, 16);
Mike Marshallf7ab0932015-07-17 10:38:11 -040079
Mike Marshallf7ab0932015-07-17 10:38:11 -040080}
81
Mike Marshallf7ab0932015-07-17 10:38:11 -040082static inline void PVFS_khandle_from(struct pvfs2_khandle *kh,
83 void *p, int size)
84{
Mike Marshallf7ab0932015-07-17 10:38:11 -040085 memset(kh, 0, 16);
Mike Marshall50e01582015-09-29 11:17:26 -040086 memcpy(kh->u, p, 16);
Mike Marshallf7ab0932015-07-17 10:38:11 -040087
Mike Marshallf7ab0932015-07-17 10:38:11 -040088}
89
90/* pvfs2-types.h ************************************************************/
91typedef __u32 PVFS_uid;
92typedef __u32 PVFS_gid;
93typedef __s32 PVFS_fs_id;
94typedef __u32 PVFS_permissions;
95typedef __u64 PVFS_time;
96typedef __s64 PVFS_size;
97typedef __u64 PVFS_flags;
98typedef __u64 PVFS_ds_position;
99typedef __s32 PVFS_error;
100typedef __s64 PVFS_offset;
101
102#define PVFS2_SUPER_MAGIC 0x20030528
Martin Brandenburg894ac432015-10-02 12:11:19 -0400103
Mike Marshall54804942015-10-05 13:44:24 -0400104/*
105 * PVFS2 error codes are a signed 32-bit integer. Error codes are negative, but
106 * the sign is stripped before decoding.
107 */
Martin Brandenburg894ac432015-10-02 12:11:19 -0400108
109/* Bit 31 is not used since it is the sign. */
110
Mike Marshall54804942015-10-05 13:44:24 -0400111/*
112 * Bit 30 specifies that this is a PVFS2 error. A PVFS2 error is either an
113 * encoded errno value or a PVFS2 protocol error.
114 */
Martin Brandenburg894ac432015-10-02 12:11:19 -0400115#define PVFS_ERROR_BIT (1 << 30)
116
Mike Marshall54804942015-10-05 13:44:24 -0400117/*
118 * Bit 29 specifies that this is a PVFS2 protocol error and not an encoded
119 * errno value.
120 */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400121#define PVFS_NON_ERRNO_ERROR_BIT (1 << 29)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400122
Mike Marshall54804942015-10-05 13:44:24 -0400123/*
124 * Bits 9, 8, and 7 specify the error class, which encodes the section of
Martin Brandenburg894ac432015-10-02 12:11:19 -0400125 * server code the error originated in for logging purposes. It is not used
Mike Marshall54804942015-10-05 13:44:24 -0400126 * in the kernel except to be masked out.
127 */
Martin Brandenburg894ac432015-10-02 12:11:19 -0400128#define PVFS_ERROR_CLASS_BITS 0x380
Mike Marshallf7ab0932015-07-17 10:38:11 -0400129
Martin Brandenburg894ac432015-10-02 12:11:19 -0400130/* Bits 6 - 0 are reserved for the actual error code. */
131#define PVFS_ERROR_NUMBER_BITS 0x7f
Mike Marshallf7ab0932015-07-17 10:38:11 -0400132
Martin Brandenburg894ac432015-10-02 12:11:19 -0400133/* Encoded errno values are decoded by PINT_errno_mapping in pvfs2-utils.c. */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400134
Martin Brandenburg894ac432015-10-02 12:11:19 -0400135/* Our own PVFS2 protocol error codes. */
136#define PVFS_ECANCEL (1|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
137#define PVFS_EDEVINIT (2|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
138#define PVFS_EDETAIL (3|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
139#define PVFS_EHOSTNTFD (4|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
140#define PVFS_EADDRNTFD (5|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
141#define PVFS_ENORECVR (6|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
142#define PVFS_ETRYAGAIN (7|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
143#define PVFS_ENOTPVFS (8|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
144#define PVFS_ESECURITY (9|PVFS_NON_ERRNO_ERROR_BIT|PVFS_ERROR_BIT)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400145
146/* permission bits */
147#define PVFS_O_EXECUTE (1 << 0)
148#define PVFS_O_WRITE (1 << 1)
149#define PVFS_O_READ (1 << 2)
150#define PVFS_G_EXECUTE (1 << 3)
151#define PVFS_G_WRITE (1 << 4)
152#define PVFS_G_READ (1 << 5)
153#define PVFS_U_EXECUTE (1 << 6)
154#define PVFS_U_WRITE (1 << 7)
155#define PVFS_U_READ (1 << 8)
156/* no PVFS_U_VTX (sticky bit) */
157#define PVFS_G_SGID (1 << 10)
158#define PVFS_U_SUID (1 << 11)
159
160/* definition taken from stdint.h */
161#define INT32_MAX (2147483647)
162#define PVFS_ITERATE_START (INT32_MAX - 1)
163#define PVFS_ITERATE_END (INT32_MAX - 2)
Mike Marshall88309aa2015-09-23 16:48:40 -0400164#define PVFS_ITERATE_NEXT (INT32_MAX - 3)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400165#define PVFS_READDIR_START PVFS_ITERATE_START
166#define PVFS_READDIR_END PVFS_ITERATE_END
167#define PVFS_IMMUTABLE_FL FS_IMMUTABLE_FL
168#define PVFS_APPEND_FL FS_APPEND_FL
169#define PVFS_NOATIME_FL FS_NOATIME_FL
170#define PVFS_MIRROR_FL 0x01000000ULL
171#define PVFS_O_EXECUTE (1 << 0)
172#define PVFS_FS_ID_NULL ((__s32)0)
173#define PVFS_ATTR_SYS_UID (1 << 0)
174#define PVFS_ATTR_SYS_GID (1 << 1)
175#define PVFS_ATTR_SYS_PERM (1 << 2)
176#define PVFS_ATTR_SYS_ATIME (1 << 3)
177#define PVFS_ATTR_SYS_CTIME (1 << 4)
178#define PVFS_ATTR_SYS_MTIME (1 << 5)
179#define PVFS_ATTR_SYS_TYPE (1 << 6)
180#define PVFS_ATTR_SYS_ATIME_SET (1 << 7)
181#define PVFS_ATTR_SYS_MTIME_SET (1 << 8)
182#define PVFS_ATTR_SYS_SIZE (1 << 20)
183#define PVFS_ATTR_SYS_LNK_TARGET (1 << 24)
184#define PVFS_ATTR_SYS_DFILE_COUNT (1 << 25)
185#define PVFS_ATTR_SYS_DIRENT_COUNT (1 << 26)
186#define PVFS_ATTR_SYS_BLKSIZE (1 << 28)
187#define PVFS_ATTR_SYS_MIRROR_COPIES_COUNT (1 << 29)
188#define PVFS_ATTR_SYS_COMMON_ALL \
189 (PVFS_ATTR_SYS_UID | \
190 PVFS_ATTR_SYS_GID | \
191 PVFS_ATTR_SYS_PERM | \
192 PVFS_ATTR_SYS_ATIME | \
193 PVFS_ATTR_SYS_CTIME | \
194 PVFS_ATTR_SYS_MTIME | \
195 PVFS_ATTR_SYS_TYPE)
196
197#define PVFS_ATTR_SYS_ALL_SETABLE \
198(PVFS_ATTR_SYS_COMMON_ALL-PVFS_ATTR_SYS_TYPE)
199
200#define PVFS_ATTR_SYS_ALL_NOHINT \
201 (PVFS_ATTR_SYS_COMMON_ALL | \
202 PVFS_ATTR_SYS_SIZE | \
203 PVFS_ATTR_SYS_LNK_TARGET | \
204 PVFS_ATTR_SYS_DFILE_COUNT | \
205 PVFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
206 PVFS_ATTR_SYS_DIRENT_COUNT | \
207 PVFS_ATTR_SYS_BLKSIZE)
208#define PVFS_XATTR_REPLACE 0x2
209#define PVFS_XATTR_CREATE 0x1
210#define PVFS_MAX_SERVER_ADDR_LEN 256
211#define PVFS_NAME_MAX 256
212/*
213 * max extended attribute name len as imposed by the VFS and exploited for the
214 * upcall request types.
215 * NOTE: Please retain them as multiples of 8 even if you wish to change them
216 * This is *NECESSARY* for supporting 32 bit user-space binaries on a 64-bit
217 * kernel. Due to implementation within DBPF, this really needs to be
218 * PVFS_NAME_MAX, which it was the same value as, but no reason to let it
219 * break if that changes in the future.
220 */
221#define PVFS_MAX_XATTR_NAMELEN PVFS_NAME_MAX /* Not the same as
222 * XATTR_NAME_MAX defined
223 * by <linux/xattr.h>
224 */
225#define PVFS_MAX_XATTR_VALUELEN 8192 /* Not the same as XATTR_SIZE_MAX
226 * defined by <linux/xattr.h>
227 */
228#define PVFS_MAX_XATTR_LISTLEN 16 /* Not the same as XATTR_LIST_MAX
229 * defined by <linux/xattr.h>
230 */
231/*
232 * PVFS I/O operation types, used in both system and server interfaces.
233 */
234enum PVFS_io_type {
235 PVFS_IO_READ = 1,
236 PVFS_IO_WRITE = 2
237};
238
239/*
240 * If this enum is modified the server parameters related to the precreate pool
241 * batch and low threshold sizes may need to be modified to reflect this
242 * change.
243 */
244enum pvfs2_ds_type {
245 PVFS_TYPE_NONE = 0,
246 PVFS_TYPE_METAFILE = (1 << 0),
247 PVFS_TYPE_DATAFILE = (1 << 1),
248 PVFS_TYPE_DIRECTORY = (1 << 2),
249 PVFS_TYPE_SYMLINK = (1 << 3),
250 PVFS_TYPE_DIRDATA = (1 << 4),
251 PVFS_TYPE_INTERNAL = (1 << 5) /* for the server's private use */
252};
253
254/*
255 * PVFS_certificate simply stores a buffer with the buffer size.
256 * The buffer can be converted to an OpenSSL X509 struct for use.
257 */
258struct PVFS_certificate {
259 __u32 buf_size;
260 unsigned char *buf;
261};
262
263/*
264 * A credential identifies a user and is signed by the client/user
265 * private key.
266 */
267struct PVFS_credential {
268 __u32 userid; /* user id */
269 __u32 num_groups; /* length of group_array */
270 __u32 *group_array; /* groups for which the user is a member */
271 char *issuer; /* alias of the issuing server */
272 __u64 timeout; /* seconds after epoch to time out */
273 __u32 sig_size; /* length of the signature in bytes */
274 unsigned char *signature; /* digital signature */
275 struct PVFS_certificate certificate; /* user certificate buffer */
276};
277#define extra_size_PVFS_credential (PVFS_REQ_LIMIT_GROUPS * \
278 sizeof(__u32) + \
279 PVFS_REQ_LIMIT_ISSUER + \
280 PVFS_REQ_LIMIT_SIGNATURE + \
281 extra_size_PVFS_certificate)
282
283/* This structure is used by the VFS-client interaction alone */
284struct PVFS_keyval_pair {
285 char key[PVFS_MAX_XATTR_NAMELEN];
286 __s32 key_sz; /* __s32 for portable, fixed-size structures */
287 __s32 val_sz;
288 char val[PVFS_MAX_XATTR_VALUELEN];
289};
290
291/* pvfs2-sysint.h ***********************************************************/
292/* Describes attributes for a file, directory, or symlink. */
293struct PVFS_sys_attr_s {
294 __u32 owner;
295 __u32 group;
296 __u32 perms;
297 __u64 atime;
298 __u64 mtime;
299 __u64 ctime;
300 __s64 size;
301
302 /* NOTE: caller must free if valid */
303 char *link_target;
304
305 /* Changed to __s32 so that size of structure does not change */
306 __s32 dfile_count;
307
308 /* Changed to __s32 so that size of structure does not change */
309 __s32 distr_dir_servers_initial;
310
311 /* Changed to __s32 so that size of structure does not change */
312 __s32 distr_dir_servers_max;
313
314 /* Changed to __s32 so that size of structure does not change */
315 __s32 distr_dir_split_size;
316
317 __u32 mirror_copies_count;
318
319 /* NOTE: caller must free if valid */
320 char *dist_name;
321
322 /* NOTE: caller must free if valid */
323 char *dist_params;
324
325 __s64 dirent_count;
326 enum pvfs2_ds_type objtype;
327 __u64 flags;
328 __u32 mask;
329 __s64 blksize;
330};
331
332#define PVFS2_LOOKUP_LINK_NO_FOLLOW 0
333#define PVFS2_LOOKUP_LINK_FOLLOW 1
334
335/* pint-dev.h ***************************************************************/
336
337/* parameter structure used in PVFS_DEV_DEBUG ioctl command */
338struct dev_mask_info_s {
339 enum {
340 KERNEL_MASK,
341 CLIENT_MASK,
342 } mask_type;
343 __u64 mask_value;
344};
345
346struct dev_mask2_info_s {
347 __u64 mask1_value;
348 __u64 mask2_value;
349};
350
351/* pvfs2-util.h *************************************************************/
Mike Marshallf7ab0932015-07-17 10:38:11 -0400352__s32 PVFS_util_translate_mode(int mode);
353
354/* pvfs2-debug.h ************************************************************/
355#include "pvfs2-debug.h"
356
357/* pvfs2-internal.h *********************************************************/
358#define llu(x) (unsigned long long)(x)
359#define lld(x) (long long)(x)
360
361/* pint-dev-shared.h ********************************************************/
362#define PVFS_DEV_MAGIC 'k'
363
364#define PVFS2_READDIR_DEFAULT_DESC_COUNT 5
365
366#define DEV_GET_MAGIC 0x1
367#define DEV_GET_MAX_UPSIZE 0x2
368#define DEV_GET_MAX_DOWNSIZE 0x3
369#define DEV_MAP 0x4
370#define DEV_REMOUNT_ALL 0x5
371#define DEV_DEBUG 0x6
372#define DEV_UPSTREAM 0x7
373#define DEV_CLIENT_MASK 0x8
374#define DEV_CLIENT_STRING 0x9
375#define DEV_MAX_NR 0xa
376
377/* supported ioctls, codes are with respect to user-space */
378enum {
379 PVFS_DEV_GET_MAGIC = _IOW(PVFS_DEV_MAGIC, DEV_GET_MAGIC, __s32),
380 PVFS_DEV_GET_MAX_UPSIZE =
381 _IOW(PVFS_DEV_MAGIC, DEV_GET_MAX_UPSIZE, __s32),
382 PVFS_DEV_GET_MAX_DOWNSIZE =
383 _IOW(PVFS_DEV_MAGIC, DEV_GET_MAX_DOWNSIZE, __s32),
384 PVFS_DEV_MAP = _IO(PVFS_DEV_MAGIC, DEV_MAP),
385 PVFS_DEV_REMOUNT_ALL = _IO(PVFS_DEV_MAGIC, DEV_REMOUNT_ALL),
386 PVFS_DEV_DEBUG = _IOR(PVFS_DEV_MAGIC, DEV_DEBUG, __s32),
387 PVFS_DEV_UPSTREAM = _IOW(PVFS_DEV_MAGIC, DEV_UPSTREAM, int),
388 PVFS_DEV_CLIENT_MASK = _IOW(PVFS_DEV_MAGIC,
389 DEV_CLIENT_MASK,
390 struct dev_mask2_info_s),
391 PVFS_DEV_CLIENT_STRING = _IOW(PVFS_DEV_MAGIC,
392 DEV_CLIENT_STRING,
393 char *),
394 PVFS_DEV_MAXNR = DEV_MAX_NR,
395};
396
397/*
398 * version number for use in communicating between kernel space and user
Mike Marshall54804942015-10-05 13:44:24 -0400399 * space. Zero signifies the upstream version of the kernel module.
Mike Marshallf7ab0932015-07-17 10:38:11 -0400400 */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400401#define PVFS_KERNEL_PROTO_VERSION 0
402
403/*
404 * describes memory regions to map in the PVFS_DEV_MAP ioctl.
405 * NOTE: See devpvfs2-req.c for 32 bit compat structure.
406 * Since this structure has a variable-sized layout that is different
407 * on 32 and 64 bit platforms, we need to normalize to a 64 bit layout
408 * on such systems before servicing ioctl calls from user-space binaries
409 * that may be 32 bit!
410 */
411struct PVFS_dev_map_desc {
412 void *ptr;
413 __s32 total_size;
414 __s32 size;
415 __s32 count;
416};
417
418/* gossip.h *****************************************************************/
419
420#ifdef GOSSIP_DISABLE_DEBUG
421#define gossip_debug(mask, format, f...) do {} while (0)
422#else
423extern __u64 gossip_debug_mask;
424extern struct client_debug_mask client_debug_mask;
425
426/* try to avoid function call overhead by checking masks in macro */
427#define gossip_debug(mask, format, f...) \
428do { \
429 if (gossip_debug_mask & mask) \
430 printk(format, ##f); \
431} while (0)
432#endif /* GOSSIP_DISABLE_DEBUG */
433
434/* do file and line number printouts w/ the GNU preprocessor */
435#define gossip_ldebug(mask, format, f...) \
436 gossip_debug(mask, "%s: " format, __func__, ##f)
437
438#define gossip_err printk
439#define gossip_lerr(format, f...) \
440 gossip_err("%s line %d: " format, \
441 __FILE__, \
442 __LINE__, \
443 ##f)