orangefs-kernel.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * (C) 2001 Clemson University and The University of Chicago
  3. *
  4. * See COPYING in top-level directory.
  5. */
  6. /*
  7. * The ORANGEFS Linux kernel support allows ORANGEFS volumes to be mounted and
  8. * accessed through the Linux VFS (i.e. using standard I/O system calls).
  9. * This support is only needed on clients that wish to mount the file system.
  10. *
  11. */
  12. /*
  13. * Declarations and macros for the ORANGEFS Linux kernel support.
  14. */
  15. #ifndef __ORANGEFSKERNEL_H
  16. #define __ORANGEFSKERNEL_H
  17. #include <linux/kernel.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/statfs.h>
  20. #include <linux/backing-dev.h>
  21. #include <linux/device.h>
  22. #include <linux/mpage.h>
  23. #include <linux/namei.h>
  24. #include <linux/errno.h>
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/types.h>
  29. #include <linux/fs.h>
  30. #include <linux/vmalloc.h>
  31. #include <linux/aio.h>
  32. #include <linux/posix_acl.h>
  33. #include <linux/posix_acl_xattr.h>
  34. #include <linux/compat.h>
  35. #include <linux/mount.h>
  36. #include <linux/uaccess.h>
  37. #include <linux/atomic.h>
  38. #include <linux/uio.h>
  39. #include <linux/sched.h>
  40. #include <linux/mm.h>
  41. #include <linux/wait.h>
  42. #include <linux/dcache.h>
  43. #include <linux/pagemap.h>
  44. #include <linux/poll.h>
  45. #include <linux/rwsem.h>
  46. #include <linux/xattr.h>
  47. #include <linux/exportfs.h>
  48. #include <asm/unaligned.h>
  49. #include "orangefs-dev-proto.h"
  50. #ifdef ORANGEFS_KERNEL_DEBUG
  51. #define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 10
  52. #else
  53. #define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 20
  54. #endif
  55. #define ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS 30
  56. #define ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS 900 /* 15 minutes */
  57. #define ORANGEFS_REQDEVICE_NAME "pvfs2-req"
  58. #define ORANGEFS_DEVREQ_MAGIC 0x20030529
  59. #define ORANGEFS_LINK_MAX 0x000000FF
  60. #define ORANGEFS_PURGE_RETRY_COUNT 0x00000005
  61. #define ORANGEFS_SEEK_END 0x00000002
  62. #define ORANGEFS_MAX_NUM_OPTIONS 0x00000004
  63. #define ORANGEFS_MAX_MOUNT_OPT_LEN 0x00000080
  64. #define ORANGEFS_MAX_FSKEY_LEN 64
  65. #define MAX_DEV_REQ_UPSIZE (2 * sizeof(__s32) + \
  66. sizeof(__u64) + sizeof(struct orangefs_upcall_s))
  67. #define MAX_DEV_REQ_DOWNSIZE (2 * sizeof(__s32) + \
  68. sizeof(__u64) + sizeof(struct orangefs_downcall_s))
  69. /*
  70. * valid orangefs kernel operation states
  71. *
  72. * unknown - op was just initialized
  73. * waiting - op is on request_list (upward bound)
  74. * inprogr - op is in progress (waiting for downcall)
  75. * serviced - op has matching downcall; ok
  76. * purged - op has to start a timer since client-core
  77. * exited uncleanly before servicing op
  78. * given up - submitter has given up waiting for it
  79. */
  80. enum orangefs_vfs_op_states {
  81. OP_VFS_STATE_UNKNOWN = 0,
  82. OP_VFS_STATE_WAITING = 1,
  83. OP_VFS_STATE_INPROGR = 2,
  84. OP_VFS_STATE_SERVICED = 4,
  85. OP_VFS_STATE_PURGED = 8,
  86. OP_VFS_STATE_GIVEN_UP = 16,
  87. };
  88. /*
  89. * Defines for controlling whether I/O upcalls are for async or sync operations
  90. */
  91. enum ORANGEFS_async_io_type {
  92. ORANGEFS_VFS_SYNC_IO = 0,
  93. ORANGEFS_VFS_ASYNC_IO = 1,
  94. };
  95. /*
  96. * An array of client_debug_mask will be built to hold debug keyword/mask
  97. * values fetched from userspace.
  98. */
  99. struct client_debug_mask {
  100. char *keyword;
  101. __u64 mask1;
  102. __u64 mask2;
  103. };
  104. /*
  105. * orangefs kernel memory related flags
  106. */
  107. #if ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB))
  108. #define ORANGEFS_CACHE_CREATE_FLAGS SLAB_RED_ZONE
  109. #else
  110. #define ORANGEFS_CACHE_CREATE_FLAGS 0
  111. #endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */
  112. #define ORANGEFS_GFP_FLAGS (GFP_KERNEL)
  113. #define ORANGEFS_BUFMAP_GFP_FLAGS (GFP_KERNEL)
  114. /* orangefs xattr and acl related defines */
  115. #define ORANGEFS_XATTR_INDEX_POSIX_ACL_ACCESS 1
  116. #define ORANGEFS_XATTR_INDEX_POSIX_ACL_DEFAULT 2
  117. #define ORANGEFS_XATTR_INDEX_TRUSTED 3
  118. #define ORANGEFS_XATTR_INDEX_DEFAULT 4
  119. #define ORANGEFS_XATTR_NAME_ACL_ACCESS XATTR_NAME_POSIX_ACL_ACCESS
  120. #define ORANGEFS_XATTR_NAME_ACL_DEFAULT XATTR_NAME_POSIX_ACL_DEFAULT
  121. #define ORANGEFS_XATTR_NAME_TRUSTED_PREFIX "trusted."
  122. #define ORANGEFS_XATTR_NAME_DEFAULT_PREFIX ""
  123. /* these functions are defined in orangefs-utils.c */
  124. int orangefs_prepare_cdm_array(char *debug_array_string);
  125. int orangefs_prepare_debugfs_help_string(int);
  126. /* defined in orangefs-debugfs.c */
  127. int orangefs_client_debug_init(void);
  128. void debug_string_to_mask(char *, void *, int);
  129. void do_c_mask(int, char *, struct client_debug_mask **);
  130. void do_k_mask(int, char *, __u64 **);
  131. void debug_mask_to_string(void *, int);
  132. void do_k_string(void *, int);
  133. void do_c_string(void *, int);
  134. int check_amalgam_keyword(void *, int);
  135. int keyword_is_amalgam(char *);
  136. /*these variables are defined in orangefs-mod.c */
  137. extern char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
  138. extern char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
  139. extern char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
  140. extern unsigned int kernel_mask_set_mod_init;
  141. extern int orangefs_init_acl(struct inode *inode, struct inode *dir);
  142. extern const struct xattr_handler *orangefs_xattr_handlers[];
  143. extern struct posix_acl *orangefs_get_acl(struct inode *inode, int type);
  144. extern int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
  145. /*
  146. * Redefine xtvec structure so that we could move helper functions out of
  147. * the define
  148. */
  149. struct xtvec {
  150. __kernel_off_t xtv_off; /* must be off_t */
  151. __kernel_size_t xtv_len; /* must be size_t */
  152. };
  153. /*
  154. * orangefs data structures
  155. */
  156. struct orangefs_kernel_op_s {
  157. enum orangefs_vfs_op_states op_state;
  158. __u64 tag;
  159. /*
  160. * Set uses_shared_memory to 1 if this operation uses shared memory.
  161. * If true, then a retry on the op must also get a new shared memory
  162. * buffer and re-populate it. Cancels don't care - it only matters
  163. * for service_operation() retry logics and cancels don't go through
  164. * it anymore.
  165. */
  166. union {
  167. int uses_shared_memory;
  168. int slot_to_free;
  169. };
  170. struct orangefs_upcall_s upcall;
  171. struct orangefs_downcall_s downcall;
  172. wait_queue_head_t waitq;
  173. spinlock_t lock;
  174. struct completion done;
  175. atomic_t ref_count;
  176. /* VFS aio fields */
  177. int attempts;
  178. struct list_head list;
  179. };
  180. #define set_op_state_waiting(op) ((op)->op_state = OP_VFS_STATE_WAITING)
  181. #define set_op_state_inprogress(op) ((op)->op_state = OP_VFS_STATE_INPROGR)
  182. #define set_op_state_given_up(op) ((op)->op_state = OP_VFS_STATE_GIVEN_UP)
  183. static inline void set_op_state_serviced(struct orangefs_kernel_op_s *op)
  184. {
  185. op->op_state = OP_VFS_STATE_SERVICED;
  186. wake_up_interruptible(&op->waitq);
  187. }
  188. #define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING)
  189. #define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
  190. #define op_state_serviced(op) ((op)->op_state & OP_VFS_STATE_SERVICED)
  191. #define op_state_purged(op) ((op)->op_state & OP_VFS_STATE_PURGED)
  192. #define op_state_given_up(op) ((op)->op_state & OP_VFS_STATE_GIVEN_UP)
  193. #define op_is_cancel(op) ((op)->upcall.type == ORANGEFS_VFS_OP_CANCEL)
  194. static inline void get_op(struct orangefs_kernel_op_s *op)
  195. {
  196. atomic_inc(&op->ref_count);
  197. gossip_debug(GOSSIP_DEV_DEBUG,
  198. "(get) Alloced OP (%p:%llu)\n", op, llu(op->tag));
  199. }
  200. void __op_release(struct orangefs_kernel_op_s *op);
  201. static inline void op_release(struct orangefs_kernel_op_s *op)
  202. {
  203. if (atomic_dec_and_test(&op->ref_count)) {
  204. gossip_debug(GOSSIP_DEV_DEBUG,
  205. "(put) Releasing OP (%p:%llu)\n", op, llu((op)->tag));
  206. __op_release(op);
  207. }
  208. }
  209. extern void orangefs_bufmap_put(int);
  210. static inline void put_cancel(struct orangefs_kernel_op_s *op)
  211. {
  212. orangefs_bufmap_put(op->slot_to_free);
  213. op_release(op);
  214. }
  215. static inline void set_op_state_purged(struct orangefs_kernel_op_s *op)
  216. {
  217. spin_lock(&op->lock);
  218. if (unlikely(op_is_cancel(op))) {
  219. list_del(&op->list);
  220. spin_unlock(&op->lock);
  221. put_cancel(op);
  222. } else {
  223. op->op_state |= OP_VFS_STATE_PURGED;
  224. wake_up_interruptible(&op->waitq);
  225. spin_unlock(&op->lock);
  226. }
  227. }
  228. /* per inode private orangefs info */
  229. struct orangefs_inode_s {
  230. struct orangefs_object_kref refn;
  231. char link_target[ORANGEFS_NAME_MAX];
  232. __s64 blksize;
  233. /*
  234. * Reading/Writing Extended attributes need to acquire the appropriate
  235. * reader/writer semaphore on the orangefs_inode_s structure.
  236. */
  237. struct rw_semaphore xattr_sem;
  238. struct inode vfs_inode;
  239. sector_t last_failed_block_index_read;
  240. /*
  241. * State of in-memory attributes not yet flushed to disk associated
  242. * with this object
  243. */
  244. unsigned long pinode_flags;
  245. };
  246. #define P_ATIME_FLAG 0
  247. #define P_MTIME_FLAG 1
  248. #define P_CTIME_FLAG 2
  249. #define P_MODE_FLAG 3
  250. #define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
  251. #define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
  252. #define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags)
  253. #define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
  254. #define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
  255. #define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags)
  256. #define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
  257. #define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
  258. #define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags)
  259. #define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
  260. #define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
  261. #define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags)
  262. /* per superblock private orangefs info */
  263. struct orangefs_sb_info_s {
  264. struct orangefs_khandle root_khandle;
  265. __s32 fs_id;
  266. int id;
  267. int flags;
  268. #define ORANGEFS_OPT_INTR 0x01
  269. #define ORANGEFS_OPT_LOCAL_LOCK 0x02
  270. char devname[ORANGEFS_MAX_SERVER_ADDR_LEN];
  271. struct super_block *sb;
  272. int mount_pending;
  273. struct list_head list;
  274. };
  275. /*
  276. * structure that holds the state of any async I/O operation issued
  277. * through the VFS. Needed especially to handle cancellation requests
  278. * or even completion notification so that the VFS client-side daemon
  279. * can free up its vfs_request slots.
  280. */
  281. struct orangefs_kiocb_s {
  282. /* the pointer to the task that initiated the AIO */
  283. struct task_struct *tsk;
  284. /* pointer to the kiocb that kicked this operation */
  285. struct kiocb *kiocb;
  286. /* buffer index that was used for the I/O */
  287. struct orangefs_bufmap *bufmap;
  288. int buffer_index;
  289. /* orangefs kernel operation type */
  290. struct orangefs_kernel_op_s *op;
  291. /* The user space buffers from/to which I/O is being staged */
  292. struct iovec *iov;
  293. /* number of elements in the iovector */
  294. unsigned long nr_segs;
  295. /* set to indicate the type of the operation */
  296. int rw;
  297. /* file offset */
  298. loff_t offset;
  299. /* and the count in bytes */
  300. size_t bytes_to_be_copied;
  301. ssize_t bytes_copied;
  302. int needs_cleanup;
  303. };
  304. struct orangefs_stats {
  305. unsigned long cache_hits;
  306. unsigned long cache_misses;
  307. unsigned long reads;
  308. unsigned long writes;
  309. };
  310. extern struct orangefs_stats g_orangefs_stats;
  311. /*
  312. * NOTE: See Documentation/filesystems/porting for information
  313. * on implementing FOO_I and properly accessing fs private data
  314. */
  315. static inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode)
  316. {
  317. return container_of(inode, struct orangefs_inode_s, vfs_inode);
  318. }
  319. static inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb)
  320. {
  321. return (struct orangefs_sb_info_s *) sb->s_fs_info;
  322. }
  323. /* ino_t descends from "unsigned long", 8 bytes, 64 bits. */
  324. static inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle)
  325. {
  326. union {
  327. unsigned char u[8];
  328. __u64 ino;
  329. } ihandle;
  330. ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
  331. ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
  332. ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
  333. ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
  334. ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
  335. ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
  336. ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
  337. ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
  338. return ihandle.ino;
  339. }
  340. static inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode)
  341. {
  342. return &(ORANGEFS_I(inode)->refn.khandle);
  343. }
  344. static inline __s32 get_fsid_from_ino(struct inode *inode)
  345. {
  346. return ORANGEFS_I(inode)->refn.fs_id;
  347. }
  348. static inline ino_t get_ino_from_khandle(struct inode *inode)
  349. {
  350. struct orangefs_khandle *khandle;
  351. ino_t ino;
  352. khandle = get_khandle_from_ino(inode);
  353. ino = orangefs_khandle_to_ino(khandle);
  354. return ino;
  355. }
  356. static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry)
  357. {
  358. return get_ino_from_khandle(dentry->d_parent->d_inode);
  359. }
  360. static inline int is_root_handle(struct inode *inode)
  361. {
  362. gossip_debug(GOSSIP_DCACHE_DEBUG,
  363. "%s: root handle: %pU, this handle: %pU:\n",
  364. __func__,
  365. &ORANGEFS_SB(inode->i_sb)->root_khandle,
  366. get_khandle_from_ino(inode));
  367. if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle),
  368. get_khandle_from_ino(inode)))
  369. return 0;
  370. else
  371. return 1;
  372. }
  373. static inline int match_handle(struct orangefs_khandle resp_handle,
  374. struct inode *inode)
  375. {
  376. gossip_debug(GOSSIP_DCACHE_DEBUG,
  377. "%s: one handle: %pU, another handle:%pU:\n",
  378. __func__,
  379. &resp_handle,
  380. get_khandle_from_ino(inode));
  381. if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
  382. return 0;
  383. else
  384. return 1;
  385. }
  386. /*
  387. * defined in orangefs-cache.c
  388. */
  389. int op_cache_initialize(void);
  390. int op_cache_finalize(void);
  391. struct orangefs_kernel_op_s *op_alloc(__s32 type);
  392. void orangefs_new_tag(struct orangefs_kernel_op_s *op);
  393. char *get_opname_string(struct orangefs_kernel_op_s *new_op);
  394. int orangefs_inode_cache_initialize(void);
  395. int orangefs_inode_cache_finalize(void);
  396. /*
  397. * defined in orangefs-mod.c
  398. */
  399. void purge_inprogress_ops(void);
  400. /*
  401. * defined in waitqueue.c
  402. */
  403. void purge_waiting_ops(void);
  404. /*
  405. * defined in super.c
  406. */
  407. struct dentry *orangefs_mount(struct file_system_type *fst,
  408. int flags,
  409. const char *devname,
  410. void *data);
  411. void orangefs_kill_sb(struct super_block *sb);
  412. int orangefs_remount(struct super_block *sb);
  413. int fsid_key_table_initialize(void);
  414. void fsid_key_table_finalize(void);
  415. /*
  416. * defined in inode.c
  417. */
  418. __u32 convert_to_orangefs_mask(unsigned long lite_mask);
  419. struct inode *orangefs_new_inode(struct super_block *sb,
  420. struct inode *dir,
  421. int mode,
  422. dev_t dev,
  423. struct orangefs_object_kref *ref);
  424. int orangefs_setattr(struct dentry *dentry, struct iattr *iattr);
  425. int orangefs_getattr(struct vfsmount *mnt,
  426. struct dentry *dentry,
  427. struct kstat *kstat);
  428. int orangefs_permission(struct inode *inode, int mask);
  429. /*
  430. * defined in xattr.c
  431. */
  432. int orangefs_setxattr(struct dentry *dentry,
  433. const char *name,
  434. const void *value,
  435. size_t size,
  436. int flags);
  437. ssize_t orangefs_getxattr(struct dentry *dentry,
  438. const char *name,
  439. void *buffer,
  440. size_t size);
  441. ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  442. /*
  443. * defined in namei.c
  444. */
  445. struct inode *orangefs_iget(struct super_block *sb,
  446. struct orangefs_object_kref *ref);
  447. ssize_t orangefs_inode_read(struct inode *inode,
  448. struct iov_iter *iter,
  449. loff_t *offset,
  450. loff_t readahead_size);
  451. /*
  452. * defined in devorangefs-req.c
  453. */
  454. int orangefs_dev_init(void);
  455. void orangefs_dev_cleanup(void);
  456. int is_daemon_in_service(void);
  457. bool __is_daemon_in_service(void);
  458. int fs_mount_pending(__s32 fsid);
  459. /*
  460. * defined in orangefs-utils.c
  461. */
  462. __s32 fsid_of_op(struct orangefs_kernel_op_s *op);
  463. int orangefs_flush_inode(struct inode *inode);
  464. ssize_t orangefs_inode_getxattr(struct inode *inode,
  465. const char *prefix,
  466. const char *name,
  467. void *buffer,
  468. size_t size);
  469. int orangefs_inode_setxattr(struct inode *inode,
  470. const char *prefix,
  471. const char *name,
  472. const void *value,
  473. size_t size,
  474. int flags);
  475. int orangefs_inode_getattr(struct inode *inode, __u32 mask, int check);
  476. int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr);
  477. void orangefs_make_bad_inode(struct inode *inode);
  478. void orangefs_block_signals(sigset_t *);
  479. void orangefs_set_signals(sigset_t *);
  480. int orangefs_unmount_sb(struct super_block *sb);
  481. bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op);
  482. static inline __u64 orangefs_convert_time_field(const struct timespec *ts)
  483. {
  484. return (__u64)ts->tv_sec;
  485. }
  486. int orangefs_normalize_to_errno(__s32 error_code);
  487. extern struct mutex devreq_mutex;
  488. extern struct mutex request_mutex;
  489. extern int debug;
  490. extern int op_timeout_secs;
  491. extern int slot_timeout_secs;
  492. extern struct list_head orangefs_superblocks;
  493. extern spinlock_t orangefs_superblocks_lock;
  494. extern struct list_head orangefs_request_list;
  495. extern spinlock_t orangefs_request_list_lock;
  496. extern wait_queue_head_t orangefs_request_list_waitq;
  497. extern struct list_head *htable_ops_in_progress;
  498. extern spinlock_t htable_ops_in_progress_lock;
  499. extern int hash_table_size;
  500. extern const struct address_space_operations orangefs_address_operations;
  501. extern struct backing_dev_info orangefs_backing_dev_info;
  502. extern struct inode_operations orangefs_file_inode_operations;
  503. extern const struct file_operations orangefs_file_operations;
  504. extern struct inode_operations orangefs_symlink_inode_operations;
  505. extern struct inode_operations orangefs_dir_inode_operations;
  506. extern const struct file_operations orangefs_dir_operations;
  507. extern const struct dentry_operations orangefs_dentry_operations;
  508. extern const struct file_operations orangefs_devreq_file_operations;
  509. extern wait_queue_head_t orangefs_bufmap_init_waitq;
  510. /*
  511. * misc convenience macros
  512. */
  513. #define ORANGEFS_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */
  514. #define ORANGEFS_OP_PRIORITY 2 /* service_operation() is high priority */
  515. #define ORANGEFS_OP_CANCELLATION 4 /* this is a cancellation */
  516. #define ORANGEFS_OP_NO_SEMAPHORE 8 /* don't acquire semaphore */
  517. #define ORANGEFS_OP_ASYNC 16 /* Queue it, but don't wait */
  518. int service_operation(struct orangefs_kernel_op_s *op,
  519. const char *op_name,
  520. int flags);
  521. #define get_interruptible_flag(inode) \
  522. ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \
  523. ORANGEFS_OP_INTERRUPTIBLE : 0)
  524. #define add_orangefs_sb(sb) \
  525. do { \
  526. gossip_debug(GOSSIP_SUPER_DEBUG, \
  527. "Adding SB %p to orangefs superblocks\n", \
  528. ORANGEFS_SB(sb)); \
  529. spin_lock(&orangefs_superblocks_lock); \
  530. list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks); \
  531. spin_unlock(&orangefs_superblocks_lock); \
  532. } while (0)
  533. #define remove_orangefs_sb(sb) \
  534. do { \
  535. struct list_head *tmp = NULL; \
  536. struct list_head *tmp_safe = NULL; \
  537. struct orangefs_sb_info_s *orangefs_sb = NULL; \
  538. \
  539. spin_lock(&orangefs_superblocks_lock); \
  540. list_for_each_safe(tmp, tmp_safe, &orangefs_superblocks) { \
  541. orangefs_sb = list_entry(tmp, \
  542. struct orangefs_sb_info_s, \
  543. list); \
  544. if (orangefs_sb && (orangefs_sb->sb == sb)) { \
  545. gossip_debug(GOSSIP_SUPER_DEBUG, \
  546. "Removing SB %p from orangefs superblocks\n", \
  547. orangefs_sb); \
  548. list_del(&orangefs_sb->list); \
  549. break; \
  550. } \
  551. } \
  552. spin_unlock(&orangefs_superblocks_lock); \
  553. } while (0)
  554. #define orangefs_lock_inode(inode) spin_lock(&inode->i_lock)
  555. #define orangefs_unlock_inode(inode) spin_unlock(&inode->i_lock)
  556. #define fill_default_sys_attrs(sys_attr, type, mode) \
  557. do { \
  558. sys_attr.owner = from_kuid(current_user_ns(), current_fsuid()); \
  559. sys_attr.group = from_kgid(current_user_ns(), current_fsgid()); \
  560. sys_attr.size = 0; \
  561. sys_attr.perms = ORANGEFS_util_translate_mode(mode); \
  562. sys_attr.objtype = type; \
  563. sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE; \
  564. } while (0)
  565. #define orangefs_inode_lock(__i) mutex_lock(&(__i)->i_mutex)
  566. #define orangefs_inode_unlock(__i) mutex_unlock(&(__i)->i_mutex)
  567. static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size)
  568. {
  569. #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
  570. orangefs_inode_lock(inode);
  571. #endif
  572. i_size_write(inode, i_size);
  573. #if BITS_PER_LONG == 32 && defined(CONFIG_SMP)
  574. orangefs_inode_unlock(inode);
  575. #endif
  576. }
  577. static inline unsigned int diff(struct timeval *end, struct timeval *begin)
  578. {
  579. if (end->tv_usec < begin->tv_usec) {
  580. end->tv_usec += 1000000;
  581. end->tv_sec--;
  582. }
  583. end->tv_sec -= begin->tv_sec;
  584. end->tv_usec -= begin->tv_usec;
  585. return (end->tv_sec * 1000000) + end->tv_usec;
  586. }
  587. #endif /* __ORANGEFSKERNEL_H */