blob: fe8284045a40467874769d5eb36c2a24b0f454b6 [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
Mike Marshall575e9462015-12-04 12:56:14 -050056#include "orangefs-dev-proto.h"
Mike Marshallf7ab0932015-07-17 10:38:11 -040057
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
Mike Marshallf7ab0932015-07-17 10:38:11 -040083/* borrowed from irda.h */
84#ifndef MSECS_TO_JIFFIES
85#define MSECS_TO_JIFFIES(ms) (((ms)*HZ+999)/1000)
86#endif
87
Mike Marshallf7ab0932015-07-17 10:38:11 -040088/*
Yi Liu8bb8aef2015-11-24 15:12:14 -050089 * valid orangefs kernel operation states
Mike Marshallf7ab0932015-07-17 10:38:11 -040090 *
91 * unknown - op was just initialized
92 * waiting - op is on request_list (upward bound)
93 * inprogr - op is in progress (waiting for downcall)
94 * serviced - op has matching downcall; ok
95 * purged - op has to start a timer since client-core
96 * exited uncleanly before servicing op
97 */
Yi Liu8bb8aef2015-11-24 15:12:14 -050098enum orangefs_vfs_op_states {
Mike Marshallf7ab0932015-07-17 10:38:11 -040099 OP_VFS_STATE_UNKNOWN = 0,
100 OP_VFS_STATE_WAITING = 1,
101 OP_VFS_STATE_INPROGR = 2,
102 OP_VFS_STATE_SERVICED = 4,
103 OP_VFS_STATE_PURGED = 8,
104};
105
106#define set_op_state_waiting(op) ((op)->op_state = OP_VFS_STATE_WAITING)
107#define set_op_state_inprogress(op) ((op)->op_state = OP_VFS_STATE_INPROGR)
108#define set_op_state_serviced(op) ((op)->op_state = OP_VFS_STATE_SERVICED)
109#define set_op_state_purged(op) ((op)->op_state |= OP_VFS_STATE_PURGED)
110
111#define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING)
112#define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
113#define op_state_serviced(op) ((op)->op_state & OP_VFS_STATE_SERVICED)
114#define op_state_purged(op) ((op)->op_state & OP_VFS_STATE_PURGED)
115
116#define get_op(op) \
117 do { \
118 atomic_inc(&(op)->aio_ref_count); \
119 gossip_debug(GOSSIP_DEV_DEBUG, \
120 "(get) Alloced OP (%p:%llu)\n", \
121 op, \
122 llu((op)->tag)); \
123 } while (0)
124
125#define put_op(op) \
126 do { \
127 if (atomic_sub_and_test(1, &(op)->aio_ref_count) == 1) { \
128 gossip_debug(GOSSIP_DEV_DEBUG, \
129 "(put) Releasing OP (%p:%llu)\n", \
130 op, \
131 llu((op)->tag)); \
132 op_release(op); \
133 } \
134 } while (0)
135
136#define op_wait(op) (atomic_read(&(op)->aio_ref_count) <= 2 ? 0 : 1)
137
138/*
139 * Defines for controlling whether I/O upcalls are for async or sync operations
140 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500141enum ORANGEFS_async_io_type {
142 ORANGEFS_VFS_SYNC_IO = 0,
143 ORANGEFS_VFS_ASYNC_IO = 1,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400144};
145
146/*
147 * An array of client_debug_mask will be built to hold debug keyword/mask
148 * values fetched from userspace.
149 */
150struct client_debug_mask {
151 char *keyword;
152 __u64 mask1;
153 __u64 mask2;
154};
155
156/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500157 * orangefs kernel memory related flags
Mike Marshallf7ab0932015-07-17 10:38:11 -0400158 */
159
Yi Liu8bb8aef2015-11-24 15:12:14 -0500160#if ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB))
161#define ORANGEFS_CACHE_CREATE_FLAGS SLAB_RED_ZONE
Mike Marshallf7ab0932015-07-17 10:38:11 -0400162#else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500163#define ORANGEFS_CACHE_CREATE_FLAGS 0
164#endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400165
Yi Liu8bb8aef2015-11-24 15:12:14 -0500166#define ORANGEFS_CACHE_ALLOC_FLAGS (GFP_KERNEL)
167#define ORANGEFS_GFP_FLAGS (GFP_KERNEL)
168#define ORANGEFS_BUFMAP_GFP_FLAGS (GFP_KERNEL)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400169
Yi Liu8bb8aef2015-11-24 15:12:14 -0500170/* orangefs xattr and acl related defines */
171#define ORANGEFS_XATTR_INDEX_POSIX_ACL_ACCESS 1
172#define ORANGEFS_XATTR_INDEX_POSIX_ACL_DEFAULT 2
173#define ORANGEFS_XATTR_INDEX_TRUSTED 3
174#define ORANGEFS_XATTR_INDEX_DEFAULT 4
Mike Marshallf7ab0932015-07-17 10:38:11 -0400175
Mike Marshallfef8b672015-12-17 14:31:24 -0500176#define ORANGEFS_XATTR_NAME_ACL_ACCESS XATTR_NAME_POSIX_ACL_ACCESS
177#define ORANGEFS_XATTR_NAME_ACL_DEFAULT XATTR_NAME_POSIX_ACL_DEFAULT
Yi Liu8bb8aef2015-11-24 15:12:14 -0500178#define ORANGEFS_XATTR_NAME_TRUSTED_PREFIX "trusted."
179#define ORANGEFS_XATTR_NAME_DEFAULT_PREFIX ""
Mike Marshallf7ab0932015-07-17 10:38:11 -0400180
Yi Liu8bb8aef2015-11-24 15:12:14 -0500181/* these functions are defined in orangefs-utils.c */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400182int orangefs_prepare_cdm_array(char *debug_array_string);
183int orangefs_prepare_debugfs_help_string(int);
184
Yi Liu8bb8aef2015-11-24 15:12:14 -0500185/* defined in orangefs-debugfs.c */
186int orangefs_client_debug_init(void);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400187
188void debug_string_to_mask(char *, void *, int);
189void do_c_mask(int, char *, struct client_debug_mask **);
190void do_k_mask(int, char *, __u64 **);
191
192void debug_mask_to_string(void *, int);
193void do_k_string(void *, int);
194void do_c_string(void *, int);
195int check_amalgam_keyword(void *, int);
196int keyword_is_amalgam(char *);
197
Yi Liu8bb8aef2015-11-24 15:12:14 -0500198/*these variables are defined in orangefs-mod.c */
199extern char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
200extern char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
201extern char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400202extern unsigned int kernel_mask_set_mod_init;
203
Yi Liu8bb8aef2015-11-24 15:12:14 -0500204extern int orangefs_init_acl(struct inode *inode, struct inode *dir);
205extern const struct xattr_handler *orangefs_xattr_handlers[];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400206
Yi Liu8bb8aef2015-11-24 15:12:14 -0500207extern struct posix_acl *orangefs_get_acl(struct inode *inode, int type);
208extern int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400209
Mike Marshallf7ab0932015-07-17 10:38:11 -0400210/*
211 * Redefine xtvec structure so that we could move helper functions out of
212 * the define
213 */
214struct xtvec {
215 __kernel_off_t xtv_off; /* must be off_t */
216 __kernel_size_t xtv_len; /* must be size_t */
217};
218
219/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500220 * orangefs data structures
Mike Marshallf7ab0932015-07-17 10:38:11 -0400221 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500222struct orangefs_kernel_op_s {
223 enum orangefs_vfs_op_states op_state;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400224 __u64 tag;
225
226 /*
227 * Set uses_shared_memory to 1 if this operation uses shared memory.
228 * If true, then a retry on the op must also get a new shared memory
229 * buffer and re-populate it.
230 */
231 int uses_shared_memory;
232
Yi Liu8bb8aef2015-11-24 15:12:14 -0500233 struct orangefs_upcall_s upcall;
234 struct orangefs_downcall_s downcall;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400235
236 wait_queue_head_t waitq;
237 spinlock_t lock;
238
239 int io_completed;
240 wait_queue_head_t io_completion_waitq;
241
Mike Marshallf7ab0932015-07-17 10:38:11 -0400242 /* VFS aio fields */
243
Yi Liu8bb8aef2015-11-24 15:12:14 -0500244 /* used by the async I/O code to stash the orangefs_kiocb_s structure */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400245 void *priv;
246
247 /* used again for the async I/O code for deallocation */
248 atomic_t aio_ref_count;
249
250 int attempts;
251
252 struct list_head list;
253};
254
Yi Liu8bb8aef2015-11-24 15:12:14 -0500255/* per inode private orangefs info */
256struct orangefs_inode_s {
257 struct orangefs_object_kref refn;
258 char link_target[ORANGEFS_NAME_MAX];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400259 __s64 blksize;
260 /*
261 * Reading/Writing Extended attributes need to acquire the appropriate
Yi Liu8bb8aef2015-11-24 15:12:14 -0500262 * reader/writer semaphore on the orangefs_inode_s structure.
Mike Marshallf7ab0932015-07-17 10:38:11 -0400263 */
264 struct rw_semaphore xattr_sem;
265
266 struct inode vfs_inode;
267 sector_t last_failed_block_index_read;
268
269 /*
270 * State of in-memory attributes not yet flushed to disk associated
271 * with this object
272 */
273 unsigned long pinode_flags;
274
Yi Liu8bb8aef2015-11-24 15:12:14 -0500275 /* All allocated orangefs_inode_s objects are chained to a list */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400276 struct list_head list;
277};
278
279#define P_ATIME_FLAG 0
280#define P_MTIME_FLAG 1
281#define P_CTIME_FLAG 2
282#define P_MODE_FLAG 3
283
284#define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
285#define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
286#define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
287
288#define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
289#define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
290#define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
291
292#define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
293#define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
294#define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
295
296#define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
297#define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
298#define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
299
Yi Liu8bb8aef2015-11-24 15:12:14 -0500300/* per superblock private orangefs info */
301struct orangefs_sb_info_s {
302 struct orangefs_khandle root_khandle;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400303 __s32 fs_id;
304 int id;
305 int flags;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500306#define ORANGEFS_OPT_INTR 0x01
307#define ORANGEFS_OPT_LOCAL_LOCK 0x02
308 char devname[ORANGEFS_MAX_SERVER_ADDR_LEN];
Mike Marshallf7ab0932015-07-17 10:38:11 -0400309 struct super_block *sb;
310 int mount_pending;
311 struct list_head list;
312};
313
314/*
Mike Marshallf7ab0932015-07-17 10:38:11 -0400315 * structure that holds the state of any async I/O operation issued
316 * through the VFS. Needed especially to handle cancellation requests
317 * or even completion notification so that the VFS client-side daemon
318 * can free up its vfs_request slots.
319 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500320struct orangefs_kiocb_s {
Mike Marshallf7ab0932015-07-17 10:38:11 -0400321 /* the pointer to the task that initiated the AIO */
322 struct task_struct *tsk;
323
324 /* pointer to the kiocb that kicked this operation */
325 struct kiocb *kiocb;
326
327 /* buffer index that was used for the I/O */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500328 struct orangefs_bufmap *bufmap;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400329 int buffer_index;
330
Yi Liu8bb8aef2015-11-24 15:12:14 -0500331 /* orangefs kernel operation type */
332 struct orangefs_kernel_op_s *op;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400333
334 /* The user space buffers from/to which I/O is being staged */
335 struct iovec *iov;
336
337 /* number of elements in the iovector */
338 unsigned long nr_segs;
339
340 /* set to indicate the type of the operation */
341 int rw;
342
343 /* file offset */
344 loff_t offset;
345
346 /* and the count in bytes */
347 size_t bytes_to_be_copied;
348
349 ssize_t bytes_copied;
350 int needs_cleanup;
351};
352
Yi Liu8bb8aef2015-11-24 15:12:14 -0500353struct orangefs_stats {
Mike Marshallf7ab0932015-07-17 10:38:11 -0400354 unsigned long cache_hits;
355 unsigned long cache_misses;
356 unsigned long reads;
357 unsigned long writes;
358};
359
Yi Liu8bb8aef2015-11-24 15:12:14 -0500360extern struct orangefs_stats g_orangefs_stats;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400361
362/*
Mike Marshall54804942015-10-05 13:44:24 -0400363 * NOTE: See Documentation/filesystems/porting for information
364 * on implementing FOO_I and properly accessing fs private data
365 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500366static inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400367{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500368 return container_of(inode, struct orangefs_inode_s, vfs_inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400369}
370
Yi Liu8bb8aef2015-11-24 15:12:14 -0500371static inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400372{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500373 return (struct orangefs_sb_info_s *) sb->s_fs_info;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400374}
375
376/* ino_t descends from "unsigned long", 8 bytes, 64 bits. */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500377static inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400378{
379 union {
380 unsigned char u[8];
381 __u64 ino;
382 } ihandle;
383
384 ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
385 ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
386 ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
387 ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
388 ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
389 ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
390 ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
391 ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
392
393 return ihandle.ino;
394}
395
Yi Liu8bb8aef2015-11-24 15:12:14 -0500396static inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400397{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500398 return &(ORANGEFS_I(inode)->refn.khandle);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400399}
400
401static inline __s32 get_fsid_from_ino(struct inode *inode)
402{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500403 return ORANGEFS_I(inode)->refn.fs_id;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400404}
405
406static inline ino_t get_ino_from_khandle(struct inode *inode)
407{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500408 struct orangefs_khandle *khandle;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400409 ino_t ino;
410
411 khandle = get_khandle_from_ino(inode);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500412 ino = orangefs_khandle_to_ino(khandle);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400413 return ino;
414}
415
416static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry)
417{
418 return get_ino_from_khandle(dentry->d_parent->d_inode);
419}
420
421static inline int is_root_handle(struct inode *inode)
422{
423 gossip_debug(GOSSIP_DCACHE_DEBUG,
424 "%s: root handle: %pU, this handle: %pU:\n",
425 __func__,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500426 &ORANGEFS_SB(inode->i_sb)->root_khandle,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400427 get_khandle_from_ino(inode));
428
Yi Liu8bb8aef2015-11-24 15:12:14 -0500429 if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle),
Mike Marshallf7ab0932015-07-17 10:38:11 -0400430 get_khandle_from_ino(inode)))
431 return 0;
432 else
433 return 1;
434}
435
Yi Liu8bb8aef2015-11-24 15:12:14 -0500436static inline int match_handle(struct orangefs_khandle resp_handle,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400437 struct inode *inode)
438{
439 gossip_debug(GOSSIP_DCACHE_DEBUG,
440 "%s: one handle: %pU, another handle:%pU:\n",
441 __func__,
442 &resp_handle,
443 get_khandle_from_ino(inode));
444
Yi Liu8bb8aef2015-11-24 15:12:14 -0500445 if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
Mike Marshallf7ab0932015-07-17 10:38:11 -0400446 return 0;
447 else
448 return 1;
449}
450
451/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500452 * defined in orangefs-cache.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400453 */
454int op_cache_initialize(void);
455int op_cache_finalize(void);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500456struct orangefs_kernel_op_s *op_alloc(__s32 type);
457char *get_opname_string(struct orangefs_kernel_op_s *new_op);
458void op_release(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400459
460int dev_req_cache_initialize(void);
461int dev_req_cache_finalize(void);
462void *dev_req_alloc(void);
463void dev_req_release(void *);
464
Yi Liu8bb8aef2015-11-24 15:12:14 -0500465int orangefs_inode_cache_initialize(void);
466int orangefs_inode_cache_finalize(void);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400467
468int kiocb_cache_initialize(void);
469int kiocb_cache_finalize(void);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500470struct orangefs_kiocb_s *kiocb_alloc(void);
471void kiocb_release(struct orangefs_kiocb_s *ptr);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400472
473/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500474 * defined in orangefs-mod.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400475 */
476void purge_inprogress_ops(void);
477
478/*
479 * defined in waitqueue.c
480 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500481int wait_for_matching_downcall(struct orangefs_kernel_op_s *op);
482int wait_for_cancellation_downcall(struct orangefs_kernel_op_s *op);
483void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400484void purge_waiting_ops(void);
485
486/*
487 * defined in super.c
488 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500489struct dentry *orangefs_mount(struct file_system_type *fst,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400490 int flags,
491 const char *devname,
492 void *data);
493
Yi Liu8bb8aef2015-11-24 15:12:14 -0500494void orangefs_kill_sb(struct super_block *sb);
495int orangefs_remount(struct super_block *sb);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400496
497int fsid_key_table_initialize(void);
498void fsid_key_table_finalize(void);
499
500/*
501 * defined in inode.c
502 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500503__u32 convert_to_orangefs_mask(unsigned long lite_mask);
504struct inode *orangefs_new_inode(struct super_block *sb,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400505 struct inode *dir,
506 int mode,
507 dev_t dev,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500508 struct orangefs_object_kref *ref);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400509
Yi Liu8bb8aef2015-11-24 15:12:14 -0500510int orangefs_setattr(struct dentry *dentry, struct iattr *iattr);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400511
Yi Liu8bb8aef2015-11-24 15:12:14 -0500512int orangefs_getattr(struct vfsmount *mnt,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400513 struct dentry *dentry,
514 struct kstat *kstat);
515
516/*
517 * defined in xattr.c
518 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500519int orangefs_setxattr(struct dentry *dentry,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400520 const char *name,
521 const void *value,
522 size_t size,
523 int flags);
524
Yi Liu8bb8aef2015-11-24 15:12:14 -0500525ssize_t orangefs_getxattr(struct dentry *dentry,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400526 const char *name,
527 void *buffer,
528 size_t size);
529
Yi Liu8bb8aef2015-11-24 15:12:14 -0500530ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400531
532/*
533 * defined in namei.c
534 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500535struct inode *orangefs_iget(struct super_block *sb,
536 struct orangefs_object_kref *ref);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400537
Yi Liu8bb8aef2015-11-24 15:12:14 -0500538ssize_t orangefs_inode_read(struct inode *inode,
539 struct iov_iter *iter,
540 loff_t *offset,
541 loff_t readahead_size);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400542
543/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500544 * defined in devorangefs-req.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400545 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500546int orangefs_dev_init(void);
547void orangefs_dev_cleanup(void);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400548int is_daemon_in_service(void);
549int fs_mount_pending(__s32 fsid);
550
551/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500552 * defined in orangefs-utils.c
Mike Marshallf7ab0932015-07-17 10:38:11 -0400553 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500554__s32 fsid_of_op(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400555
Yi Liu8bb8aef2015-11-24 15:12:14 -0500556int orangefs_flush_inode(struct inode *inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400557
Yi Liu8bb8aef2015-11-24 15:12:14 -0500558ssize_t orangefs_inode_getxattr(struct inode *inode,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400559 const char *prefix,
560 const char *name,
561 void *buffer,
562 size_t size);
563
Yi Liu8bb8aef2015-11-24 15:12:14 -0500564int orangefs_inode_setxattr(struct inode *inode,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400565 const char *prefix,
566 const char *name,
567 const void *value,
568 size_t size,
569 int flags);
570
Yi Liu8bb8aef2015-11-24 15:12:14 -0500571int orangefs_inode_getattr(struct inode *inode, __u32 mask);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400572
Yi Liu8bb8aef2015-11-24 15:12:14 -0500573int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400574
Yi Liu8bb8aef2015-11-24 15:12:14 -0500575void orangefs_op_initialize(struct orangefs_kernel_op_s *op);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400576
Yi Liu8bb8aef2015-11-24 15:12:14 -0500577void orangefs_make_bad_inode(struct inode *inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400578
Mike Marshall8c3905a2015-09-29 12:07:46 -0400579void block_signals(sigset_t *);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400580
Mike Marshall8c3905a2015-09-29 12:07:46 -0400581void set_signals(sigset_t *);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400582
Yi Liu8bb8aef2015-11-24 15:12:14 -0500583int orangefs_unmount_sb(struct super_block *sb);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400584
Yi Liu8bb8aef2015-11-24 15:12:14 -0500585int orangefs_cancel_op_in_progress(__u64 tag);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400586
Yi Liu8bb8aef2015-11-24 15:12:14 -0500587static inline __u64 orangefs_convert_time_field(const struct timespec *ts)
Al Viro57141562015-10-08 22:02:00 -0400588{
589 return (__u64)ts->tv_sec;
590}
Mike Marshallf7ab0932015-07-17 10:38:11 -0400591
Yi Liu8bb8aef2015-11-24 15:12:14 -0500592int orangefs_normalize_to_errno(__s32 error_code);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400593
594extern struct mutex devreq_mutex;
595extern struct mutex request_mutex;
596extern int debug;
597extern int op_timeout_secs;
598extern int slot_timeout_secs;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500599extern struct list_head orangefs_superblocks;
600extern spinlock_t orangefs_superblocks_lock;
601extern struct list_head orangefs_request_list;
602extern spinlock_t orangefs_request_list_lock;
603extern wait_queue_head_t orangefs_request_list_waitq;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400604extern struct list_head *htable_ops_in_progress;
605extern spinlock_t htable_ops_in_progress_lock;
606extern int hash_table_size;
607
Yi Liu8bb8aef2015-11-24 15:12:14 -0500608extern const struct address_space_operations orangefs_address_operations;
609extern struct backing_dev_info orangefs_backing_dev_info;
610extern struct inode_operations orangefs_file_inode_operations;
611extern const struct file_operations orangefs_file_operations;
612extern struct inode_operations orangefs_symlink_inode_operations;
613extern struct inode_operations orangefs_dir_inode_operations;
614extern const struct file_operations orangefs_dir_operations;
615extern const struct dentry_operations orangefs_dentry_operations;
616extern const struct file_operations orangefs_devreq_file_operations;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400617
Yi Liu8bb8aef2015-11-24 15:12:14 -0500618extern wait_queue_head_t orangefs_bufmap_init_waitq;
Mike Marshallf7ab0932015-07-17 10:38:11 -0400619
620/*
621 * misc convenience macros
622 */
623#define add_op_to_request_list(op) \
624do { \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500625 spin_lock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400626 spin_lock(&op->lock); \
627 set_op_state_waiting(op); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500628 list_add_tail(&op->list, &orangefs_request_list); \
629 spin_unlock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400630 spin_unlock(&op->lock); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500631 wake_up_interruptible(&orangefs_request_list_waitq); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400632} while (0)
633
634#define add_priority_op_to_request_list(op) \
635 do { \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500636 spin_lock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400637 spin_lock(&op->lock); \
638 set_op_state_waiting(op); \
639 \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500640 list_add(&op->list, &orangefs_request_list); \
641 spin_unlock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400642 spin_unlock(&op->lock); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500643 wake_up_interruptible(&orangefs_request_list_waitq); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400644} while (0)
645
646#define remove_op_from_request_list(op) \
647 do { \
648 struct list_head *tmp = NULL; \
649 struct list_head *tmp_safe = NULL; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500650 struct orangefs_kernel_op_s *tmp_op = NULL; \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400651 \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500652 spin_lock(&orangefs_request_list_lock); \
653 list_for_each_safe(tmp, tmp_safe, &orangefs_request_list) { \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400654 tmp_op = list_entry(tmp, \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500655 struct orangefs_kernel_op_s, \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400656 list); \
657 if (tmp_op && (tmp_op == op)) { \
658 list_del(&tmp_op->list); \
659 break; \
660 } \
661 } \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500662 spin_unlock(&orangefs_request_list_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400663 } while (0)
664
Yi Liu8bb8aef2015-11-24 15:12:14 -0500665#define ORANGEFS_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */
666#define ORANGEFS_OP_PRIORITY 2 /* service_operation() is high priority */
667#define ORANGEFS_OP_CANCELLATION 4 /* this is a cancellation */
668#define ORANGEFS_OP_NO_SEMAPHORE 8 /* don't acquire semaphore */
669#define ORANGEFS_OP_ASYNC 16 /* Queue it, but don't wait */
Mike Marshallf7ab0932015-07-17 10:38:11 -0400670
Yi Liu8bb8aef2015-11-24 15:12:14 -0500671int service_operation(struct orangefs_kernel_op_s *op,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400672 const char *op_name,
673 int flags);
674
675/*
676 * handles two possible error cases, depending on context.
677 *
678 * by design, our vfs i/o errors need to be handled in one of two ways,
679 * depending on where the error occured.
680 *
681 * if the error happens in the waitqueue code because we either timed
682 * out or a signal was raised while waiting, we need to cancel the
683 * userspace i/o operation and free the op manually. this is done to
684 * avoid having the device start writing application data to our shared
685 * bufmap pages without us expecting it.
686 *
687 * FIXME: POSSIBLE OPTIMIZATION:
688 * However, if we timed out or if we got a signal AND our upcall was never
689 * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't
690 * need to send a cancellation upcall. The way we can handle this is
691 * set error_exit to 2 in such cases and 1 whenever cancellation has to be
692 * sent and have handle_error
693 * take care of this situation as well..
694 *
Yi Liu8bb8aef2015-11-24 15:12:14 -0500695 * if a orangefs sysint level error occured and i/o has been completed,
Mike Marshallf7ab0932015-07-17 10:38:11 -0400696 * there is no need to cancel the operation, as the user has finished
697 * using the bufmap page and so there is no danger in this case. in
698 * this case, we wake up the device normally so that it may free the
699 * op, as normal.
700 *
701 * note the only reason this is a macro is because both read and write
702 * cases need the exact same handling code.
703 */
704#define handle_io_error() \
705do { \
706 if (!op_state_serviced(new_op)) { \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500707 orangefs_cancel_op_in_progress(new_op->tag); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400708 op_release(new_op); \
709 } else { \
710 wake_up_daemon_for_return(new_op); \
711 } \
712 new_op = NULL; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500713 orangefs_bufmap_put(bufmap, buffer_index); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400714 buffer_index = -1; \
715} while (0)
716
717#define get_interruptible_flag(inode) \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500718 ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \
719 ORANGEFS_OP_INTERRUPTIBLE : 0)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400720
Yi Liu8bb8aef2015-11-24 15:12:14 -0500721#define add_orangefs_sb(sb) \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400722do { \
723 gossip_debug(GOSSIP_SUPER_DEBUG, \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500724 "Adding SB %p to orangefs superblocks\n", \
725 ORANGEFS_SB(sb)); \
726 spin_lock(&orangefs_superblocks_lock); \
727 list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks); \
728 spin_unlock(&orangefs_superblocks_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400729} while (0)
730
Yi Liu8bb8aef2015-11-24 15:12:14 -0500731#define remove_orangefs_sb(sb) \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400732do { \
733 struct list_head *tmp = NULL; \
734 struct list_head *tmp_safe = NULL; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500735 struct orangefs_sb_info_s *orangefs_sb = NULL; \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400736 \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500737 spin_lock(&orangefs_superblocks_lock); \
738 list_for_each_safe(tmp, tmp_safe, &orangefs_superblocks) { \
739 orangefs_sb = list_entry(tmp, \
740 struct orangefs_sb_info_s, \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400741 list); \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500742 if (orangefs_sb && (orangefs_sb->sb == sb)) { \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400743 gossip_debug(GOSSIP_SUPER_DEBUG, \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500744 "Removing SB %p from orangefs superblocks\n", \
745 orangefs_sb); \
746 list_del(&orangefs_sb->list); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400747 break; \
748 } \
749 } \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500750 spin_unlock(&orangefs_superblocks_lock); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400751} while (0)
752
Yi Liu8bb8aef2015-11-24 15:12:14 -0500753#define orangefs_lock_inode(inode) spin_lock(&inode->i_lock)
754#define orangefs_unlock_inode(inode) spin_unlock(&inode->i_lock)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400755
756#define fill_default_sys_attrs(sys_attr, type, mode) \
757do { \
758 sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
759 sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
760 sys_attr.size = 0; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500761 sys_attr.perms = ORANGEFS_util_translate_mode(mode); \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400762 sys_attr.objtype = type; \
Yi Liu8bb8aef2015-11-24 15:12:14 -0500763 sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE; \
Mike Marshallf7ab0932015-07-17 10:38:11 -0400764} while (0)
765
Yi Liu8bb8aef2015-11-24 15:12:14 -0500766#define orangefs_inode_lock(__i) mutex_lock(&(__i)->i_mutex)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400767
Yi Liu8bb8aef2015-11-24 15:12:14 -0500768#define orangefs_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400769
Yi Liu8bb8aef2015-11-24 15:12:14 -0500770static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size)
Mike Marshallf7ab0932015-07-17 10:38:11 -0400771{
772#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
Arnd Bergmanneb57bcc2015-12-21 14:49:29 +0100773 orangefs_inode_lock(inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400774#endif
775 i_size_write(inode, i_size);
776#if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
Yi Liu8bb8aef2015-11-24 15:12:14 -0500777 orangefs_inode_unlock(inode);
Mike Marshallf7ab0932015-07-17 10:38:11 -0400778#endif
779}
780
781static inline unsigned int diff(struct timeval *end, struct timeval *begin)
782{
783 if (end->tv_usec < begin->tv_usec) {
784 end->tv_usec += 1000000;
785 end->tv_sec--;
786 }
787 end->tv_sec -= begin->tv_sec;
788 end->tv_usec -= begin->tv_usec;
789 return (end->tv_sec * 1000000) + end->tv_usec;
790}
791
Yi Liu8bb8aef2015-11-24 15:12:14 -0500792#endif /* __ORANGEFSKERNEL_H */