blob: 33fcf3bccd2e925eded767336cb0d5485bf1aeaf [file] [log] [blame]
Mike Marshallf7ab0932015-07-17 10:38:11 -04001/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7/*
Yi Liu8bb8aef2015-11-24 15:12:14 -05008 * The ORANGEFS Linux kernel support allows ORANGEFS volumes to be mounted and
Mike Marshallf7ab0932015-07-17 10:38:11 -04009 * accessed through the Linux VFS (i.e. using standard I/O system calls).
10 * This support is only needed on clients that wish to mount the file system.
11 *
12 */
13
14/*
Yi Liu8bb8aef2015-11-24 15:12:14 -050015 * Declarations and macros for the ORANGEFS Linux kernel support.
Mike Marshallf7ab0932015-07-17 10:38:11 -040016 */
17
Yi Liu8bb8aef2015-11-24 15:12:14 -050018#ifndef __ORANGEFSKERNEL_H
19#define __ORANGEFSKERNEL_H
Mike Marshallf7ab0932015-07-17 10:38:11 -040020
21#include <linux/kernel.h>
22#include <linux/moduleparam.h>
23#include <linux/statfs.h>
24#include <linux/backing-dev.h>
25#include <linux/device.h>
26#include <linux/mpage.h>
27#include <linux/namei.h>
28#include <linux/errno.h>
29#include <linux/init.h>
30#include <linux/module.h>
31#include <linux/slab.h>
32#include <linux/types.h>
33#include <linux/fs.h>
34#include <linux/vmalloc.h>
35
36#include <linux/aio.h>
37#include <linux/posix_acl.h>
38#include <linux/posix_acl_xattr.h>
39#include <linux/compat.h>
40#include <linux/mount.h>
41#include <linux/uaccess.h>
42#include <linux/atomic.h>
43#include <linux/uio.h>
44#include <linux/sched.h>
45#include <linux/mm.h>
46#include <linux/wait.h>
47#include <linux/dcache.h>
48#include <linux/pagemap.h>
49#include <linux/poll.h>
50#include <linux/rwsem.h>
51#include <linux/xattr.h>
52#include <linux/exportfs.h>
53
54#include <asm/unaligned.h>
55
56#include "pvfs2-dev-proto.h"
57
Yi Liu8bb8aef2015-11-24 15:12:14 -050058#ifdef ORANGEFS_KERNEL_DEBUG
59#define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 10
Mike Marshallf7ab0932015-07-17 10:38:11 -040060#else
Yi Liu8bb8aef2015-11-24 15:12:14 -050061#define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 20
Mike Marshallf7ab0932015-07-17 10:38:11 -040062#endif
63
Yi Liu8bb8aef2015-11-24 15:12:14 -050064#define ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS 30
Mike Marshallf7ab0932015-07-17 10:38:11 -040065
Yi Liu8bb8aef2015-11-24 15:12:14 -050066#define ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS 900 /* 15 minutes */
Mike Marshallf7ab0932015-07-17 10:38:11 -040067
Yi Liu8bb8aef2015-11-24 15:12:14 -050068#define ORANGEFS_REQDEVICE_NAME "pvfs2-req"
Mike Marshallf7ab0932015-07-17 10:38:11 -040069
Yi Liu8bb8aef2015-11-24 15:12:14 -050070#define ORANGEFS_DEVREQ_MAGIC 0x20030529
71#define ORANGEFS_LINK_MAX 0x000000FF
72#define ORANGEFS_PURGE_RETRY_COUNT 0x00000005
73#define ORANGEFS_SEEK_END 0x00000002
74#define ORANGEFS_MAX_NUM_OPTIONS 0x00000004
75#define ORANGEFS_MAX_MOUNT_OPT_LEN 0x00000080
76#define ORANGEFS_MAX_FSKEY_LEN 64
Mike Marshallf7ab0932015-07-17 10:38:11 -040077
78#define MAX_DEV_REQ_UPSIZE (2*sizeof(__s32) + \
Yi Liu8bb8aef2015-11-24 15:12:14 -050079sizeof(__u64) + sizeof(struct orangefs_upcall_s))
Mike Marshallf7ab0932015-07-17 10:38:11 -040080#define MAX_DEV_REQ_DOWNSIZE (2*sizeof(__s32) + \
Yi Liu8bb8aef2015-11-24 15:12:14 -050081sizeof(__u64) + sizeof(struct orangefs_downcall_s))
Mike Marshallf7ab0932015-07-17 10:38:11 -040082
83#define BITS_PER_LONG_DIV_8 (BITS_PER_LONG >> 3)
84
85/* borrowed from irda.h */
86#ifndef MSECS_TO_JIFFIES
87#define MSECS_TO_JIFFIES(ms) (((ms)*HZ+999)/1000)
88#endif
89
90#define MAX_ALIGNED_DEV_REQ_UPSIZE \
91 (MAX_DEV_REQ_UPSIZE + \
92 ((((MAX_DEV_REQ_UPSIZE / \
93 (BITS_PER_LONG_DIV_8)) * \
94 (BITS_PER_LONG_DIV_8)) + \
95 (BITS_PER_LONG_DIV_8)) - \
96 MAX_DEV_REQ_UPSIZE))
97
98#define MAX_ALIGNED_DEV_REQ_DOWNSIZE \
99 (MAX_DEV_REQ_DOWNSIZE + \
100 ((((MAX_DEV_REQ_DOWNSIZE / \
101 (BITS_PER_LONG_DIV_8)) * \
102 (BITS_PER_LONG_DIV_8)) + \
103 (BITS_PER_LONG_DIV_8)) - \
104 MAX_DEV_REQ_DOWNSIZE))
105
106/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500107 * valid orangefs kernel operation states
Mike Marshallf7ab0932015-07-17 10:38:11 -0400108 *
109 * unknown - op was just initialized
110 * waiting - op is on request_list (upward bound)
111 * inprogr - op is in progress (waiting for downcall)
112 * serviced - op has matching downcall; ok
113 * purged - op has to start a timer since client-core
114 * exited uncleanly before servicing op
115 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500116enum orangefs_vfs_op_states {
Mike Marshallf7ab0932015-07-17 10:38:11 -0400117 OP_VFS_STATE_UNKNOWN = 0,
118 OP_VFS_STATE_WAITING = 1,
119 OP_VFS_STATE_INPROGR = 2,
120 OP_VFS_STATE_SERVICED = 4,
121 OP_VFS_STATE_PURGED = 8,
122};
123
124#define set_op_state_waiting(op) ((op)->op_state = OP_VFS_STATE_WAITING)
125#define set_op_state_inprogress(op) ((op)->op_state = OP_VFS_STATE_INPROGR)
126#define set_op_state_serviced(op) ((op)->op_state = OP_VFS_STATE_SERVICED)
127#define set_op_state_purged(op) ((op)->op_state |= OP_VFS_STATE_PURGED)
128
129#define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING)
130#define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
131#define op_state_serviced(op) ((op)->op_state & OP_VFS_STATE_SERVICED)
132#define op_state_purged(op) ((op)->op_state & OP_VFS_STATE_PURGED)
133
134#define get_op(op) \
135 do { \
136 atomic_inc(&(op)->aio_ref_count); \
137 gossip_debug(GOSSIP_DEV_DEBUG, \
138 "(get) Alloced OP (%p:%llu)\n", \
139 op, \
140 llu((op)->tag)); \
141 } while (0)
142
143#define put_op(op) \
144 do { \
145 if (atomic_sub_and_test(1, &(op)->aio_ref_count) == 1) { \
146 gossip_debug(GOSSIP_DEV_DEBUG, \
147 "(put) Releasing OP (%p:%llu)\n", \
148 op, \
149 llu((op)->tag)); \
150 op_release(op); \
151 } \
152 } while (0)
153
154#define op_wait(op) (atomic_read(&(op)->aio_ref_count) <= 2 ? 0 : 1)
155
156/*
157 * Defines for controlling whether I/O upcalls are for async or sync operations
158 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500159enum ORANGEFS_async_io_type {
160 ORANGEFS_VFS_SYNC_IO = 0,
161 ORANGEFS_VFS_ASYNC_IO = 1,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400162};
163
164/*
165 * An array of client_debug_mask will be built to hold debug keyword/mask
166 * values fetched from userspace.
167 */
168struct client_debug_mask {
169 char *keyword;
170 __u64 mask1;
171 __u64 mask2;
172};
173
174/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500175 * orangefs kernel memory related flags
Mike Marshallf7ab0932015-07-17 10:38:11 -0400176 */
177
Yi Liu8bb8aef2015-11-24 15:12:14 -0500178#if ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB))
179#define ORANGEFS_CACHE_CREATE_FLAGS SLAB_RED_ZONE
Mike Marshallf7ab0932015-07-17 10:38:11 -0400180#else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500181#define ORANGEFS_CACHE_CREATE_FLAGS 0
182#endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400183
Yi Liu8bb8aef2015-11-24 15:12:14 -0500184#define ORANGEFS_CACHE_ALLOC_FLAGS (GFP_KERNEL)
185#define ORANGEFS_GFP_FLAGS (GFP_KERNEL)
186#define ORANGEFS_BUFMAP_GFP_FLAGS (GFP_KERNEL)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400187
Yi Liu8bb8aef2015-11-24 15:12:14 -0500188/* orangefs xattr and acl related defines */
189#define ORANGEFS_XATTR_INDEX_POSIX_ACL_ACCESS 1
190#define ORANGEFS_XATTR_INDEX_POSIX_ACL_DEFAULT 2
191#define ORANGEFS_XATTR_INDEX_TRUSTED 3
192#define ORANGEFS_XATTR_INDEX_DEFAULT 4
Mike Marshallf7ab0932015-07-17 10:38:11 -0400193
194#if 0
195#ifndef POSIX_ACL_XATTR_ACCESS
196#define POSIX_ACL_XATTR_ACCESS "system.posix_acl_access"
197#endif
198#ifndef POSIX_ACL_XATTR_DEFAULT
199#define POSIX_ACL_XATTR_DEFAULT "system.posix_acl_default"
200#endif
201#endif
202
Yi Liu8bb8aef2015-11-24 15:12:14 -0500203#define ORANGEFS_XATTR_NAME_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
204#define ORANGEFS_XATTR_NAME_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT
205#define ORANGEFS_XATTR_NAME_TRUSTED_PREFIX "trusted."
206#define ORANGEFS_XATTR_NAME_DEFAULT_PREFIX ""
Mike Marshallf7ab0932015-07-17 10:38:11 -0400207
Yi Liu8bb8aef2015-11-24 15:12:14 -0500208/* these functions are defined in orangefs-utils.c */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400209int orangefs_prepare_cdm_array(char *debug_array_string);
210int orangefs_prepare_debugfs_help_string(int);
211
Yi Liu8bb8aef2015-11-24 15:12:14 -0500212/* defined in orangefs-debugfs.c */
213int orangefs_client_debug_init(void);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400214
215void debug_string_to_mask(char *, void *, int);
216void do_c_mask(int, char *, struct client_debug_mask **);
217void do_k_mask(int, char *, __u64 **);
218
219void debug_mask_to_string(void *, int);
220void do_k_string(void *, int);
221void do_c_string(void *, int);
222int check_amalgam_keyword(void *, int);
223int keyword_is_amalgam(char *);
224
Yi Liu8bb8aef2015-11-24 15:12:14 -0500225/*these variables are defined in orangefs-mod.c */
226extern char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
227extern char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
228extern char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400229extern unsigned int kernel_mask_set_mod_init;
230
Yi Liu8bb8aef2015-11-24 15:12:14 -0500231extern int orangefs_init_acl(struct inode *inode, struct inode *dir);
232extern const struct xattr_handler *orangefs_xattr_handlers[];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400233
Yi Liu8bb8aef2015-11-24 15:12:14 -0500234extern struct posix_acl *orangefs_get_acl(struct inode *inode, int type);
235extern int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400236
Mike Marshallf7ab0932015-07-17 10:38:11 -0400237/*
238 * Redefine xtvec structure so that we could move helper functions out of
239 * the define
240 */
241struct xtvec {
242 __kernel_off_t xtv_off; /* must be off_t */
243 __kernel_size_t xtv_len; /* must be size_t */
244};
245
246/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500247 * orangefs data structures
Mike Marshallf7ab0932015-07-17 10:38:11 -0400248 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500249struct orangefs_kernel_op_s {
250 enum orangefs_vfs_op_states op_state;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400251 __u64 tag;
252
253 /*
254 * Set uses_shared_memory to 1 if this operation uses shared memory.
255 * If true, then a retry on the op must also get a new shared memory
256 * buffer and re-populate it.
257 */
258 int uses_shared_memory;
259
Yi Liu8bb8aef2015-11-24 15:12:14 -0500260 struct orangefs_upcall_s upcall;
261 struct orangefs_downcall_s downcall;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400262
263 wait_queue_head_t waitq;
264 spinlock_t lock;
265
266 int io_completed;
267 wait_queue_head_t io_completion_waitq;
268
Mike Marshallf7ab0932015-07-17 10:38:11 -0400269 /* VFS aio fields */
270
Yi Liu8bb8aef2015-11-24 15:12:14 -0500271 /* used by the async I/O code to stash the orangefs_kiocb_s structure */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400272 void *priv;
273
274 /* used again for the async I/O code for deallocation */
275 atomic_t aio_ref_count;
276
277 int attempts;
278
279 struct list_head list;
280};
281
Yi Liu8bb8aef2015-11-24 15:12:14 -0500282/* per inode private orangefs info */
283struct orangefs_inode_s {
284 struct orangefs_object_kref refn;
285 char link_target[ORANGEFS_NAME_MAX];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400286 __s64 blksize;
287 /*
288 * Reading/Writing Extended attributes need to acquire the appropriate
Yi Liu8bb8aef2015-11-24 15:12:14 -0500289 * reader/writer semaphore on the orangefs_inode_s structure.
Mike Marshallf7ab0932015-07-17 10:38:11 -0400290 */
291 struct rw_semaphore xattr_sem;
292
293 struct inode vfs_inode;
294 sector_t last_failed_block_index_read;
295
296 /*
297 * State of in-memory attributes not yet flushed to disk associated
298 * with this object
299 */
300 unsigned long pinode_flags;
301
Yi Liu8bb8aef2015-11-24 15:12:14 -0500302 /* All allocated orangefs_inode_s objects are chained to a list */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400303 struct list_head list;
304};
305
306#define P_ATIME_FLAG 0
307#define P_MTIME_FLAG 1
308#define P_CTIME_FLAG 2
309#define P_MODE_FLAG 3
310
311#define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
312#define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
313#define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
314
315#define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
316#define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
317#define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
318
319#define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
320#define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
321#define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
322
323#define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
324#define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
325#define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
326
Yi Liu8bb8aef2015-11-24 15:12:14 -0500327/* per superblock private orangefs info */
328struct orangefs_sb_info_s {
329 struct orangefs_khandle root_khandle;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400330 __s32 fs_id;
331 int id;
332 int flags;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500333#define ORANGEFS_OPT_INTR 0x01
334#define ORANGEFS_OPT_LOCAL_LOCK 0x02
335 char devname[ORANGEFS_MAX_SERVER_ADDR_LEN];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400336 struct super_block *sb;
337 int mount_pending;
338 struct list_head list;
339};
340
341/*
Mike Marshallf7ab0932015-07-17 10:38:11 -0400342 * structure that holds the state of any async I/O operation issued
343 * through the VFS. Needed especially to handle cancellation requests
344 * or even completion notification so that the VFS client-side daemon
345 * can free up its vfs_request slots.
346 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500347struct orangefs_kiocb_s {
Mike Marshallf7ab0932015-07-17 10:38:11 -0400348 /* the pointer to the task that initiated the AIO */
349 struct task_struct *tsk;
350
351 /* pointer to the kiocb that kicked this operation */
352 struct kiocb *kiocb;
353
354 /* buffer index that was used for the I/O */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500355 struct orangefs_bufmap *bufmap;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400356 int buffer_index;
357
Yi Liu8bb8aef2015-11-24 15:12:14 -0500358 /* orangefs kernel operation type */
359 struct orangefs_kernel_op_s *op;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400360
361 /* The user space buffers from/to which I/O is being staged */
362 struct iovec *iov;
363
364 /* number of elements in the iovector */
365 unsigned long nr_segs;
366
367 /* set to indicate the type of the operation */
368 int rw;
369
370 /* file offset */
371 loff_t offset;
372
373 /* and the count in bytes */
374 size_t bytes_to_be_copied;
375
376 ssize_t bytes_copied;
377 int needs_cleanup;
378};
379
Yi Liu8bb8aef2015-11-24 15:12:14 -0500380struct orangefs_stats {
Mike Marshallf7ab0932015-07-17 10:38:11 -0400381 unsigned long cache_hits;
382 unsigned long cache_misses;
383 unsigned long reads;
384 unsigned long writes;
385};
386
Yi Liu8bb8aef2015-11-24 15:12:14 -0500387extern struct orangefs_stats g_orangefs_stats;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400388
389/*
Mike Marshall54804942015-10-05 13:44:24 -0400390 * NOTE: See Documentation/filesystems/porting for information
391 * on implementing FOO_I and properly accessing fs private data
392 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500393static inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400394{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500395 return container_of(inode, struct orangefs_inode_s, vfs_inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400396}
397
Yi Liu8bb8aef2015-11-24 15:12:14 -0500398static inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400399{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500400 return (struct orangefs_sb_info_s *) sb->s_fs_info;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400401}
402
403/* ino_t descends from "unsigned long", 8 bytes, 64 bits. */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500404static inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400405{
406 union {
407 unsigned char u[8];
408 __u64 ino;
409 } ihandle;
410
411 ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
412 ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
413 ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
414 ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
415 ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
416 ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
417 ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
418 ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
419
420 return ihandle.ino;
421}
422
Yi Liu8bb8aef2015-11-24 15:12:14 -0500423static inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400424{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500425 return &(ORANGEFS_I(inode)->refn.khandle);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400426}
427
428static inline __s32 get_fsid_from_ino(struct inode *inode)
429{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500430 return ORANGEFS_I(inode)->refn.fs_id;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400431}
432
433static inline ino_t get_ino_from_khandle(struct inode *inode)
434{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500435 struct orangefs_khandle *khandle;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400436 ino_t ino;
437
438 khandle = get_khandle_from_ino(inode);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500439 ino = orangefs_khandle_to_ino(khandle);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400440 return ino;
441}
442
443static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry)
444{
445 return get_ino_from_khandle(dentry->d_parent->d_inode);
446}
447
448static inline int is_root_handle(struct inode *inode)
449{
450 gossip_debug(GOSSIP_DCACHE_DEBUG,
451 "%s: root handle: %pU, this handle: %pU:\n",
452 __func__,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500453 &ORANGEFS_SB(inode->i_sb)->root_khandle,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400454 get_khandle_from_ino(inode));
455
Yi Liu8bb8aef2015-11-24 15:12:14 -0500456 if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle),
Mike Marshallf7ab0932015-07-17 10:38:11 -0400457 get_khandle_from_ino(inode)))
458 return 0;
459 else
460 return 1;
461}
462
Yi Liu8bb8aef2015-11-24 15:12:14 -0500463static inline int match_handle(struct orangefs_khandle resp_handle,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400464 struct inode *inode)
465{
466 gossip_debug(GOSSIP_DCACHE_DEBUG,
467 "%s: one handle: %pU, another handle:%pU:\n",
468 __func__,
469 &resp_handle,
470 get_khandle_from_ino(inode));
471
Yi Liu8bb8aef2015-11-24 15:12:14 -0500472 if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
Mike Marshallf7ab0932015-07-17 10:38:11 -0400473 return 0;
474 else
475 return 1;
476}
477
478/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500479 * defined in orangefs-cache.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400480 */
481int op_cache_initialize(void);
482int op_cache_finalize(void);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500483struct orangefs_kernel_op_s *op_alloc(__s32 type);
484char *get_opname_string(struct orangefs_kernel_op_s *new_op);
485void op_release(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400486
487int dev_req_cache_initialize(void);
488int dev_req_cache_finalize(void);
489void *dev_req_alloc(void);
490void dev_req_release(void *);
491
Yi Liu8bb8aef2015-11-24 15:12:14 -0500492int orangefs_inode_cache_initialize(void);
493int orangefs_inode_cache_finalize(void);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400494
495int kiocb_cache_initialize(void);
496int kiocb_cache_finalize(void);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500497struct orangefs_kiocb_s *kiocb_alloc(void);
498void kiocb_release(struct orangefs_kiocb_s *ptr);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400499
500/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500501 * defined in orangefs-mod.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400502 */
503void purge_inprogress_ops(void);
504
505/*
506 * defined in waitqueue.c
507 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500508int wait_for_matching_downcall(struct orangefs_kernel_op_s *op);
509int wait_for_cancellation_downcall(struct orangefs_kernel_op_s *op);
510void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400511void purge_waiting_ops(void);
512
513/*
514 * defined in super.c
515 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500516struct dentry *orangefs_mount(struct file_system_type *fst,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400517 int flags,
518 const char *devname,
519 void *data);
520
Yi Liu8bb8aef2015-11-24 15:12:14 -0500521void orangefs_kill_sb(struct super_block *sb);
522int orangefs_remount(struct super_block *sb);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400523
524int fsid_key_table_initialize(void);
525void fsid_key_table_finalize(void);
526
527/*
528 * defined in inode.c
529 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500530__u32 convert_to_orangefs_mask(unsigned long lite_mask);
531struct inode *orangefs_new_inode(struct super_block *sb,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400532 struct inode *dir,
533 int mode,
534 dev_t dev,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500535 struct orangefs_object_kref *ref);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400536
Yi Liu8bb8aef2015-11-24 15:12:14 -0500537int orangefs_setattr(struct dentry *dentry, struct iattr *iattr);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400538
Yi Liu8bb8aef2015-11-24 15:12:14 -0500539int orangefs_getattr(struct vfsmount *mnt,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400540 struct dentry *dentry,
541 struct kstat *kstat);
542
543/*
544 * defined in xattr.c
545 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500546int orangefs_setxattr(struct dentry *dentry,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400547 const char *name,
548 const void *value,
549 size_t size,
550 int flags);
551
Yi Liu8bb8aef2015-11-24 15:12:14 -0500552ssize_t orangefs_getxattr(struct dentry *dentry,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400553 const char *name,
554 void *buffer,
555 size_t size);
556
Yi Liu8bb8aef2015-11-24 15:12:14 -0500557ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400558
559/*
560 * defined in namei.c
561 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500562struct inode *orangefs_iget(struct super_block *sb,
563 struct orangefs_object_kref *ref);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400564
Yi Liu8bb8aef2015-11-24 15:12:14 -0500565ssize_t orangefs_inode_read(struct inode *inode,
566 struct iov_iter *iter,
567 loff_t *offset,
568 loff_t readahead_size);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400569
570/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500571 * defined in devorangefs-req.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400572 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500573int orangefs_dev_init(void);
574void orangefs_dev_cleanup(void);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400575int is_daemon_in_service(void);
576int fs_mount_pending(__s32 fsid);
577
578/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500579 * defined in orangefs-utils.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400580 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500581__s32 fsid_of_op(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400582
Yi Liu8bb8aef2015-11-24 15:12:14 -0500583int orangefs_flush_inode(struct inode *inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400584
Yi Liu8bb8aef2015-11-24 15:12:14 -0500585ssize_t orangefs_inode_getxattr(struct inode *inode,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400586 const char *prefix,
587 const char *name,
588 void *buffer,
589 size_t size);
590
Yi Liu8bb8aef2015-11-24 15:12:14 -0500591int orangefs_inode_setxattr(struct inode *inode,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400592 const char *prefix,
593 const char *name,
594 const void *value,
595 size_t size,
596 int flags);
597
Yi Liu8bb8aef2015-11-24 15:12:14 -0500598int orangefs_inode_getattr(struct inode *inode, __u32 mask);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400599
Yi Liu8bb8aef2015-11-24 15:12:14 -0500600int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400601
Yi Liu8bb8aef2015-11-24 15:12:14 -0500602void orangefs_op_initialize(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400603
Yi Liu8bb8aef2015-11-24 15:12:14 -0500604void orangefs_make_bad_inode(struct inode *inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400605
Mike Marshall8c3905a2015-09-29 12:07:46 -0400606void block_signals(sigset_t *);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400607
Mike Marshall8c3905a2015-09-29 12:07:46 -0400608void set_signals(sigset_t *);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400609
Yi Liu8bb8aef2015-11-24 15:12:14 -0500610int orangefs_unmount_sb(struct super_block *sb);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400611
Yi Liu8bb8aef2015-11-24 15:12:14 -0500612int orangefs_cancel_op_in_progress(__u64 tag);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400613
Yi Liu8bb8aef2015-11-24 15:12:14 -0500614static inline __u64 orangefs_convert_time_field(const struct timespec *ts)
Al Viro57141562015-10-08 22:02:00 -0400615{
616 return (__u64)ts->tv_sec;
617}
Mike Marshallf7ab0932015-07-17 10:38:11 -0400618
Yi Liu8bb8aef2015-11-24 15:12:14 -0500619int orangefs_normalize_to_errno(__s32 error_code);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400620
621extern struct mutex devreq_mutex;
622extern struct mutex request_mutex;
623extern int debug;
624extern int op_timeout_secs;
625extern int slot_timeout_secs;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500626extern struct list_head orangefs_superblocks;
627extern spinlock_t orangefs_superblocks_lock;
628extern struct list_head orangefs_request_list;
629extern spinlock_t orangefs_request_list_lock;
630extern wait_queue_head_t orangefs_request_list_waitq;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400631extern struct list_head *htable_ops_in_progress;
632extern spinlock_t htable_ops_in_progress_lock;
633extern int hash_table_size;
634
Yi Liu8bb8aef2015-11-24 15:12:14 -0500635extern const struct address_space_operations orangefs_address_operations;
636extern struct backing_dev_info orangefs_backing_dev_info;
637extern struct inode_operations orangefs_file_inode_operations;
638extern const struct file_operations orangefs_file_operations;
639extern struct inode_operations orangefs_symlink_inode_operations;
640extern struct inode_operations orangefs_dir_inode_operations;
641extern const struct file_operations orangefs_dir_operations;
642extern const struct dentry_operations orangefs_dentry_operations;
643extern const struct file_operations orangefs_devreq_file_operations;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400644
Yi Liu8bb8aef2015-11-24 15:12:14 -0500645extern wait_queue_head_t orangefs_bufmap_init_waitq;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400646
647/*
648 * misc convenience macros
649 */
650#define add_op_to_request_list(op) \
651do { \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500652 spin_lock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400653 spin_lock(&op->lock); \
654 set_op_state_waiting(op); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500655 list_add_tail(&op->list, &orangefs_request_list); \
656 spin_unlock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400657 spin_unlock(&op->lock); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500658 wake_up_interruptible(&orangefs_request_list_waitq); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400659} while (0)
660
661#define add_priority_op_to_request_list(op) \
662 do { \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500663 spin_lock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400664 spin_lock(&op->lock); \
665 set_op_state_waiting(op); \
666 \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500667 list_add(&op->list, &orangefs_request_list); \
668 spin_unlock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400669 spin_unlock(&op->lock); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500670 wake_up_interruptible(&orangefs_request_list_waitq); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400671} while (0)
672
673#define remove_op_from_request_list(op) \
674 do { \
675 struct list_head *tmp = NULL; \
676 struct list_head *tmp_safe = NULL; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500677 struct orangefs_kernel_op_s *tmp_op = NULL; \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400678 \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500679 spin_lock(&orangefs_request_list_lock); \
680 list_for_each_safe(tmp, tmp_safe, &orangefs_request_list) { \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400681 tmp_op = list_entry(tmp, \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500682 struct orangefs_kernel_op_s, \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400683 list); \
684 if (tmp_op && (tmp_op == op)) { \
685 list_del(&tmp_op->list); \
686 break; \
687 } \
688 } \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500689 spin_unlock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400690 } while (0)
691
Yi Liu8bb8aef2015-11-24 15:12:14 -0500692#define ORANGEFS_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */
693#define ORANGEFS_OP_PRIORITY 2 /* service_operation() is high priority */
694#define ORANGEFS_OP_CANCELLATION 4 /* this is a cancellation */
695#define ORANGEFS_OP_NO_SEMAPHORE 8 /* don't acquire semaphore */
696#define ORANGEFS_OP_ASYNC 16 /* Queue it, but don't wait */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400697
Yi Liu8bb8aef2015-11-24 15:12:14 -0500698int service_operation(struct orangefs_kernel_op_s *op,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400699 const char *op_name,
700 int flags);
701
702/*
703 * handles two possible error cases, depending on context.
704 *
705 * by design, our vfs i/o errors need to be handled in one of two ways,
706 * depending on where the error occured.
707 *
708 * if the error happens in the waitqueue code because we either timed
709 * out or a signal was raised while waiting, we need to cancel the
710 * userspace i/o operation and free the op manually. this is done to
711 * avoid having the device start writing application data to our shared
712 * bufmap pages without us expecting it.
713 *
714 * FIXME: POSSIBLE OPTIMIZATION:
715 * However, if we timed out or if we got a signal AND our upcall was never
716 * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't
717 * need to send a cancellation upcall. The way we can handle this is
718 * set error_exit to 2 in such cases and 1 whenever cancellation has to be
719 * sent and have handle_error
720 * take care of this situation as well..
721 *
Yi Liu8bb8aef2015-11-24 15:12:14 -0500722 * if a orangefs sysint level error occured and i/o has been completed,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400723 * there is no need to cancel the operation, as the user has finished
724 * using the bufmap page and so there is no danger in this case. in
725 * this case, we wake up the device normally so that it may free the
726 * op, as normal.
727 *
728 * note the only reason this is a macro is because both read and write
729 * cases need the exact same handling code.
730 */
731#define handle_io_error() \
732do { \
733 if (!op_state_serviced(new_op)) { \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500734 orangefs_cancel_op_in_progress(new_op->tag); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400735 op_release(new_op); \
736 } else { \
737 wake_up_daemon_for_return(new_op); \
738 } \
739 new_op = NULL; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500740 orangefs_bufmap_put(bufmap, buffer_index); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400741 buffer_index = -1; \
742} while (0)
743
744#define get_interruptible_flag(inode) \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500745 ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \
746 ORANGEFS_OP_INTERRUPTIBLE : 0)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400747
Yi Liu8bb8aef2015-11-24 15:12:14 -0500748#define add_orangefs_sb(sb) \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400749do { \
750 gossip_debug(GOSSIP_SUPER_DEBUG, \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500751 "Adding SB %p to orangefs superblocks\n", \
752 ORANGEFS_SB(sb)); \
753 spin_lock(&orangefs_superblocks_lock); \
754 list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks); \
755 spin_unlock(&orangefs_superblocks_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400756} while (0)
757
Yi Liu8bb8aef2015-11-24 15:12:14 -0500758#define remove_orangefs_sb(sb) \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400759do { \
760 struct list_head *tmp = NULL; \
761 struct list_head *tmp_safe = NULL; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500762 struct orangefs_sb_info_s *orangefs_sb = NULL; \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400763 \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500764 spin_lock(&orangefs_superblocks_lock); \
765 list_for_each_safe(tmp, tmp_safe, &orangefs_superblocks) { \
766 orangefs_sb = list_entry(tmp, \
767 struct orangefs_sb_info_s, \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400768 list); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500769 if (orangefs_sb && (orangefs_sb->sb == sb)) { \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400770 gossip_debug(GOSSIP_SUPER_DEBUG, \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500771 "Removing SB %p from orangefs superblocks\n", \
772 orangefs_sb); \
773 list_del(&orangefs_sb->list); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400774 break; \
775 } \
776 } \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500777 spin_unlock(&orangefs_superblocks_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400778} while (0)
779
Yi Liu8bb8aef2015-11-24 15:12:14 -0500780#define orangefs_lock_inode(inode) spin_lock(&inode->i_lock)
781#define orangefs_unlock_inode(inode) spin_unlock(&inode->i_lock)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400782
783#define fill_default_sys_attrs(sys_attr, type, mode) \
784do { \
785 sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
786 sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
787 sys_attr.size = 0; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500788 sys_attr.perms = ORANGEFS_util_translate_mode(mode); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400789 sys_attr.objtype = type; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500790 sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE; \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400791} while (0)
792
Yi Liu8bb8aef2015-11-24 15:12:14 -0500793#define orangefs_inode_lock(__i) mutex_lock(&(__i)->i_mutex)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400794
Yi Liu8bb8aef2015-11-24 15:12:14 -0500795#define orangefs_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400796
Yi Liu8bb8aef2015-11-24 15:12:14 -0500797static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400798{
799#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
Yi Liu8bb8aef2015-11-24 15:12:14 -0500800 ornagefs_inode_lock(inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400801#endif
802 i_size_write(inode, i_size);
803#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
Yi Liu8bb8aef2015-11-24 15:12:14 -0500804 orangefs_inode_unlock(inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400805#endif
806}
807
808static inline unsigned int diff(struct timeval *end, struct timeval *begin)
809{
810 if (end->tv_usec < begin->tv_usec) {
811 end->tv_usec += 1000000;
812 end->tv_sec--;
813 }
814 end->tv_sec -= begin->tv_sec;
815 end->tv_usec -= begin->tv_usec;
816 return (end->tv_sec * 1000000) + end->tv_usec;
817}
818
Yi Liu8bb8aef2015-11-24 15:12:14 -0500819#endif /* __ORANGEFSKERNEL_H */