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; 249575e9461SMike Marshall }; 250575e9461SMike Marshall 251575e9461SMike Marshall #define P_ATIME_FLAG 0 252575e9461SMike Marshall #define P_MTIME_FLAG 1 253575e9461SMike Marshall #define P_CTIME_FLAG 2 254575e9461SMike Marshall #define P_MODE_FLAG 3 255575e9461SMike Marshall 256575e9461SMike Marshall #define ClearAtimeFlag(pinode) clear_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) 257575e9461SMike Marshall #define SetAtimeFlag(pinode) set_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) 258575e9461SMike Marshall #define AtimeFlag(pinode) test_bit(P_ATIME_FLAG, &(pinode)->pinode_flags) 259575e9461SMike Marshall 260575e9461SMike Marshall #define ClearMtimeFlag(pinode) clear_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) 261575e9461SMike Marshall #define SetMtimeFlag(pinode) set_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) 262575e9461SMike Marshall #define MtimeFlag(pinode) test_bit(P_MTIME_FLAG, &(pinode)->pinode_flags) 263575e9461SMike Marshall 264575e9461SMike Marshall #define ClearCtimeFlag(pinode) clear_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) 265575e9461SMike Marshall #define SetCtimeFlag(pinode) set_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) 266575e9461SMike Marshall #define CtimeFlag(pinode) test_bit(P_CTIME_FLAG, &(pinode)->pinode_flags) 267575e9461SMike Marshall 268575e9461SMike Marshall #define ClearModeFlag(pinode) clear_bit(P_MODE_FLAG, &(pinode)->pinode_flags) 269575e9461SMike Marshall #define SetModeFlag(pinode) set_bit(P_MODE_FLAG, &(pinode)->pinode_flags) 270575e9461SMike Marshall #define ModeFlag(pinode) test_bit(P_MODE_FLAG, &(pinode)->pinode_flags) 271575e9461SMike Marshall 272575e9461SMike Marshall /* per superblock private orangefs info */ 273575e9461SMike Marshall struct orangefs_sb_info_s { 274575e9461SMike Marshall struct orangefs_khandle root_khandle; 275575e9461SMike Marshall __s32 fs_id; 276575e9461SMike Marshall int id; 277575e9461SMike Marshall int flags; 278575e9461SMike Marshall #define ORANGEFS_OPT_INTR 0x01 279575e9461SMike Marshall #define ORANGEFS_OPT_LOCAL_LOCK 0x02 280575e9461SMike Marshall char devname[ORANGEFS_MAX_SERVER_ADDR_LEN]; 281575e9461SMike Marshall struct super_block *sb; 282575e9461SMike Marshall int mount_pending; 283575e9461SMike Marshall struct list_head list; 284575e9461SMike Marshall }; 285575e9461SMike Marshall 286575e9461SMike Marshall /* 287575e9461SMike Marshall * structure that holds the state of any async I/O operation issued 288575e9461SMike Marshall * through the VFS. Needed especially to handle cancellation requests 289575e9461SMike Marshall * or even completion notification so that the VFS client-side daemon 290575e9461SMike Marshall * can free up its vfs_request slots. 291575e9461SMike Marshall */ 292575e9461SMike Marshall struct orangefs_kiocb_s { 293575e9461SMike Marshall /* the pointer to the task that initiated the AIO */ 294575e9461SMike Marshall struct task_struct *tsk; 295575e9461SMike Marshall 296575e9461SMike Marshall /* pointer to the kiocb that kicked this operation */ 297575e9461SMike Marshall struct kiocb *kiocb; 298575e9461SMike Marshall 299575e9461SMike Marshall /* buffer index that was used for the I/O */ 300575e9461SMike Marshall struct orangefs_bufmap *bufmap; 301575e9461SMike Marshall int buffer_index; 302575e9461SMike Marshall 303575e9461SMike Marshall /* orangefs kernel operation type */ 304575e9461SMike Marshall struct orangefs_kernel_op_s *op; 305575e9461SMike Marshall 306575e9461SMike Marshall /* The user space buffers from/to which I/O is being staged */ 307575e9461SMike Marshall struct iovec *iov; 308575e9461SMike Marshall 309575e9461SMike Marshall /* number of elements in the iovector */ 310575e9461SMike Marshall unsigned long nr_segs; 311575e9461SMike Marshall 312575e9461SMike Marshall /* set to indicate the type of the operation */ 313575e9461SMike Marshall int rw; 314575e9461SMike Marshall 315575e9461SMike Marshall /* file offset */ 316575e9461SMike Marshall loff_t offset; 317575e9461SMike Marshall 318575e9461SMike Marshall /* and the count in bytes */ 319575e9461SMike Marshall size_t bytes_to_be_copied; 320575e9461SMike Marshall 321575e9461SMike Marshall ssize_t bytes_copied; 322575e9461SMike Marshall int needs_cleanup; 323575e9461SMike Marshall }; 324575e9461SMike Marshall 325575e9461SMike Marshall struct orangefs_stats { 326575e9461SMike Marshall unsigned long cache_hits; 327575e9461SMike Marshall unsigned long cache_misses; 328575e9461SMike Marshall unsigned long reads; 329575e9461SMike Marshall unsigned long writes; 330575e9461SMike Marshall }; 331575e9461SMike Marshall 332575e9461SMike Marshall extern struct orangefs_stats g_orangefs_stats; 333575e9461SMike Marshall 334575e9461SMike Marshall /* 335575e9461SMike Marshall * NOTE: See Documentation/filesystems/porting for information 336575e9461SMike Marshall * on implementing FOO_I and properly accessing fs private data 337575e9461SMike Marshall */ 338575e9461SMike Marshall static inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode) 339575e9461SMike Marshall { 340575e9461SMike Marshall return container_of(inode, struct orangefs_inode_s, vfs_inode); 341575e9461SMike Marshall } 342575e9461SMike Marshall 343575e9461SMike Marshall static inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb) 344575e9461SMike Marshall { 345575e9461SMike Marshall return (struct orangefs_sb_info_s *) sb->s_fs_info; 346575e9461SMike Marshall } 347575e9461SMike Marshall 348575e9461SMike Marshall /* ino_t descends from "unsigned long", 8 bytes, 64 bits. */ 349575e9461SMike Marshall static inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle) 350575e9461SMike Marshall { 351575e9461SMike Marshall union { 352575e9461SMike Marshall unsigned char u[8]; 353575e9461SMike Marshall __u64 ino; 354575e9461SMike Marshall } ihandle; 355575e9461SMike Marshall 356575e9461SMike Marshall ihandle.u[0] = khandle->u[0] ^ khandle->u[4]; 357575e9461SMike Marshall ihandle.u[1] = khandle->u[1] ^ khandle->u[5]; 358575e9461SMike Marshall ihandle.u[2] = khandle->u[2] ^ khandle->u[6]; 359575e9461SMike Marshall ihandle.u[3] = khandle->u[3] ^ khandle->u[7]; 360575e9461SMike Marshall ihandle.u[4] = khandle->u[12] ^ khandle->u[8]; 361575e9461SMike Marshall ihandle.u[5] = khandle->u[13] ^ khandle->u[9]; 362575e9461SMike Marshall ihandle.u[6] = khandle->u[14] ^ khandle->u[10]; 363575e9461SMike Marshall ihandle.u[7] = khandle->u[15] ^ khandle->u[11]; 364575e9461SMike Marshall 365575e9461SMike Marshall return ihandle.ino; 366575e9461SMike Marshall } 367575e9461SMike Marshall 368575e9461SMike Marshall static inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode) 369575e9461SMike Marshall { 370575e9461SMike Marshall return &(ORANGEFS_I(inode)->refn.khandle); 371575e9461SMike Marshall } 372575e9461SMike Marshall 373575e9461SMike Marshall static inline __s32 get_fsid_from_ino(struct inode *inode) 374575e9461SMike Marshall { 375575e9461SMike Marshall return ORANGEFS_I(inode)->refn.fs_id; 376575e9461SMike Marshall } 377575e9461SMike Marshall 378575e9461SMike Marshall static inline ino_t get_ino_from_khandle(struct inode *inode) 379575e9461SMike Marshall { 380575e9461SMike Marshall struct orangefs_khandle *khandle; 381575e9461SMike Marshall ino_t ino; 382575e9461SMike Marshall 383575e9461SMike Marshall khandle = get_khandle_from_ino(inode); 384575e9461SMike Marshall ino = orangefs_khandle_to_ino(khandle); 385575e9461SMike Marshall return ino; 386575e9461SMike Marshall } 387575e9461SMike Marshall 388575e9461SMike Marshall static inline ino_t get_parent_ino_from_dentry(struct dentry *dentry) 389575e9461SMike Marshall { 390575e9461SMike Marshall return get_ino_from_khandle(dentry->d_parent->d_inode); 391575e9461SMike Marshall } 392575e9461SMike Marshall 393575e9461SMike Marshall static inline int is_root_handle(struct inode *inode) 394575e9461SMike Marshall { 395575e9461SMike Marshall gossip_debug(GOSSIP_DCACHE_DEBUG, 396575e9461SMike Marshall "%s: root handle: %pU, this handle: %pU:\n", 397575e9461SMike Marshall __func__, 398575e9461SMike Marshall &ORANGEFS_SB(inode->i_sb)->root_khandle, 399575e9461SMike Marshall get_khandle_from_ino(inode)); 400575e9461SMike Marshall 401575e9461SMike Marshall if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle), 402575e9461SMike Marshall get_khandle_from_ino(inode))) 403575e9461SMike Marshall return 0; 404575e9461SMike Marshall else 405575e9461SMike Marshall return 1; 406575e9461SMike Marshall } 407575e9461SMike Marshall 408575e9461SMike Marshall static inline int match_handle(struct orangefs_khandle resp_handle, 409575e9461SMike Marshall struct inode *inode) 410575e9461SMike Marshall { 411575e9461SMike Marshall gossip_debug(GOSSIP_DCACHE_DEBUG, 412575e9461SMike Marshall "%s: one handle: %pU, another handle:%pU:\n", 413575e9461SMike Marshall __func__, 414575e9461SMike Marshall &resp_handle, 415575e9461SMike Marshall get_khandle_from_ino(inode)); 416575e9461SMike Marshall 417575e9461SMike Marshall if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode))) 418575e9461SMike Marshall return 0; 419575e9461SMike Marshall else 420575e9461SMike Marshall return 1; 421575e9461SMike Marshall } 422575e9461SMike Marshall 423575e9461SMike Marshall /* 424575e9461SMike Marshall * defined in orangefs-cache.c 425575e9461SMike Marshall */ 426575e9461SMike Marshall int op_cache_initialize(void); 427575e9461SMike Marshall int op_cache_finalize(void); 428575e9461SMike Marshall struct orangefs_kernel_op_s *op_alloc(__s32 type); 42978699e29SAl Viro void orangefs_new_tag(struct orangefs_kernel_op_s *op); 430575e9461SMike Marshall char *get_opname_string(struct orangefs_kernel_op_s *new_op); 431575e9461SMike Marshall 432575e9461SMike Marshall int orangefs_inode_cache_initialize(void); 433575e9461SMike Marshall int orangefs_inode_cache_finalize(void); 434575e9461SMike Marshall 435575e9461SMike Marshall /* 436575e9461SMike Marshall * defined in orangefs-mod.c 437575e9461SMike Marshall */ 438575e9461SMike Marshall void purge_inprogress_ops(void); 439575e9461SMike Marshall 440575e9461SMike Marshall /* 441575e9461SMike Marshall * defined in waitqueue.c 442575e9461SMike Marshall */ 443575e9461SMike Marshall void purge_waiting_ops(void); 444575e9461SMike Marshall 445575e9461SMike Marshall /* 446575e9461SMike Marshall * defined in super.c 447575e9461SMike Marshall */ 448575e9461SMike Marshall struct dentry *orangefs_mount(struct file_system_type *fst, 449575e9461SMike Marshall int flags, 450575e9461SMike Marshall const char *devname, 451575e9461SMike Marshall void *data); 452575e9461SMike Marshall 453575e9461SMike Marshall void orangefs_kill_sb(struct super_block *sb); 45445996492SAl Viro int orangefs_remount(struct orangefs_sb_info_s *); 455575e9461SMike Marshall 456575e9461SMike Marshall int fsid_key_table_initialize(void); 457575e9461SMike Marshall void fsid_key_table_finalize(void); 458575e9461SMike Marshall 459575e9461SMike Marshall /* 460575e9461SMike Marshall * defined in inode.c 461575e9461SMike Marshall */ 462575e9461SMike Marshall __u32 convert_to_orangefs_mask(unsigned long lite_mask); 463575e9461SMike Marshall struct inode *orangefs_new_inode(struct super_block *sb, 464575e9461SMike Marshall struct inode *dir, 465575e9461SMike Marshall int mode, 466575e9461SMike Marshall dev_t dev, 467575e9461SMike Marshall struct orangefs_object_kref *ref); 468575e9461SMike Marshall 469575e9461SMike Marshall int orangefs_setattr(struct dentry *dentry, struct iattr *iattr); 470575e9461SMike Marshall 471575e9461SMike Marshall int orangefs_getattr(struct vfsmount *mnt, 472575e9461SMike Marshall struct dentry *dentry, 473575e9461SMike Marshall struct kstat *kstat); 474575e9461SMike Marshall 475933287daSMartin Brandenburg int orangefs_permission(struct inode *inode, int mask); 476933287daSMartin Brandenburg 477575e9461SMike Marshall /* 478575e9461SMike Marshall * defined in xattr.c 479575e9461SMike Marshall */ 480575e9461SMike Marshall int orangefs_setxattr(struct dentry *dentry, 481575e9461SMike Marshall const char *name, 482575e9461SMike Marshall const void *value, 483575e9461SMike Marshall size_t size, 484575e9461SMike Marshall int flags); 485575e9461SMike Marshall 486575e9461SMike Marshall ssize_t orangefs_getxattr(struct dentry *dentry, 487575e9461SMike Marshall const char *name, 488575e9461SMike Marshall void *buffer, 489575e9461SMike Marshall size_t size); 490575e9461SMike Marshall 491575e9461SMike Marshall ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size); 492575e9461SMike Marshall 493575e9461SMike Marshall /* 494575e9461SMike Marshall * defined in namei.c 495575e9461SMike Marshall */ 496575e9461SMike Marshall struct inode *orangefs_iget(struct super_block *sb, 497575e9461SMike Marshall struct orangefs_object_kref *ref); 498575e9461SMike Marshall 499575e9461SMike Marshall ssize_t orangefs_inode_read(struct inode *inode, 500575e9461SMike Marshall struct iov_iter *iter, 501575e9461SMike Marshall loff_t *offset, 502575e9461SMike Marshall loff_t readahead_size); 503575e9461SMike Marshall 504575e9461SMike Marshall /* 505575e9461SMike Marshall * defined in devorangefs-req.c 506575e9461SMike Marshall */ 507575e9461SMike Marshall int orangefs_dev_init(void); 508575e9461SMike Marshall void orangefs_dev_cleanup(void); 509575e9461SMike Marshall int is_daemon_in_service(void); 51078699e29SAl Viro bool __is_daemon_in_service(void); 511575e9461SMike Marshall 512575e9461SMike Marshall /* 513575e9461SMike Marshall * defined in orangefs-utils.c 514575e9461SMike Marshall */ 515575e9461SMike Marshall __s32 fsid_of_op(struct orangefs_kernel_op_s *op); 516575e9461SMike Marshall 517575e9461SMike Marshall int orangefs_flush_inode(struct inode *inode); 518575e9461SMike Marshall 519575e9461SMike Marshall ssize_t orangefs_inode_getxattr(struct inode *inode, 520575e9461SMike Marshall const char *name, 521575e9461SMike Marshall void *buffer, 522575e9461SMike Marshall size_t size); 523575e9461SMike Marshall 524575e9461SMike Marshall int orangefs_inode_setxattr(struct inode *inode, 525575e9461SMike Marshall const char *name, 526575e9461SMike Marshall const void *value, 527575e9461SMike Marshall size_t size, 528575e9461SMike Marshall int flags); 529575e9461SMike Marshall 5303c9cf98dSMartin Brandenburg int orangefs_inode_getattr(struct inode *inode, int new, int size); 531575e9461SMike Marshall 5325859d77eSMartin Brandenburg int orangefs_inode_check_changed(struct inode *inode); 5335859d77eSMartin Brandenburg 534575e9461SMike Marshall int orangefs_inode_setattr(struct inode *inode, struct iattr *iattr); 535575e9461SMike Marshall 536575e9461SMike Marshall void orangefs_make_bad_inode(struct inode *inode); 537575e9461SMike Marshall 538575e9461SMike Marshall int orangefs_unmount_sb(struct super_block *sb); 539575e9461SMike Marshall 54078699e29SAl Viro bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op); 541575e9461SMike Marshall 542575e9461SMike Marshall int orangefs_normalize_to_errno(__s32 error_code); 543575e9461SMike Marshall 544575e9461SMike Marshall extern struct mutex devreq_mutex; 545575e9461SMike Marshall extern struct mutex request_mutex; 546575e9461SMike Marshall extern int debug; 547575e9461SMike Marshall extern int op_timeout_secs; 548575e9461SMike Marshall extern int slot_timeout_secs; 549575e9461SMike Marshall extern struct list_head orangefs_superblocks; 550575e9461SMike Marshall extern spinlock_t orangefs_superblocks_lock; 551575e9461SMike Marshall extern struct list_head orangefs_request_list; 552575e9461SMike Marshall extern spinlock_t orangefs_request_list_lock; 553575e9461SMike Marshall extern wait_queue_head_t orangefs_request_list_waitq; 554575e9461SMike Marshall extern struct list_head *htable_ops_in_progress; 555575e9461SMike Marshall extern spinlock_t htable_ops_in_progress_lock; 556575e9461SMike Marshall extern int hash_table_size; 557575e9461SMike Marshall 558575e9461SMike Marshall extern const struct address_space_operations orangefs_address_operations; 559575e9461SMike Marshall extern struct backing_dev_info orangefs_backing_dev_info; 560575e9461SMike Marshall extern struct inode_operations orangefs_file_inode_operations; 561575e9461SMike Marshall extern const struct file_operations orangefs_file_operations; 562575e9461SMike Marshall extern struct inode_operations orangefs_symlink_inode_operations; 563575e9461SMike Marshall extern struct inode_operations orangefs_dir_inode_operations; 564575e9461SMike Marshall extern const struct file_operations orangefs_dir_operations; 565575e9461SMike Marshall extern const struct dentry_operations orangefs_dentry_operations; 566575e9461SMike Marshall extern const struct file_operations orangefs_devreq_file_operations; 567575e9461SMike Marshall 568575e9461SMike Marshall extern wait_queue_head_t orangefs_bufmap_init_waitq; 569575e9461SMike Marshall 570575e9461SMike Marshall /* 571575e9461SMike Marshall * misc convenience macros 572575e9461SMike Marshall */ 573575e9461SMike Marshall 574575e9461SMike Marshall #define ORANGEFS_OP_INTERRUPTIBLE 1 /* service_operation() is interruptible */ 575575e9461SMike Marshall #define ORANGEFS_OP_PRIORITY 2 /* service_operation() is high priority */ 576575e9461SMike Marshall #define ORANGEFS_OP_CANCELLATION 4 /* this is a cancellation */ 577adcf34a2SMike Marshall #define ORANGEFS_OP_NO_MUTEX 8 /* don't acquire request_mutex */ 578575e9461SMike Marshall #define ORANGEFS_OP_ASYNC 16 /* Queue it, but don't wait */ 579575e9461SMike Marshall 580575e9461SMike Marshall int service_operation(struct orangefs_kernel_op_s *op, 581575e9461SMike Marshall const char *op_name, 582575e9461SMike Marshall int flags); 583575e9461SMike Marshall 584575e9461SMike Marshall #define get_interruptible_flag(inode) \ 585575e9461SMike Marshall ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \ 586575e9461SMike Marshall ORANGEFS_OP_INTERRUPTIBLE : 0) 587575e9461SMike Marshall 588575e9461SMike Marshall #define fill_default_sys_attrs(sys_attr, type, mode) \ 589575e9461SMike Marshall do { \ 59078fee0b6SJann Horn sys_attr.owner = from_kuid(&init_user_ns, current_fsuid()); \ 59178fee0b6SJann Horn sys_attr.group = from_kgid(&init_user_ns, current_fsgid()); \ 592575e9461SMike Marshall sys_attr.perms = ORANGEFS_util_translate_mode(mode); \ 59369a23de2SMartin Brandenburg sys_attr.mtime = 0; \ 59469a23de2SMartin Brandenburg sys_attr.atime = 0; \ 59569a23de2SMartin Brandenburg sys_attr.ctime = 0; \ 596575e9461SMike Marshall sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE; \ 597575e9461SMike Marshall } while (0) 598575e9461SMike Marshall 599575e9461SMike Marshall static inline void orangefs_i_size_write(struct inode *inode, loff_t i_size) 600575e9461SMike Marshall { 601575e9461SMike Marshall #if BITS_PER_LONG == 32 && defined(CONFIG_SMP) 6025ecfcb26SAl Viro inode_lock(inode); 603575e9461SMike Marshall #endif 604575e9461SMike Marshall i_size_write(inode, i_size); 605575e9461SMike Marshall #if BITS_PER_LONG == 32 && defined(CONFIG_SMP) 6065ecfcb26SAl Viro inode_unlock(inode); 607575e9461SMike Marshall #endif 608575e9461SMike Marshall } 609575e9461SMike Marshall 610575e9461SMike Marshall #endif /* __ORANGEFSKERNEL_H */ 611