1575e9461SMike Marshall /* 2575e9461SMike Marshall * (C) 2001 Clemson University and The University of Chicago 3575e9461SMike Marshall * 4575e9461SMike Marshall * See COPYING in top-level directory. 5575e9461SMike Marshall */ 6575e9461SMike Marshall 7575e9461SMike Marshall /* 8575e9461SMike Marshall * The ORANGEFS Linux kernel support allows ORANGEFS volumes to be mounted and 9575e9461SMike Marshall * accessed through the Linux VFS (i.e. using standard I/O system calls). 10575e9461SMike Marshall * This support is only needed on clients that wish to mount the file system. 11575e9461SMike Marshall * 12575e9461SMike Marshall */ 13575e9461SMike Marshall 14575e9461SMike Marshall /* 15575e9461SMike Marshall * Declarations and macros for the ORANGEFS Linux kernel support. 16575e9461SMike Marshall */ 17575e9461SMike Marshall 18575e9461SMike Marshall #ifndef __ORANGEFSKERNEL_H 19575e9461SMike Marshall #define __ORANGEFSKERNEL_H 20575e9461SMike Marshall 21575e9461SMike Marshall #include <linux/kernel.h> 22575e9461SMike Marshall #include <linux/moduleparam.h> 23575e9461SMike Marshall #include <linux/statfs.h> 24575e9461SMike Marshall #include <linux/backing-dev.h> 25575e9461SMike Marshall #include <linux/device.h> 26575e9461SMike Marshall #include <linux/mpage.h> 27575e9461SMike Marshall #include <linux/namei.h> 28575e9461SMike Marshall #include <linux/errno.h> 29575e9461SMike Marshall #include <linux/init.h> 30575e9461SMike Marshall #include <linux/module.h> 31575e9461SMike Marshall #include <linux/slab.h> 32575e9461SMike Marshall #include <linux/types.h> 33575e9461SMike Marshall #include <linux/fs.h> 34575e9461SMike Marshall #include <linux/vmalloc.h> 35575e9461SMike Marshall 36575e9461SMike Marshall #include <linux/aio.h> 37575e9461SMike Marshall #include <linux/posix_acl.h> 38575e9461SMike Marshall #include <linux/posix_acl_xattr.h> 39575e9461SMike Marshall #include <linux/compat.h> 40575e9461SMike Marshall #include <linux/mount.h> 41575e9461SMike Marshall #include <linux/uaccess.h> 42575e9461SMike Marshall #include <linux/atomic.h> 43575e9461SMike Marshall #include <linux/uio.h> 44575e9461SMike Marshall #include <linux/sched.h> 45575e9461SMike Marshall #include <linux/mm.h> 46575e9461SMike Marshall #include <linux/wait.h> 47575e9461SMike Marshall #include <linux/dcache.h> 48575e9461SMike Marshall #include <linux/pagemap.h> 49575e9461SMike Marshall #include <linux/poll.h> 50575e9461SMike Marshall #include <linux/rwsem.h> 51575e9461SMike Marshall #include <linux/xattr.h> 52575e9461SMike Marshall #include <linux/exportfs.h> 53575e9461SMike Marshall 54575e9461SMike Marshall #include <asm/unaligned.h> 55575e9461SMike Marshall 56575e9461SMike Marshall #include "orangefs-dev-proto.h" 57575e9461SMike Marshall 58575e9461SMike Marshall #ifdef ORANGEFS_KERNEL_DEBUG 59575e9461SMike Marshall #define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 10 60575e9461SMike Marshall #else 61575e9461SMike Marshall #define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 20 62575e9461SMike Marshall #endif 63575e9461SMike Marshall 64575e9461SMike Marshall #define ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS 30 65575e9461SMike Marshall 66575e9461SMike Marshall #define ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS 900 /* 15 minutes */ 67575e9461SMike Marshall 68575e9461SMike Marshall #define ORANGEFS_REQDEVICE_NAME "pvfs2-req" 69575e9461SMike Marshall 70575e9461SMike Marshall #define ORANGEFS_DEVREQ_MAGIC 0x20030529 71575e9461SMike Marshall #define ORANGEFS_LINK_MAX 0x000000FF 72575e9461SMike Marshall #define ORANGEFS_PURGE_RETRY_COUNT 0x00000005 73575e9461SMike Marshall #define ORANGEFS_MAX_NUM_OPTIONS 0x00000004 74575e9461SMike Marshall #define ORANGEFS_MAX_MOUNT_OPT_LEN 0x00000080 75575e9461SMike Marshall #define ORANGEFS_MAX_FSKEY_LEN 64 76575e9461SMike Marshall 77575e9461SMike Marshall #define MAX_DEV_REQ_UPSIZE (2 * sizeof(__s32) + \ 78575e9461SMike Marshall sizeof(__u64) + sizeof(struct orangefs_upcall_s)) 79575e9461SMike Marshall #define MAX_DEV_REQ_DOWNSIZE (2 * sizeof(__s32) + \ 80575e9461SMike Marshall sizeof(__u64) + sizeof(struct orangefs_downcall_s)) 81575e9461SMike Marshall 82575e9461SMike Marshall /* 83575e9461SMike Marshall * valid orangefs kernel operation states 84575e9461SMike Marshall * 85575e9461SMike Marshall * unknown - op was just initialized 86575e9461SMike Marshall * waiting - op is on request_list (upward bound) 87575e9461SMike Marshall * inprogr - op is in progress (waiting for downcall) 88575e9461SMike Marshall * serviced - op has matching downcall; ok 89575e9461SMike Marshall * purged - op has to start a timer since client-core 90575e9461SMike Marshall * exited uncleanly before servicing op 91ed42fe05SAl Viro * given up - submitter has given up waiting for it 92575e9461SMike Marshall */ 93575e9461SMike Marshall enum orangefs_vfs_op_states { 94575e9461SMike Marshall OP_VFS_STATE_UNKNOWN = 0, 95575e9461SMike Marshall OP_VFS_STATE_WAITING = 1, 96575e9461SMike Marshall OP_VFS_STATE_INPROGR = 2, 97575e9461SMike Marshall OP_VFS_STATE_SERVICED = 4, 98575e9461SMike Marshall OP_VFS_STATE_PURGED = 8, 99ed42fe05SAl Viro OP_VFS_STATE_GIVEN_UP = 16, 100575e9461SMike Marshall }; 101575e9461SMike Marshall 102575e9461SMike Marshall /* 103575e9461SMike Marshall * An array of client_debug_mask will be built to hold debug keyword/mask 104575e9461SMike Marshall * values fetched from userspace. 105575e9461SMike Marshall */ 106575e9461SMike Marshall struct client_debug_mask { 107575e9461SMike Marshall char *keyword; 108575e9461SMike Marshall __u64 mask1; 109575e9461SMike Marshall __u64 mask2; 110575e9461SMike Marshall }; 111575e9461SMike Marshall 112575e9461SMike Marshall /* 113575e9461SMike Marshall * orangefs kernel memory related flags 114575e9461SMike Marshall */ 115575e9461SMike Marshall 116575e9461SMike Marshall #if ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) 117575e9461SMike Marshall #define ORANGEFS_CACHE_CREATE_FLAGS SLAB_RED_ZONE 118575e9461SMike Marshall #else 119575e9461SMike Marshall #define ORANGEFS_CACHE_CREATE_FLAGS 0 120575e9461SMike Marshall #endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */ 121575e9461SMike Marshall 122575e9461SMike Marshall /* these functions are defined in orangefs-utils.c */ 123575e9461SMike Marshall int orangefs_prepare_cdm_array(char *debug_array_string); 124575e9461SMike Marshall int orangefs_prepare_debugfs_help_string(int); 125575e9461SMike Marshall 126575e9461SMike Marshall /* defined in orangefs-debugfs.c */ 127575e9461SMike Marshall int orangefs_client_debug_init(void); 128575e9461SMike Marshall 129575e9461SMike Marshall void debug_string_to_mask(char *, void *, int); 130575e9461SMike Marshall void do_c_mask(int, char *, struct client_debug_mask **); 131575e9461SMike Marshall void do_k_mask(int, char *, __u64 **); 132575e9461SMike Marshall 133575e9461SMike Marshall void debug_mask_to_string(void *, int); 134575e9461SMike Marshall void do_k_string(void *, int); 135575e9461SMike Marshall void do_c_string(void *, int); 136575e9461SMike Marshall int check_amalgam_keyword(void *, int); 137575e9461SMike Marshall int keyword_is_amalgam(char *); 138575e9461SMike Marshall 139575e9461SMike Marshall /*these variables are defined in orangefs-mod.c */ 140575e9461SMike Marshall extern char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN]; 141575e9461SMike Marshall extern char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN]; 142575e9461SMike Marshall extern char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN]; 143575e9461SMike Marshall extern unsigned int kernel_mask_set_mod_init; 144575e9461SMike Marshall 145575e9461SMike Marshall extern int orangefs_init_acl(struct inode *inode, struct inode *dir); 146575e9461SMike Marshall extern const struct xattr_handler *orangefs_xattr_handlers[]; 147575e9461SMike Marshall 148575e9461SMike Marshall extern struct posix_acl *orangefs_get_acl(struct inode *inode, int type); 149575e9461SMike Marshall extern int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type); 150575e9461SMike Marshall 151575e9461SMike Marshall /* 152575e9461SMike Marshall * Redefine xtvec structure so that we could move helper functions out of 153575e9461SMike Marshall * the define 154575e9461SMike Marshall */ 155575e9461SMike Marshall struct xtvec { 156575e9461SMike Marshall __kernel_off_t xtv_off; /* must be off_t */ 157575e9461SMike Marshall __kernel_size_t xtv_len; /* must be size_t */ 158575e9461SMike Marshall }; 159575e9461SMike Marshall 160575e9461SMike Marshall /* 161575e9461SMike Marshall * orangefs data structures 162575e9461SMike Marshall */ 163575e9461SMike Marshall struct orangefs_kernel_op_s { 164575e9461SMike Marshall enum orangefs_vfs_op_states op_state; 165575e9461SMike Marshall __u64 tag; 166575e9461SMike Marshall 167575e9461SMike Marshall /* 168d37c0f30SMike Marshall * Set uses_shared_memory to non zero if this operation uses 169d37c0f30SMike Marshall * shared memory. If true, then a retry on the op must also 170d37c0f30SMike Marshall * get a new shared memory buffer and re-populate it. 171d37c0f30SMike Marshall * Cancels don't care - it only matters for service_operation() 172d37c0f30SMike Marshall * retry logics and cancels don't go through it anymore. It 173d37c0f30SMike Marshall * safely stays non-zero when we use it as slot_to_free. 174575e9461SMike Marshall */ 17578699e29SAl Viro union { 176575e9461SMike Marshall int uses_shared_memory; 17778699e29SAl Viro int slot_to_free; 17878699e29SAl Viro }; 179575e9461SMike Marshall 180575e9461SMike Marshall struct orangefs_upcall_s upcall; 181575e9461SMike Marshall struct orangefs_downcall_s downcall; 182575e9461SMike Marshall 183d2d87a3bSAl Viro struct completion waitq; 184575e9461SMike Marshall spinlock_t lock; 185575e9461SMike Marshall 186575e9461SMike Marshall int attempts; 187575e9461SMike Marshall 188575e9461SMike Marshall struct list_head list; 189575e9461SMike Marshall }; 190575e9461SMike Marshall 19160831949SAl Viro #define set_op_state_waiting(op) ((op)->op_state = OP_VFS_STATE_WAITING) 19260831949SAl Viro #define set_op_state_inprogress(op) ((op)->op_state = OP_VFS_STATE_INPROGR) 1932d4cae0dSMike Marshall #define set_op_state_given_up(op) ((op)->op_state = OP_VFS_STATE_GIVEN_UP) 19460831949SAl Viro static inline void set_op_state_serviced(struct orangefs_kernel_op_s *op) 19560831949SAl Viro { 19660831949SAl Viro op->op_state = OP_VFS_STATE_SERVICED; 197d2d87a3bSAl Viro complete(&op->waitq); 19860831949SAl Viro } 19960831949SAl Viro 20060831949SAl Viro #define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING) 20160831949SAl Viro #define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR) 20260831949SAl Viro #define op_state_serviced(op) ((op)->op_state & OP_VFS_STATE_SERVICED) 20360831949SAl Viro #define op_state_purged(op) ((op)->op_state & OP_VFS_STATE_PURGED) 204ed42fe05SAl Viro #define op_state_given_up(op) ((op)->op_state & OP_VFS_STATE_GIVEN_UP) 20578699e29SAl Viro #define op_is_cancel(op) ((op)->upcall.type == ORANGEFS_VFS_OP_CANCEL) 206ed42fe05SAl Viro 207c1223ca4SAl Viro void op_release(struct orangefs_kernel_op_s *op); 20860831949SAl Viro 20978699e29SAl Viro extern void orangefs_bufmap_put(int); 21078699e29SAl Viro static inline void put_cancel(struct orangefs_kernel_op_s *op) 21178699e29SAl Viro { 21278699e29SAl Viro orangefs_bufmap_put(op->slot_to_free); 21378699e29SAl Viro op_release(op); 21478699e29SAl Viro } 21578699e29SAl Viro 21678699e29SAl Viro static inline void set_op_state_purged(struct orangefs_kernel_op_s *op) 21778699e29SAl Viro { 21878699e29SAl Viro spin_lock(&op->lock); 21978699e29SAl Viro if (unlikely(op_is_cancel(op))) { 22005a50a5bSAl Viro list_del_init(&op->list); 22178699e29SAl Viro spin_unlock(&op->lock); 22278699e29SAl Viro put_cancel(op); 22378699e29SAl Viro } else { 22478699e29SAl Viro op->op_state |= OP_VFS_STATE_PURGED; 225d2d87a3bSAl Viro complete(&op->waitq); 22678699e29SAl Viro spin_unlock(&op->lock); 22778699e29SAl Viro } 22878699e29SAl Viro } 22978699e29SAl Viro 230575e9461SMike Marshall /* per inode private orangefs info */ 231575e9461SMike Marshall struct orangefs_inode_s { 232575e9461SMike Marshall struct orangefs_object_kref refn; 233575e9461SMike Marshall char link_target[ORANGEFS_NAME_MAX]; 234575e9461SMike Marshall __s64 blksize; 235575e9461SMike Marshall /* 236575e9461SMike Marshall * Reading/Writing Extended attributes need to acquire the appropriate 237575e9461SMike Marshall * reader/writer semaphore on the orangefs_inode_s structure. 238575e9461SMike Marshall */ 239575e9461SMike Marshall struct rw_semaphore xattr_sem; 240575e9461SMike Marshall 241575e9461SMike Marshall struct inode vfs_inode; 242575e9461SMike Marshall sector_t last_failed_block_index_read; 243575e9461SMike Marshall 244575e9461SMike Marshall /* 245575e9461SMike Marshall * State of in-memory attributes not yet flushed to disk associated 246575e9461SMike Marshall * with this object 247575e9461SMike Marshall */ 248575e9461SMike Marshall unsigned long pinode_flags; 24971680c18SMartin Brandenburg 25071680c18SMartin Brandenburg unsigned long getattr_time; 251575e9461SMike Marshall }; 252575e9461SMike Marshall 253575e9461SMike Marshall #define P_ATIME_FLAG 0 254575e9461SMike Marshall #define P_MTIME_FLAG 1 255575e9461SMike Marshall #define P_CTIME_FLAG 2 256575e9461SMike Marshall #define P_MODE_FLAG 3 257575e9461SMike Marshall 258575e9461SMike Marshall #define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) 259575e9461SMike Marshall #define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) 260575e9461SMike Marshall #define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) 261575e9461SMike Marshall 262575e9461SMike Marshall #define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) 263575e9461SMike Marshall #define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) 264575e9461SMike Marshall #define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) 265575e9461SMike Marshall 266575e9461SMike Marshall #define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) 267575e9461SMike Marshall #define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) 268575e9461SMike Marshall #define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) 269575e9461SMike Marshall 270575e9461SMike Marshall #define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags) 271575e9461SMike Marshall #define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags) 272575e9461SMike Marshall #define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags) 273575e9461SMike Marshall 274575e9461SMike Marshall /* per superblock private orangefs info */ 275575e9461SMike Marshall struct orangefs_sb_info_s { 276575e9461SMike Marshall struct orangefs_khandle root_khandle; 277575e9461SMike Marshall __s32 fs_id; 278575e9461SMike Marshall int id; 279575e9461SMike Marshall int flags; 280575e9461SMike Marshall #define ORANGEFS_OPT_INTR 0x01 281575e9461SMike Marshall #define ORANGEFS_OPT_LOCAL_LOCK 0x02 282575e9461SMike Marshall char devname[ORANGEFS_MAX_SERVER_ADDR_LEN]; 283575e9461SMike Marshall struct super_block *sb; 284575e9461SMike Marshall int mount_pending; 285575e9461SMike Marshall struct list_head list; 286575e9461SMike Marshall }; 287575e9461SMike Marshall 288575e9461SMike Marshall /* 289575e9461SMike Marshall * structure that holds the state of any async I/O operation issued 290575e9461SMike Marshall * through the VFS. Needed especially to handle cancellation requests 291575e9461SMike Marshall * or even completion notification so that the VFS client-side daemon 292575e9461SMike Marshall * can free up its vfs_request slots. 293575e9461SMike Marshall */ 294575e9461SMike Marshall struct orangefs_kiocb_s { 295575e9461SMike Marshall /* the pointer to the task that initiated the AIO */ 296575e9461SMike Marshall struct task_struct *tsk; 297575e9461SMike Marshall 298575e9461SMike Marshall /* pointer to the kiocb that kicked this operation */ 299575e9461SMike Marshall struct kiocb *kiocb; 300575e9461SMike Marshall 301575e9461SMike Marshall /* buffer index that was used for the I/O */ 302575e9461SMike Marshall struct orangefs_bufmap *bufmap; 303575e9461SMike Marshall int buffer_index; 304575e9461SMike Marshall 305575e9461SMike Marshall /* orangefs kernel operation type */ 306575e9461SMike Marshall struct orangefs_kernel_op_s *op; 307575e9461SMike Marshall 308575e9461SMike Marshall /* The user space buffers from/to which I/O is being staged */ 309575e9461SMike Marshall struct iovec *iov; 310575e9461SMike Marshall 311575e9461SMike Marshall /* number of elements in the iovector */ 312575e9461SMike Marshall unsigned long nr_segs; 313575e9461SMike Marshall 314575e9461SMike Marshall /* set to indicate the type of the operation */ 315575e9461SMike Marshall int rw; 316575e9461SMike Marshall 317575e9461SMike Marshall /* file offset */ 318575e9461SMike Marshall loff_t offset; 319575e9461SMike Marshall 320575e9461SMike Marshall /* and the count in bytes */ 321575e9461SMike Marshall size_t bytes_to_be_copied; 322575e9461SMike Marshall 323575e9461SMike Marshall ssize_t bytes_copied; 324575e9461SMike Marshall int needs_cleanup; 325575e9461SMike Marshall }; 326575e9461SMike Marshall 327575e9461SMike Marshall struct orangefs_stats { 328575e9461SMike Marshall unsigned long cache_hits; 329575e9461SMike Marshall unsigned long cache_misses; 330575e9461SMike Marshall unsigned long reads; 331575e9461SMike Marshall unsigned long writes; 332575e9461SMike Marshall }; 333575e9461SMike Marshall 334575e9461SMike Marshall extern struct orangefs_stats g_orangefs_stats; 335575e9461SMike Marshall 336575e9461SMike Marshall /* 337575e9461SMike Marshall * NOTE: See Documentation/filesystems/porting for information 338575e9461SMike Marshall * on implementing FOO_I and properly accessing fs private data 339575e9461SMike Marshall */ 340575e9461SMike Marshall static inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode) 341575e9461SMike Marshall { 342575e9461SMike Marshall return container_of(inode, struct orangefs_inode_s, vfs_inode); 343575e9461SMike Marshall } 344575e9461SMike Marshall 345575e9461SMike Marshall static inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb) 346575e9461SMike Marshall { 347575e9461SMike Marshall return (struct orangefs_sb_info_s *) sb->s_fs_info; 348575e9461SMike Marshall } 349575e9461SMike Marshall 350575e9461SMike Marshall /* ino_t descends from "unsigned long", 8 bytes, 64 bits. */ 351575e9461SMike Marshall static inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle) 352575e9461SMike Marshall { 353575e9461SMike Marshall union { 354575e9461SMike Marshall unsigned char u[8]; 355575e9461SMike Marshall __u64 ino; 356575e9461SMike Marshall } ihandle; 357575e9461SMike Marshall 358575e9461SMike Marshall ihandle.u[0] = khandle->u[0] ^ khandle->u[4]; 359575e9461SMike Marshall ihandle.u[1] = khandle->u[1] ^ khandle->u[5]; 360575e9461SMike Marshall ihandle.u[2] = khandle->u[2] ^ khandle->u[6]; 361575e9461SMike Marshall ihandle.u[3] = khandle->u[3] ^ khandle->u[7]; 362575e9461SMike Marshall ihandle.u[4] = khandle->u[12] ^ khandle->u[8]; 363575e9461SMike Marshall ihandle.u[5] = khandle->u[13] ^ khandle->u[9]; 364575e9461SMike Marshall ihandle.u[6] = khandle->u[14] ^ khandle->u[10]; 365575e9461SMike Marshall ihandle.u[7] = khandle->u[15] ^ khandle->u[11]; 366575e9461SMike Marshall 367575e9461SMike Marshall return ihandle.ino; 368575e9461SMike Marshall } 369575e9461SMike Marshall 370575e9461SMike Marshall static inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode) 371575e9461SMike Marshall { 372575e9461SMike Marshall return &(ORANGEFS_I(inode)->refn.khandle); 373575e9461SMike Marshall } 374575e9461SMike Marshall 375575e9461SMike Marshall static inline __s32 get_fsid_from_ino(struct inode *inode) 376575e9461SMike Marshall { 377575e9461SMike Marshall return ORANGEFS_I(inode)->refn.fs_id; 378575e9461SMike Marshall } 379575e9461SMike Marshall 380575e9461SMike Marshall static inline ino_t get_ino_from_khandle(struct inode *inode) 381575e9461SMike Marshall { 382575e9461SMike Marshall struct orangefs_khandle *khandle; 383575e9461SMike Marshall ino_t ino; 384575e9461SMike Marshall 385575e9461SMike Marshall khandle = get_khandle_from_ino(inode); 386575e9461SMike Marshall ino = orangefs_khandle_to_ino(khandle); 387575e9461SMike Marshall return ino; 388575e9461SMike Marshall } 389575e9461SMike Marshall 390575e9461SMike Marshall static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry) 391575e9461SMike Marshall { 392575e9461SMike Marshall return get_ino_from_khandle(dentry->d_parent->d_inode); 393575e9461SMike Marshall } 394575e9461SMike Marshall 395575e9461SMike Marshall static inline int is_root_handle(struct inode *inode) 396575e9461SMike Marshall { 397575e9461SMike Marshall gossip_debug(GOSSIP_DCACHE_DEBUG, 398575e9461SMike Marshall "%s: root handle: %pU, this handle: %pU:\n", 399575e9461SMike Marshall __func__, 400575e9461SMike Marshall &ORANGEFS_SB(inode->i_sb)->root_khandle, 401575e9461SMike Marshall get_khandle_from_ino(inode)); 402575e9461SMike Marshall 403575e9461SMike Marshall if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle), 404575e9461SMike Marshall get_khandle_from_ino(inode))) 405575e9461SMike Marshall return 0; 406575e9461SMike Marshall else 407575e9461SMike Marshall return 1; 408575e9461SMike Marshall } 409575e9461SMike Marshall 410575e9461SMike Marshall static inline int match_handle(struct orangefs_khandle resp_handle, 411575e9461SMike Marshall struct inode *inode) 412575e9461SMike Marshall { 413575e9461SMike Marshall gossip_debug(GOSSIP_DCACHE_DEBUG, 414575e9461SMike Marshall "%s: one handle: %pU, another handle:%pU:\n", 415575e9461SMike Marshall __func__, 416575e9461SMike Marshall &resp_handle, 417575e9461SMike Marshall get_khandle_from_ino(inode)); 418575e9461SMike Marshall 419575e9461SMike Marshall if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode))) 420575e9461SMike Marshall return 0; 421575e9461SMike Marshall else 422575e9461SMike Marshall return 1; 423575e9461SMike Marshall } 424575e9461SMike Marshall 425575e9461SMike Marshall /* 426575e9461SMike Marshall * defined in orangefs-cache.c 427575e9461SMike Marshall */ 428575e9461SMike Marshall int op_cache_initialize(void); 429575e9461SMike Marshall int op_cache_finalize(void); 430575e9461SMike Marshall struct orangefs_kernel_op_s *op_alloc(__s32 type); 43178699e29SAl Viro void orangefs_new_tag(struct orangefs_kernel_op_s *op); 432575e9461SMike Marshall char *get_opname_string(struct orangefs_kernel_op_s *new_op); 433575e9461SMike Marshall 434575e9461SMike Marshall int orangefs_inode_cache_initialize(void); 435575e9461SMike Marshall int orangefs_inode_cache_finalize(void); 436575e9461SMike Marshall 437575e9461SMike Marshall /* 438575e9461SMike Marshall * defined in orangefs-mod.c 439575e9461SMike Marshall */ 440575e9461SMike Marshall void purge_inprogress_ops(void); 441575e9461SMike Marshall 442575e9461SMike Marshall /* 443575e9461SMike Marshall * defined in waitqueue.c 444575e9461SMike Marshall */ 445575e9461SMike Marshall void purge_waiting_ops(void); 446575e9461SMike Marshall 447575e9461SMike Marshall /* 448575e9461SMike Marshall * defined in super.c 449575e9461SMike Marshall */ 450575e9461SMike Marshall struct dentry *orangefs_mount(struct file_system_type *fst, 451575e9461SMike Marshall int flags, 452575e9461SMike Marshall const char *devname, 453575e9461SMike Marshall void *data); 454575e9461SMike Marshall 455575e9461SMike Marshall void orangefs_kill_sb(struct super_block *sb); 45645996492SAl Viro int orangefs_remount(struct orangefs_sb_info_s *); 457575e9461SMike Marshall 458575e9461SMike Marshall int fsid_key_table_initialize(void); 459575e9461SMike Marshall void fsid_key_table_finalize(void); 460575e9461SMike Marshall 461575e9461SMike Marshall /* 462575e9461SMike Marshall * defined in inode.c 463575e9461SMike Marshall */ 464575e9461SMike Marshall __u32 convert_to_orangefs_mask(unsigned long lite_mask); 465575e9461SMike Marshall struct inode *orangefs_new_inode(struct super_block *sb, 466575e9461SMike Marshall struct inode *dir, 467575e9461SMike Marshall int mode, 468575e9461SMike Marshall dev_t dev, 469575e9461SMike Marshall struct orangefs_object_kref *ref); 470575e9461SMike Marshall 471575e9461SMike Marshall int orangefs_setattr(struct dentry *dentry, struct iattr *iattr); 472575e9461SMike Marshall 473575e9461SMike Marshall int orangefs_getattr(struct vfsmount *mnt, 474575e9461SMike Marshall struct dentry *dentry, 475575e9461SMike Marshall struct kstat *kstat); 476575e9461SMike Marshall 477933287daSMartin Brandenburg int orangefs_permission(struct inode *inode, int mask); 478933287daSMartin Brandenburg 479575e9461SMike Marshall /* 480575e9461SMike Marshall * defined in xattr.c 481575e9461SMike Marshall */ 482575e9461SMike Marshall int orangefs_setxattr(struct dentry *dentry, 483575e9461SMike Marshall const char *name, 484575e9461SMike Marshall const void *value, 485575e9461SMike Marshall size_t size, 486575e9461SMike Marshall int flags); 487575e9461SMike Marshall 488575e9461SMike Marshall ssize_t orangefs_getxattr(struct dentry *dentry, 489575e9461SMike Marshall const char *name, 490575e9461SMike Marshall void *buffer, 491575e9461SMike Marshall size_t size); 492575e9461SMike Marshall 493575e9461SMike Marshall ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size); 494575e9461SMike Marshall 495575e9461SMike Marshall /* 496575e9461SMike Marshall * defined in namei.c 497575e9461SMike Marshall */ 498575e9461SMike Marshall struct inode *orangefs_iget(struct super_block *sb, 499575e9461SMike Marshall struct orangefs_object_kref *ref); 500575e9461SMike Marshall 501575e9461SMike Marshall ssize_t orangefs_inode_read(struct inode *inode, 502575e9461SMike Marshall struct iov_iter *iter, 503575e9461SMike Marshall loff_t *offset, 504575e9461SMike Marshall loff_t readahead_size); 505575e9461SMike Marshall 506575e9461SMike Marshall /* 507575e9461SMike Marshall * defined in devorangefs-req.c 508575e9461SMike Marshall */ 509575e9461SMike Marshall int orangefs_dev_init(void); 510575e9461SMike Marshall void orangefs_dev_cleanup(void); 511575e9461SMike Marshall int is_daemon_in_service(void); 51278699e29SAl Viro bool __is_daemon_in_service(void); 513575e9461SMike Marshall 514575e9461SMike Marshall /* 515575e9461SMike Marshall * defined in orangefs-utils.c 516575e9461SMike Marshall */ 517575e9461SMike Marshall __s32 fsid_of_op(struct orangefs_kernel_op_s *op); 518575e9461SMike Marshall 519575e9461SMike Marshall int orangefs_flush_inode(struct inode *inode); 520575e9461SMike Marshall 521575e9461SMike Marshall ssize_t orangefs_inode_getxattr(struct inode *inode, 522575e9461SMike Marshall const char *name, 523575e9461SMike Marshall void *buffer, 524575e9461SMike Marshall size_t size); 525575e9461SMike Marshall 526575e9461SMike Marshall int orangefs_inode_setxattr(struct inode *inode, 527575e9461SMike Marshall const char *name, 528575e9461SMike Marshall const void *value, 529575e9461SMike Marshall size_t size, 530575e9461SMike Marshall int flags); 531575e9461SMike Marshall 53271680c18SMartin Brandenburg int orangefs_inode_getattr(struct inode *inode, int new, int bypass); 533575e9461SMike Marshall 5345859d77eSMartin Brandenburg int orangefs_inode_check_changed(struct inode *inode); 5355859d77eSMartin Brandenburg 536575e9461SMike Marshall int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr); 537575e9461SMike Marshall 538575e9461SMike Marshall void orangefs_make_bad_inode(struct inode *inode); 539575e9461SMike Marshall 540575e9461SMike Marshall int orangefs_unmount_sb(struct super_block *sb); 541575e9461SMike Marshall 54278699e29SAl Viro bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op); 543575e9461SMike Marshall 544575e9461SMike Marshall int orangefs_normalize_to_errno(__s32 error_code); 545575e9461SMike Marshall 546575e9461SMike Marshall extern struct mutex devreq_mutex; 547575e9461SMike Marshall extern struct mutex request_mutex; 548575e9461SMike Marshall extern int debug; 549575e9461SMike Marshall extern int op_timeout_secs; 550575e9461SMike Marshall extern int slot_timeout_secs; 551575e9461SMike Marshall extern struct list_head orangefs_superblocks; 552575e9461SMike Marshall extern spinlock_t orangefs_superblocks_lock; 553575e9461SMike Marshall extern struct list_head orangefs_request_list; 554575e9461SMike Marshall extern spinlock_t orangefs_request_list_lock; 555575e9461SMike Marshall extern wait_queue_head_t orangefs_request_list_waitq; 556575e9461SMike Marshall extern struct list_head *htable_ops_in_progress; 557575e9461SMike Marshall extern spinlock_t htable_ops_in_progress_lock; 558575e9461SMike Marshall extern int hash_table_size; 559575e9461SMike Marshall 560575e9461SMike Marshall extern const struct address_space_operations orangefs_address_operations; 561575e9461SMike Marshall extern struct backing_dev_info orangefs_backing_dev_info; 5626f3fc107SAl Viro extern const struct inode_operations orangefs_file_inode_operations; 563575e9461SMike Marshall extern const struct file_operations orangefs_file_operations; 5646f3fc107SAl Viro extern const struct inode_operations orangefs_symlink_inode_operations; 5656f3fc107SAl Viro extern const struct inode_operations orangefs_dir_inode_operations; 566575e9461SMike Marshall extern const struct file_operations orangefs_dir_operations; 567575e9461SMike Marshall extern const struct dentry_operations orangefs_dentry_operations; 568575e9461SMike Marshall extern const struct file_operations orangefs_devreq_file_operations; 569575e9461SMike Marshall 570575e9461SMike Marshall extern wait_queue_head_t orangefs_bufmap_init_waitq; 571575e9461SMike Marshall 572575e9461SMike Marshall /* 573575e9461SMike Marshall * misc convenience macros 574575e9461SMike Marshall */ 575575e9461SMike Marshall 576575e9461SMike Marshall #define ORANGEFS_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */ 577575e9461SMike Marshall #define ORANGEFS_OP_PRIORITY 2 /* service_operation() is high priority */ 578575e9461SMike Marshall #define ORANGEFS_OP_CANCELLATION 4 /* this is a cancellation */ 579adcf34a2SMike Marshall #define ORANGEFS_OP_NO_MUTEX 8 /* don't acquire request_mutex */ 580575e9461SMike Marshall #define ORANGEFS_OP_ASYNC 16 /* Queue it, but don't wait */ 581575e9461SMike Marshall 582575e9461SMike Marshall int service_operation(struct orangefs_kernel_op_s *op, 583575e9461SMike Marshall const char *op_name, 584575e9461SMike Marshall int flags); 585575e9461SMike Marshall 586575e9461SMike Marshall #define get_interruptible_flag(inode) \ 587575e9461SMike Marshall ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \ 588575e9461SMike Marshall ORANGEFS_OP_INTERRUPTIBLE : 0) 589575e9461SMike Marshall 590575e9461SMike Marshall #define fill_default_sys_attrs(sys_attr, type, mode) \ 591575e9461SMike Marshall do { \ 59278fee0b6SJann Horn sys_attr.owner = from_kuid(&init_user_ns, current_fsuid()); \ 59378fee0b6SJann Horn sys_attr.group = from_kgid(&init_user_ns, current_fsgid()); \ 594575e9461SMike Marshall sys_attr.perms = ORANGEFS_util_translate_mode(mode); \ 59569a23de2SMartin Brandenburg sys_attr.mtime = 0; \ 59669a23de2SMartin Brandenburg sys_attr.atime = 0; \ 59769a23de2SMartin Brandenburg sys_attr.ctime = 0; \ 598575e9461SMike Marshall sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE; \ 599575e9461SMike Marshall } while (0) 600575e9461SMike Marshall 601575e9461SMike Marshall static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size) 602575e9461SMike Marshall { 603575e9461SMike Marshall #if BITS_PER_LONG == 32 && defined(CONFIG_SMP) 6045ecfcb26SAl Viro inode_lock(inode); 605575e9461SMike Marshall #endif 606575e9461SMike Marshall i_size_write(inode, i_size); 607575e9461SMike Marshall #if BITS_PER_LONG == 32 && defined(CONFIG_SMP) 6085ecfcb26SAl Viro inode_unlock(inode); 609575e9461SMike Marshall #endif 610575e9461SMike Marshall } 611575e9461SMike Marshall 612575e9461SMike Marshall #endif /* __ORANGEFSKERNEL_H */ 613