0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef __ORANGEFSKERNEL_H
0020 #define __ORANGEFSKERNEL_H
0021
0022 #include <linux/kernel.h>
0023 #include <linux/moduleparam.h>
0024 #include <linux/statfs.h>
0025 #include <linux/backing-dev.h>
0026 #include <linux/device.h>
0027 #include <linux/mpage.h>
0028 #include <linux/namei.h>
0029 #include <linux/errno.h>
0030 #include <linux/init.h>
0031 #include <linux/module.h>
0032 #include <linux/slab.h>
0033 #include <linux/types.h>
0034 #include <linux/fs.h>
0035 #include <linux/vmalloc.h>
0036
0037 #include <linux/aio.h>
0038 #include <linux/posix_acl.h>
0039 #include <linux/posix_acl_xattr.h>
0040 #include <linux/compat.h>
0041 #include <linux/mount.h>
0042 #include <linux/uaccess.h>
0043 #include <linux/atomic.h>
0044 #include <linux/uio.h>
0045 #include <linux/sched/signal.h>
0046 #include <linux/mm.h>
0047 #include <linux/wait.h>
0048 #include <linux/dcache.h>
0049 #include <linux/pagemap.h>
0050 #include <linux/poll.h>
0051 #include <linux/rwsem.h>
0052 #include <linux/xattr.h>
0053 #include <linux/exportfs.h>
0054 #include <linux/hashtable.h>
0055
0056 #include <asm/unaligned.h>
0057
0058 #include "orangefs-dev-proto.h"
0059
0060 #define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS 20
0061
0062 #define ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS 30
0063
0064 #define ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS 900
0065
0066 #define ORANGEFS_REQDEVICE_NAME "pvfs2-req"
0067
0068 #define ORANGEFS_DEVREQ_MAGIC 0x20030529
0069 #define ORANGEFS_PURGE_RETRY_COUNT 0x00000005
0070
0071 #define MAX_DEV_REQ_UPSIZE (2 * sizeof(__s32) + \
0072 sizeof(__u64) + sizeof(struct orangefs_upcall_s))
0073 #define MAX_DEV_REQ_DOWNSIZE (2 * sizeof(__s32) + \
0074 sizeof(__u64) + sizeof(struct orangefs_downcall_s))
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 enum orangefs_vfs_op_states {
0088 OP_VFS_STATE_UNKNOWN = 0,
0089 OP_VFS_STATE_WAITING = 1,
0090 OP_VFS_STATE_INPROGR = 2,
0091 OP_VFS_STATE_SERVICED = 4,
0092 OP_VFS_STATE_PURGED = 8,
0093 OP_VFS_STATE_GIVEN_UP = 16,
0094 };
0095
0096
0097
0098
0099
0100 #if (defined CONFIG_DEBUG_SLAB)
0101 #define ORANGEFS_CACHE_CREATE_FLAGS SLAB_RED_ZONE
0102 #else
0103 #define ORANGEFS_CACHE_CREATE_FLAGS 0
0104 #endif
0105
0106 extern int orangefs_init_acl(struct inode *inode, struct inode *dir);
0107 extern const struct xattr_handler *orangefs_xattr_handlers[];
0108
0109 extern struct posix_acl *orangefs_get_acl(struct inode *inode, int type, bool rcu);
0110 extern int orangefs_set_acl(struct user_namespace *mnt_userns,
0111 struct inode *inode, struct posix_acl *acl,
0112 int type);
0113
0114
0115
0116
0117 struct orangefs_kernel_op_s {
0118 enum orangefs_vfs_op_states op_state;
0119 __u64 tag;
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129 union {
0130 int uses_shared_memory;
0131 int slot_to_free;
0132 };
0133
0134 struct orangefs_upcall_s upcall;
0135 struct orangefs_downcall_s downcall;
0136
0137 struct completion waitq;
0138 spinlock_t lock;
0139
0140 int attempts;
0141
0142 struct list_head list;
0143 };
0144
0145 #define set_op_state_waiting(op) ((op)->op_state = OP_VFS_STATE_WAITING)
0146 #define set_op_state_inprogress(op) ((op)->op_state = OP_VFS_STATE_INPROGR)
0147 #define set_op_state_given_up(op) ((op)->op_state = OP_VFS_STATE_GIVEN_UP)
0148 static inline void set_op_state_serviced(struct orangefs_kernel_op_s *op)
0149 {
0150 op->op_state = OP_VFS_STATE_SERVICED;
0151 complete(&op->waitq);
0152 }
0153
0154 #define op_state_waiting(op) ((op)->op_state & OP_VFS_STATE_WAITING)
0155 #define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
0156 #define op_state_serviced(op) ((op)->op_state & OP_VFS_STATE_SERVICED)
0157 #define op_state_purged(op) ((op)->op_state & OP_VFS_STATE_PURGED)
0158 #define op_state_given_up(op) ((op)->op_state & OP_VFS_STATE_GIVEN_UP)
0159 #define op_is_cancel(op) ((op)->upcall.type == ORANGEFS_VFS_OP_CANCEL)
0160
0161 void op_release(struct orangefs_kernel_op_s *op);
0162
0163 extern void orangefs_bufmap_put(int);
0164 static inline void put_cancel(struct orangefs_kernel_op_s *op)
0165 {
0166 orangefs_bufmap_put(op->slot_to_free);
0167 op_release(op);
0168 }
0169
0170 static inline void set_op_state_purged(struct orangefs_kernel_op_s *op)
0171 {
0172 spin_lock(&op->lock);
0173 if (unlikely(op_is_cancel(op))) {
0174 list_del_init(&op->list);
0175 spin_unlock(&op->lock);
0176 put_cancel(op);
0177 } else {
0178 op->op_state |= OP_VFS_STATE_PURGED;
0179 complete(&op->waitq);
0180 spin_unlock(&op->lock);
0181 }
0182 }
0183
0184
0185 struct orangefs_inode_s {
0186 struct orangefs_object_kref refn;
0187 char link_target[ORANGEFS_NAME_MAX];
0188
0189
0190
0191
0192 struct rw_semaphore xattr_sem;
0193
0194 struct inode vfs_inode;
0195 sector_t last_failed_block_index_read;
0196
0197 unsigned long getattr_time;
0198 unsigned long mapping_time;
0199 int attr_valid;
0200 kuid_t attr_uid;
0201 kgid_t attr_gid;
0202 unsigned long bitlock;
0203
0204 DECLARE_HASHTABLE(xattr_cache, 4);
0205 };
0206
0207
0208 struct orangefs_sb_info_s {
0209 struct orangefs_khandle root_khandle;
0210 __s32 fs_id;
0211 int id;
0212 int flags;
0213 #define ORANGEFS_OPT_INTR 0x01
0214 #define ORANGEFS_OPT_LOCAL_LOCK 0x02
0215 char devname[ORANGEFS_MAX_SERVER_ADDR_LEN];
0216 struct super_block *sb;
0217 int mount_pending;
0218 int no_list;
0219 struct list_head list;
0220 };
0221
0222 struct orangefs_stats {
0223 unsigned long cache_hits;
0224 unsigned long cache_misses;
0225 unsigned long reads;
0226 unsigned long writes;
0227 };
0228
0229 struct orangefs_cached_xattr {
0230 struct hlist_node node;
0231 char key[ORANGEFS_MAX_XATTR_NAMELEN];
0232 char val[ORANGEFS_MAX_XATTR_VALUELEN];
0233 ssize_t length;
0234 unsigned long timeout;
0235 };
0236
0237 struct orangefs_write_range {
0238 loff_t pos;
0239 size_t len;
0240 kuid_t uid;
0241 kgid_t gid;
0242 };
0243
0244 extern struct orangefs_stats orangefs_stats;
0245
0246
0247
0248
0249
0250 static inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode)
0251 {
0252 return container_of(inode, struct orangefs_inode_s, vfs_inode);
0253 }
0254
0255 static inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb)
0256 {
0257 return (struct orangefs_sb_info_s *) sb->s_fs_info;
0258 }
0259
0260
0261 static inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle)
0262 {
0263 union {
0264 unsigned char u[8];
0265 __u64 ino;
0266 } ihandle;
0267
0268 ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
0269 ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
0270 ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
0271 ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
0272 ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
0273 ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
0274 ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
0275 ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
0276
0277 return ihandle.ino;
0278 }
0279
0280 static inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode)
0281 {
0282 return &(ORANGEFS_I(inode)->refn.khandle);
0283 }
0284
0285 static inline int is_root_handle(struct inode *inode)
0286 {
0287 gossip_debug(GOSSIP_DCACHE_DEBUG,
0288 "%s: root handle: %pU, this handle: %pU:\n",
0289 __func__,
0290 &ORANGEFS_SB(inode->i_sb)->root_khandle,
0291 get_khandle_from_ino(inode));
0292
0293 if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle),
0294 get_khandle_from_ino(inode)))
0295 return 0;
0296 else
0297 return 1;
0298 }
0299
0300 static inline int match_handle(struct orangefs_khandle resp_handle,
0301 struct inode *inode)
0302 {
0303 gossip_debug(GOSSIP_DCACHE_DEBUG,
0304 "%s: one handle: %pU, another handle:%pU:\n",
0305 __func__,
0306 &resp_handle,
0307 get_khandle_from_ino(inode));
0308
0309 if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
0310 return 0;
0311 else
0312 return 1;
0313 }
0314
0315
0316
0317
0318 int op_cache_initialize(void);
0319 int op_cache_finalize(void);
0320 struct orangefs_kernel_op_s *op_alloc(__s32 type);
0321 void orangefs_new_tag(struct orangefs_kernel_op_s *op);
0322 char *get_opname_string(struct orangefs_kernel_op_s *new_op);
0323
0324 int orangefs_inode_cache_initialize(void);
0325 int orangefs_inode_cache_finalize(void);
0326
0327
0328
0329
0330 void purge_inprogress_ops(void);
0331
0332
0333
0334
0335 void purge_waiting_ops(void);
0336
0337
0338
0339
0340 extern uint64_t orangefs_features;
0341
0342 struct dentry *orangefs_mount(struct file_system_type *fst,
0343 int flags,
0344 const char *devname,
0345 void *data);
0346
0347 void orangefs_kill_sb(struct super_block *sb);
0348 int orangefs_remount(struct orangefs_sb_info_s *);
0349
0350 int fsid_key_table_initialize(void);
0351 void fsid_key_table_finalize(void);
0352
0353
0354
0355
0356 vm_fault_t orangefs_page_mkwrite(struct vm_fault *);
0357 struct inode *orangefs_new_inode(struct super_block *sb,
0358 struct inode *dir,
0359 int mode,
0360 dev_t dev,
0361 struct orangefs_object_kref *ref);
0362
0363 int __orangefs_setattr(struct inode *, struct iattr *);
0364 int orangefs_setattr(struct user_namespace *, struct dentry *, struct iattr *);
0365
0366 int orangefs_getattr(struct user_namespace *mnt_userns, const struct path *path,
0367 struct kstat *stat, u32 request_mask, unsigned int flags);
0368
0369 int orangefs_permission(struct user_namespace *mnt_userns,
0370 struct inode *inode, int mask);
0371
0372 int orangefs_update_time(struct inode *, struct timespec64 *, int);
0373
0374
0375
0376
0377 ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size);
0378
0379
0380
0381
0382 struct inode *orangefs_iget(struct super_block *sb,
0383 struct orangefs_object_kref *ref);
0384
0385
0386
0387
0388 extern uint32_t orangefs_userspace_version;
0389
0390 int orangefs_dev_init(void);
0391 void orangefs_dev_cleanup(void);
0392 int is_daemon_in_service(void);
0393 bool __is_daemon_in_service(void);
0394
0395
0396
0397
0398 int orangefs_revalidate_mapping(struct inode *);
0399 ssize_t wait_for_direct_io(enum ORANGEFS_io_type, struct inode *, loff_t *,
0400 struct iov_iter *, size_t, loff_t, struct orangefs_write_range *, int *,
0401 struct file *);
0402 ssize_t do_readv_writev(enum ORANGEFS_io_type, struct file *, loff_t *,
0403 struct iov_iter *);
0404
0405
0406
0407
0408 __s32 fsid_of_op(struct orangefs_kernel_op_s *op);
0409
0410 ssize_t orangefs_inode_getxattr(struct inode *inode,
0411 const char *name,
0412 void *buffer,
0413 size_t size);
0414
0415 int orangefs_inode_setxattr(struct inode *inode,
0416 const char *name,
0417 const void *value,
0418 size_t size,
0419 int flags);
0420
0421 #define ORANGEFS_GETATTR_NEW 1
0422 #define ORANGEFS_GETATTR_SIZE 2
0423
0424 int orangefs_inode_getattr(struct inode *, int);
0425
0426 int orangefs_inode_check_changed(struct inode *inode);
0427
0428 int orangefs_inode_setattr(struct inode *inode);
0429
0430 bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op);
0431
0432 int orangefs_normalize_to_errno(__s32 error_code);
0433
0434 extern struct mutex orangefs_request_mutex;
0435 extern int op_timeout_secs;
0436 extern int slot_timeout_secs;
0437 extern int orangefs_cache_timeout_msecs;
0438 extern int orangefs_dcache_timeout_msecs;
0439 extern int orangefs_getattr_timeout_msecs;
0440 extern struct list_head orangefs_superblocks;
0441 extern spinlock_t orangefs_superblocks_lock;
0442 extern struct list_head orangefs_request_list;
0443 extern spinlock_t orangefs_request_list_lock;
0444 extern wait_queue_head_t orangefs_request_list_waitq;
0445 extern struct list_head *orangefs_htable_ops_in_progress;
0446 extern spinlock_t orangefs_htable_ops_in_progress_lock;
0447 extern int hash_table_size;
0448
0449 extern const struct file_operations orangefs_file_operations;
0450 extern const struct inode_operations orangefs_symlink_inode_operations;
0451 extern const struct inode_operations orangefs_dir_inode_operations;
0452 extern const struct file_operations orangefs_dir_operations;
0453 extern const struct dentry_operations orangefs_dentry_operations;
0454
0455
0456
0457
0458
0459 #define ORANGEFS_OP_INTERRUPTIBLE 1
0460 #define ORANGEFS_OP_PRIORITY 2
0461 #define ORANGEFS_OP_CANCELLATION 4
0462 #define ORANGEFS_OP_NO_MUTEX 8
0463 #define ORANGEFS_OP_ASYNC 16
0464 #define ORANGEFS_OP_WRITEBACK 32
0465
0466 int service_operation(struct orangefs_kernel_op_s *op,
0467 const char *op_name,
0468 int flags);
0469
0470 #define get_interruptible_flag(inode) \
0471 ((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \
0472 ORANGEFS_OP_INTERRUPTIBLE : 0)
0473
0474 #define fill_default_sys_attrs(sys_attr, type, mode) \
0475 do { \
0476 sys_attr.owner = from_kuid(&init_user_ns, current_fsuid()); \
0477 sys_attr.group = from_kgid(&init_user_ns, current_fsgid()); \
0478 sys_attr.perms = ORANGEFS_util_translate_mode(mode); \
0479 sys_attr.mtime = 0; \
0480 sys_attr.atime = 0; \
0481 sys_attr.ctime = 0; \
0482 sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE; \
0483 } while (0)
0484
0485 static inline void orangefs_set_timeout(struct dentry *dentry)
0486 {
0487 unsigned long time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000;
0488
0489 dentry->d_fsdata = (void *) time;
0490 }
0491
0492 #endif