162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * (C) 2001 Clemson University and The University of Chicago
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * See COPYING in top-level directory.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/*
962306a36Sopenharmony_ci *  The ORANGEFS Linux kernel support allows ORANGEFS volumes to be mounted and
1062306a36Sopenharmony_ci *  accessed through the Linux VFS (i.e. using standard I/O system calls).
1162306a36Sopenharmony_ci *  This support is only needed on clients that wish to mount the file system.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/*
1662306a36Sopenharmony_ci *  Declarations and macros for the ORANGEFS Linux kernel support.
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#ifndef __ORANGEFSKERNEL_H
2062306a36Sopenharmony_ci#define __ORANGEFSKERNEL_H
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#include <linux/kernel.h>
2362306a36Sopenharmony_ci#include <linux/moduleparam.h>
2462306a36Sopenharmony_ci#include <linux/statfs.h>
2562306a36Sopenharmony_ci#include <linux/backing-dev.h>
2662306a36Sopenharmony_ci#include <linux/device.h>
2762306a36Sopenharmony_ci#include <linux/mpage.h>
2862306a36Sopenharmony_ci#include <linux/namei.h>
2962306a36Sopenharmony_ci#include <linux/errno.h>
3062306a36Sopenharmony_ci#include <linux/init.h>
3162306a36Sopenharmony_ci#include <linux/module.h>
3262306a36Sopenharmony_ci#include <linux/slab.h>
3362306a36Sopenharmony_ci#include <linux/types.h>
3462306a36Sopenharmony_ci#include <linux/fs.h>
3562306a36Sopenharmony_ci#include <linux/vmalloc.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#include <linux/aio.h>
3862306a36Sopenharmony_ci#include <linux/posix_acl.h>
3962306a36Sopenharmony_ci#include <linux/posix_acl_xattr.h>
4062306a36Sopenharmony_ci#include <linux/compat.h>
4162306a36Sopenharmony_ci#include <linux/mount.h>
4262306a36Sopenharmony_ci#include <linux/uaccess.h>
4362306a36Sopenharmony_ci#include <linux/atomic.h>
4462306a36Sopenharmony_ci#include <linux/uio.h>
4562306a36Sopenharmony_ci#include <linux/sched/signal.h>
4662306a36Sopenharmony_ci#include <linux/mm.h>
4762306a36Sopenharmony_ci#include <linux/wait.h>
4862306a36Sopenharmony_ci#include <linux/dcache.h>
4962306a36Sopenharmony_ci#include <linux/pagemap.h>
5062306a36Sopenharmony_ci#include <linux/poll.h>
5162306a36Sopenharmony_ci#include <linux/rwsem.h>
5262306a36Sopenharmony_ci#include <linux/xattr.h>
5362306a36Sopenharmony_ci#include <linux/exportfs.h>
5462306a36Sopenharmony_ci#include <linux/hashtable.h>
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#include <asm/unaligned.h>
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#include "orangefs-dev-proto.h"
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define ORANGEFS_DEFAULT_OP_TIMEOUT_SECS       20
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define ORANGEFS_BUFMAP_WAIT_TIMEOUT_SECS   30
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#define ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS     900	/* 15 minutes */
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define ORANGEFS_REQDEVICE_NAME          "pvfs2-req"
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define ORANGEFS_DEVREQ_MAGIC             0x20030529
6962306a36Sopenharmony_ci#define ORANGEFS_PURGE_RETRY_COUNT     0x00000005
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define MAX_DEV_REQ_UPSIZE (2 * sizeof(__s32) +   \
7262306a36Sopenharmony_cisizeof(__u64) + sizeof(struct orangefs_upcall_s))
7362306a36Sopenharmony_ci#define MAX_DEV_REQ_DOWNSIZE (2 * sizeof(__s32) + \
7462306a36Sopenharmony_cisizeof(__u64) + sizeof(struct orangefs_downcall_s))
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci/*
7762306a36Sopenharmony_ci * valid orangefs kernel operation states
7862306a36Sopenharmony_ci *
7962306a36Sopenharmony_ci * unknown  - op was just initialized
8062306a36Sopenharmony_ci * waiting  - op is on request_list (upward bound)
8162306a36Sopenharmony_ci * inprogr  - op is in progress (waiting for downcall)
8262306a36Sopenharmony_ci * serviced - op has matching downcall; ok
8362306a36Sopenharmony_ci * purged   - op has to start a timer since client-core
8462306a36Sopenharmony_ci *            exited uncleanly before servicing op
8562306a36Sopenharmony_ci * given up - submitter has given up waiting for it
8662306a36Sopenharmony_ci */
8762306a36Sopenharmony_cienum orangefs_vfs_op_states {
8862306a36Sopenharmony_ci	OP_VFS_STATE_UNKNOWN = 0,
8962306a36Sopenharmony_ci	OP_VFS_STATE_WAITING = 1,
9062306a36Sopenharmony_ci	OP_VFS_STATE_INPROGR = 2,
9162306a36Sopenharmony_ci	OP_VFS_STATE_SERVICED = 4,
9262306a36Sopenharmony_ci	OP_VFS_STATE_PURGED = 8,
9362306a36Sopenharmony_ci	OP_VFS_STATE_GIVEN_UP = 16,
9462306a36Sopenharmony_ci};
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/*
9762306a36Sopenharmony_ci * orangefs kernel memory related flags
9862306a36Sopenharmony_ci */
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#if (defined CONFIG_DEBUG_SLAB)
10162306a36Sopenharmony_ci#define ORANGEFS_CACHE_CREATE_FLAGS SLAB_RED_ZONE
10262306a36Sopenharmony_ci#else
10362306a36Sopenharmony_ci#define ORANGEFS_CACHE_CREATE_FLAGS 0
10462306a36Sopenharmony_ci#endif
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciextern const struct xattr_handler *orangefs_xattr_handlers[];
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciextern struct posix_acl *orangefs_get_acl(struct inode *inode, int type, bool rcu);
10962306a36Sopenharmony_ciextern int orangefs_set_acl(struct mnt_idmap *idmap,
11062306a36Sopenharmony_ci			    struct dentry *dentry, struct posix_acl *acl,
11162306a36Sopenharmony_ci			    int type);
11262306a36Sopenharmony_ciint __orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci/*
11562306a36Sopenharmony_ci * orangefs data structures
11662306a36Sopenharmony_ci */
11762306a36Sopenharmony_cistruct orangefs_kernel_op_s {
11862306a36Sopenharmony_ci	enum orangefs_vfs_op_states op_state;
11962306a36Sopenharmony_ci	__u64 tag;
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci	/*
12262306a36Sopenharmony_ci	 * Set uses_shared_memory to non zero if this operation uses
12362306a36Sopenharmony_ci	 * shared memory. If true, then a retry on the op must also
12462306a36Sopenharmony_ci	 * get a new shared memory buffer and re-populate it.
12562306a36Sopenharmony_ci	 * Cancels don't care - it only matters for service_operation()
12662306a36Sopenharmony_ci	 * retry logics and cancels don't go through it anymore. It
12762306a36Sopenharmony_ci	 * safely stays non-zero when we use it as slot_to_free.
12862306a36Sopenharmony_ci	 */
12962306a36Sopenharmony_ci	union {
13062306a36Sopenharmony_ci		int uses_shared_memory;
13162306a36Sopenharmony_ci		int slot_to_free;
13262306a36Sopenharmony_ci	};
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	struct orangefs_upcall_s upcall;
13562306a36Sopenharmony_ci	struct orangefs_downcall_s downcall;
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	struct completion waitq;
13862306a36Sopenharmony_ci	spinlock_t lock;
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	int attempts;
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci	struct list_head list;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci#define set_op_state_waiting(op)     ((op)->op_state = OP_VFS_STATE_WAITING)
14662306a36Sopenharmony_ci#define set_op_state_inprogress(op)  ((op)->op_state = OP_VFS_STATE_INPROGR)
14762306a36Sopenharmony_ci#define set_op_state_given_up(op)  ((op)->op_state = OP_VFS_STATE_GIVEN_UP)
14862306a36Sopenharmony_cistatic inline void set_op_state_serviced(struct orangefs_kernel_op_s *op)
14962306a36Sopenharmony_ci{
15062306a36Sopenharmony_ci	op->op_state = OP_VFS_STATE_SERVICED;
15162306a36Sopenharmony_ci	complete(&op->waitq);
15262306a36Sopenharmony_ci}
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#define op_state_waiting(op)     ((op)->op_state & OP_VFS_STATE_WAITING)
15562306a36Sopenharmony_ci#define op_state_in_progress(op) ((op)->op_state & OP_VFS_STATE_INPROGR)
15662306a36Sopenharmony_ci#define op_state_serviced(op)    ((op)->op_state & OP_VFS_STATE_SERVICED)
15762306a36Sopenharmony_ci#define op_state_purged(op)      ((op)->op_state & OP_VFS_STATE_PURGED)
15862306a36Sopenharmony_ci#define op_state_given_up(op)    ((op)->op_state & OP_VFS_STATE_GIVEN_UP)
15962306a36Sopenharmony_ci#define op_is_cancel(op)         ((op)->upcall.type == ORANGEFS_VFS_OP_CANCEL)
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_civoid op_release(struct orangefs_kernel_op_s *op);
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ciextern void orangefs_bufmap_put(int);
16462306a36Sopenharmony_cistatic inline void put_cancel(struct orangefs_kernel_op_s *op)
16562306a36Sopenharmony_ci{
16662306a36Sopenharmony_ci	orangefs_bufmap_put(op->slot_to_free);
16762306a36Sopenharmony_ci	op_release(op);
16862306a36Sopenharmony_ci}
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_cistatic inline void set_op_state_purged(struct orangefs_kernel_op_s *op)
17162306a36Sopenharmony_ci{
17262306a36Sopenharmony_ci	spin_lock(&op->lock);
17362306a36Sopenharmony_ci	if (unlikely(op_is_cancel(op))) {
17462306a36Sopenharmony_ci		list_del_init(&op->list);
17562306a36Sopenharmony_ci		spin_unlock(&op->lock);
17662306a36Sopenharmony_ci		put_cancel(op);
17762306a36Sopenharmony_ci	} else {
17862306a36Sopenharmony_ci		op->op_state |= OP_VFS_STATE_PURGED;
17962306a36Sopenharmony_ci		complete(&op->waitq);
18062306a36Sopenharmony_ci		spin_unlock(&op->lock);
18162306a36Sopenharmony_ci	}
18262306a36Sopenharmony_ci}
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/* per inode private orangefs info */
18562306a36Sopenharmony_cistruct orangefs_inode_s {
18662306a36Sopenharmony_ci	struct orangefs_object_kref refn;
18762306a36Sopenharmony_ci	char link_target[ORANGEFS_NAME_MAX];
18862306a36Sopenharmony_ci	/*
18962306a36Sopenharmony_ci	 * Reading/Writing Extended attributes need to acquire the appropriate
19062306a36Sopenharmony_ci	 * reader/writer semaphore on the orangefs_inode_s structure.
19162306a36Sopenharmony_ci	 */
19262306a36Sopenharmony_ci	struct rw_semaphore xattr_sem;
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci	struct inode vfs_inode;
19562306a36Sopenharmony_ci	sector_t last_failed_block_index_read;
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci	unsigned long getattr_time;
19862306a36Sopenharmony_ci	unsigned long mapping_time;
19962306a36Sopenharmony_ci	int attr_valid;
20062306a36Sopenharmony_ci	kuid_t attr_uid;
20162306a36Sopenharmony_ci	kgid_t attr_gid;
20262306a36Sopenharmony_ci	unsigned long bitlock;
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci	DECLARE_HASHTABLE(xattr_cache, 4);
20562306a36Sopenharmony_ci};
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci/* per superblock private orangefs info */
20862306a36Sopenharmony_cistruct orangefs_sb_info_s {
20962306a36Sopenharmony_ci	struct orangefs_khandle root_khandle;
21062306a36Sopenharmony_ci	__s32 fs_id;
21162306a36Sopenharmony_ci	int id;
21262306a36Sopenharmony_ci	int flags;
21362306a36Sopenharmony_ci#define ORANGEFS_OPT_INTR	0x01
21462306a36Sopenharmony_ci#define ORANGEFS_OPT_LOCAL_LOCK	0x02
21562306a36Sopenharmony_ci	char devname[ORANGEFS_MAX_SERVER_ADDR_LEN];
21662306a36Sopenharmony_ci	struct super_block *sb;
21762306a36Sopenharmony_ci	int mount_pending;
21862306a36Sopenharmony_ci	int no_list;
21962306a36Sopenharmony_ci	struct list_head list;
22062306a36Sopenharmony_ci};
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_cistruct orangefs_stats {
22362306a36Sopenharmony_ci	unsigned long cache_hits;
22462306a36Sopenharmony_ci	unsigned long cache_misses;
22562306a36Sopenharmony_ci	unsigned long reads;
22662306a36Sopenharmony_ci	unsigned long writes;
22762306a36Sopenharmony_ci};
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_cistruct orangefs_cached_xattr {
23062306a36Sopenharmony_ci	struct hlist_node node;
23162306a36Sopenharmony_ci	char key[ORANGEFS_MAX_XATTR_NAMELEN];
23262306a36Sopenharmony_ci	char val[ORANGEFS_MAX_XATTR_VALUELEN];
23362306a36Sopenharmony_ci	ssize_t length;
23462306a36Sopenharmony_ci	unsigned long timeout;
23562306a36Sopenharmony_ci};
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_cistruct orangefs_write_range {
23862306a36Sopenharmony_ci	loff_t pos;
23962306a36Sopenharmony_ci	size_t len;
24062306a36Sopenharmony_ci	kuid_t uid;
24162306a36Sopenharmony_ci	kgid_t gid;
24262306a36Sopenharmony_ci};
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ciextern struct orangefs_stats orangefs_stats;
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci/*
24762306a36Sopenharmony_ci * NOTE: See Documentation/filesystems/porting.rst for information
24862306a36Sopenharmony_ci * on implementing FOO_I and properly accessing fs private data
24962306a36Sopenharmony_ci */
25062306a36Sopenharmony_cistatic inline struct orangefs_inode_s *ORANGEFS_I(struct inode *inode)
25162306a36Sopenharmony_ci{
25262306a36Sopenharmony_ci	return container_of(inode, struct orangefs_inode_s, vfs_inode);
25362306a36Sopenharmony_ci}
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_cistatic inline struct orangefs_sb_info_s *ORANGEFS_SB(struct super_block *sb)
25662306a36Sopenharmony_ci{
25762306a36Sopenharmony_ci	return (struct orangefs_sb_info_s *) sb->s_fs_info;
25862306a36Sopenharmony_ci}
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci/* ino_t descends from "unsigned long", 8 bytes, 64 bits. */
26162306a36Sopenharmony_cistatic inline ino_t orangefs_khandle_to_ino(struct orangefs_khandle *khandle)
26262306a36Sopenharmony_ci{
26362306a36Sopenharmony_ci	union {
26462306a36Sopenharmony_ci		unsigned char u[8];
26562306a36Sopenharmony_ci		__u64 ino;
26662306a36Sopenharmony_ci	} ihandle;
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci	ihandle.u[0] = khandle->u[0] ^ khandle->u[4];
26962306a36Sopenharmony_ci	ihandle.u[1] = khandle->u[1] ^ khandle->u[5];
27062306a36Sopenharmony_ci	ihandle.u[2] = khandle->u[2] ^ khandle->u[6];
27162306a36Sopenharmony_ci	ihandle.u[3] = khandle->u[3] ^ khandle->u[7];
27262306a36Sopenharmony_ci	ihandle.u[4] = khandle->u[12] ^ khandle->u[8];
27362306a36Sopenharmony_ci	ihandle.u[5] = khandle->u[13] ^ khandle->u[9];
27462306a36Sopenharmony_ci	ihandle.u[6] = khandle->u[14] ^ khandle->u[10];
27562306a36Sopenharmony_ci	ihandle.u[7] = khandle->u[15] ^ khandle->u[11];
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci	return ihandle.ino;
27862306a36Sopenharmony_ci}
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_cistatic inline struct orangefs_khandle *get_khandle_from_ino(struct inode *inode)
28162306a36Sopenharmony_ci{
28262306a36Sopenharmony_ci	return &(ORANGEFS_I(inode)->refn.khandle);
28362306a36Sopenharmony_ci}
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_cistatic inline int is_root_handle(struct inode *inode)
28662306a36Sopenharmony_ci{
28762306a36Sopenharmony_ci	gossip_debug(GOSSIP_DCACHE_DEBUG,
28862306a36Sopenharmony_ci		     "%s: root handle: %pU, this handle: %pU:\n",
28962306a36Sopenharmony_ci		     __func__,
29062306a36Sopenharmony_ci		     &ORANGEFS_SB(inode->i_sb)->root_khandle,
29162306a36Sopenharmony_ci		     get_khandle_from_ino(inode));
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	if (ORANGEFS_khandle_cmp(&(ORANGEFS_SB(inode->i_sb)->root_khandle),
29462306a36Sopenharmony_ci			     get_khandle_from_ino(inode)))
29562306a36Sopenharmony_ci		return 0;
29662306a36Sopenharmony_ci	else
29762306a36Sopenharmony_ci		return 1;
29862306a36Sopenharmony_ci}
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistatic inline int match_handle(struct orangefs_khandle resp_handle,
30162306a36Sopenharmony_ci			       struct inode *inode)
30262306a36Sopenharmony_ci{
30362306a36Sopenharmony_ci	gossip_debug(GOSSIP_DCACHE_DEBUG,
30462306a36Sopenharmony_ci		     "%s: one handle: %pU, another handle:%pU:\n",
30562306a36Sopenharmony_ci		     __func__,
30662306a36Sopenharmony_ci		     &resp_handle,
30762306a36Sopenharmony_ci		     get_khandle_from_ino(inode));
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	if (ORANGEFS_khandle_cmp(&resp_handle, get_khandle_from_ino(inode)))
31062306a36Sopenharmony_ci		return 0;
31162306a36Sopenharmony_ci	else
31262306a36Sopenharmony_ci		return 1;
31362306a36Sopenharmony_ci}
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci/*
31662306a36Sopenharmony_ci * defined in orangefs-cache.c
31762306a36Sopenharmony_ci */
31862306a36Sopenharmony_ciint op_cache_initialize(void);
31962306a36Sopenharmony_ciint op_cache_finalize(void);
32062306a36Sopenharmony_cistruct orangefs_kernel_op_s *op_alloc(__s32 type);
32162306a36Sopenharmony_civoid orangefs_new_tag(struct orangefs_kernel_op_s *op);
32262306a36Sopenharmony_cichar *get_opname_string(struct orangefs_kernel_op_s *new_op);
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ciint orangefs_inode_cache_initialize(void);
32562306a36Sopenharmony_ciint orangefs_inode_cache_finalize(void);
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci/*
32862306a36Sopenharmony_ci * defined in orangefs-mod.c
32962306a36Sopenharmony_ci */
33062306a36Sopenharmony_civoid purge_inprogress_ops(void);
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci/*
33362306a36Sopenharmony_ci * defined in waitqueue.c
33462306a36Sopenharmony_ci */
33562306a36Sopenharmony_civoid purge_waiting_ops(void);
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci/*
33862306a36Sopenharmony_ci * defined in super.c
33962306a36Sopenharmony_ci */
34062306a36Sopenharmony_ciextern uint64_t orangefs_features;
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_cistruct dentry *orangefs_mount(struct file_system_type *fst,
34362306a36Sopenharmony_ci			   int flags,
34462306a36Sopenharmony_ci			   const char *devname,
34562306a36Sopenharmony_ci			   void *data);
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_civoid orangefs_kill_sb(struct super_block *sb);
34862306a36Sopenharmony_ciint orangefs_remount(struct orangefs_sb_info_s *);
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ciint fsid_key_table_initialize(void);
35162306a36Sopenharmony_civoid fsid_key_table_finalize(void);
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_ci/*
35462306a36Sopenharmony_ci * defined in inode.c
35562306a36Sopenharmony_ci */
35662306a36Sopenharmony_civm_fault_t orangefs_page_mkwrite(struct vm_fault *);
35762306a36Sopenharmony_cistruct inode *orangefs_new_inode(struct super_block *sb,
35862306a36Sopenharmony_ci			      struct inode *dir,
35962306a36Sopenharmony_ci			      umode_t mode,
36062306a36Sopenharmony_ci			      dev_t dev,
36162306a36Sopenharmony_ci			      struct orangefs_object_kref *ref);
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ciint __orangefs_setattr(struct inode *, struct iattr *);
36462306a36Sopenharmony_ciint __orangefs_setattr_mode(struct dentry *dentry, struct iattr *iattr);
36562306a36Sopenharmony_ciint orangefs_setattr(struct mnt_idmap *, struct dentry *, struct iattr *);
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ciint orangefs_getattr(struct mnt_idmap *idmap, const struct path *path,
36862306a36Sopenharmony_ci		     struct kstat *stat, u32 request_mask, unsigned int flags);
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ciint orangefs_permission(struct mnt_idmap *idmap,
37162306a36Sopenharmony_ci			struct inode *inode, int mask);
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ciint orangefs_update_time(struct inode *, int);
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci/*
37662306a36Sopenharmony_ci * defined in xattr.c
37762306a36Sopenharmony_ci */
37862306a36Sopenharmony_cissize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size);
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci/*
38162306a36Sopenharmony_ci * defined in namei.c
38262306a36Sopenharmony_ci */
38362306a36Sopenharmony_cistruct inode *orangefs_iget(struct super_block *sb,
38462306a36Sopenharmony_ci			 struct orangefs_object_kref *ref);
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ci/*
38762306a36Sopenharmony_ci * defined in devorangefs-req.c
38862306a36Sopenharmony_ci */
38962306a36Sopenharmony_ciextern uint32_t orangefs_userspace_version;
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ciint orangefs_dev_init(void);
39262306a36Sopenharmony_civoid orangefs_dev_cleanup(void);
39362306a36Sopenharmony_ciint is_daemon_in_service(void);
39462306a36Sopenharmony_cibool __is_daemon_in_service(void);
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ci/*
39762306a36Sopenharmony_ci * defined in file.c
39862306a36Sopenharmony_ci */
39962306a36Sopenharmony_ciint orangefs_revalidate_mapping(struct inode *);
40062306a36Sopenharmony_cissize_t wait_for_direct_io(enum ORANGEFS_io_type, struct inode *, loff_t *,
40162306a36Sopenharmony_ci    struct iov_iter *, size_t, loff_t, struct orangefs_write_range *, int *,
40262306a36Sopenharmony_ci    struct file *);
40362306a36Sopenharmony_cissize_t do_readv_writev(enum ORANGEFS_io_type, struct file *, loff_t *,
40462306a36Sopenharmony_ci    struct iov_iter *);
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci/*
40762306a36Sopenharmony_ci * defined in orangefs-utils.c
40862306a36Sopenharmony_ci */
40962306a36Sopenharmony_ci__s32 fsid_of_op(struct orangefs_kernel_op_s *op);
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_cissize_t orangefs_inode_getxattr(struct inode *inode,
41262306a36Sopenharmony_ci			     const char *name,
41362306a36Sopenharmony_ci			     void *buffer,
41462306a36Sopenharmony_ci			     size_t size);
41562306a36Sopenharmony_ci
41662306a36Sopenharmony_ciint orangefs_inode_setxattr(struct inode *inode,
41762306a36Sopenharmony_ci			 const char *name,
41862306a36Sopenharmony_ci			 const void *value,
41962306a36Sopenharmony_ci			 size_t size,
42062306a36Sopenharmony_ci			 int flags);
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci#define ORANGEFS_GETATTR_NEW 1
42362306a36Sopenharmony_ci#define ORANGEFS_GETATTR_SIZE 2
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_ciint orangefs_inode_getattr(struct inode *, int);
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ciint orangefs_inode_check_changed(struct inode *inode);
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ciint orangefs_inode_setattr(struct inode *inode);
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_cibool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op);
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_ciint orangefs_normalize_to_errno(__s32 error_code);
43462306a36Sopenharmony_ci
43562306a36Sopenharmony_ciextern struct mutex orangefs_request_mutex;
43662306a36Sopenharmony_ciextern int op_timeout_secs;
43762306a36Sopenharmony_ciextern int slot_timeout_secs;
43862306a36Sopenharmony_ciextern int orangefs_cache_timeout_msecs;
43962306a36Sopenharmony_ciextern int orangefs_dcache_timeout_msecs;
44062306a36Sopenharmony_ciextern int orangefs_getattr_timeout_msecs;
44162306a36Sopenharmony_ciextern struct list_head orangefs_superblocks;
44262306a36Sopenharmony_ciextern spinlock_t orangefs_superblocks_lock;
44362306a36Sopenharmony_ciextern struct list_head orangefs_request_list;
44462306a36Sopenharmony_ciextern spinlock_t orangefs_request_list_lock;
44562306a36Sopenharmony_ciextern wait_queue_head_t orangefs_request_list_waitq;
44662306a36Sopenharmony_ciextern struct list_head *orangefs_htable_ops_in_progress;
44762306a36Sopenharmony_ciextern spinlock_t orangefs_htable_ops_in_progress_lock;
44862306a36Sopenharmony_ciextern int hash_table_size;
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ciextern const struct file_operations orangefs_file_operations;
45162306a36Sopenharmony_ciextern const struct inode_operations orangefs_symlink_inode_operations;
45262306a36Sopenharmony_ciextern const struct inode_operations orangefs_dir_inode_operations;
45362306a36Sopenharmony_ciextern const struct file_operations orangefs_dir_operations;
45462306a36Sopenharmony_ciextern const struct dentry_operations orangefs_dentry_operations;
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci/*
45762306a36Sopenharmony_ci * misc convenience macros
45862306a36Sopenharmony_ci */
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci#define ORANGEFS_OP_INTERRUPTIBLE 1   /* service_operation() is interruptible */
46162306a36Sopenharmony_ci#define ORANGEFS_OP_PRIORITY      2   /* service_operation() is high priority */
46262306a36Sopenharmony_ci#define ORANGEFS_OP_CANCELLATION  4   /* this is a cancellation */
46362306a36Sopenharmony_ci#define ORANGEFS_OP_NO_MUTEX      8   /* don't acquire request_mutex */
46462306a36Sopenharmony_ci#define ORANGEFS_OP_ASYNC         16  /* Queue it, but don't wait */
46562306a36Sopenharmony_ci#define ORANGEFS_OP_WRITEBACK     32
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_ciint service_operation(struct orangefs_kernel_op_s *op,
46862306a36Sopenharmony_ci		      const char *op_name,
46962306a36Sopenharmony_ci		      int flags);
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci#define get_interruptible_flag(inode) \
47262306a36Sopenharmony_ci	((ORANGEFS_SB(inode->i_sb)->flags & ORANGEFS_OPT_INTR) ? \
47362306a36Sopenharmony_ci		ORANGEFS_OP_INTERRUPTIBLE : 0)
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci#define fill_default_sys_attrs(sys_attr, type, mode)			\
47662306a36Sopenharmony_cido {									\
47762306a36Sopenharmony_ci	sys_attr.owner = from_kuid(&init_user_ns, current_fsuid()); \
47862306a36Sopenharmony_ci	sys_attr.group = from_kgid(&init_user_ns, current_fsgid()); \
47962306a36Sopenharmony_ci	sys_attr.perms = ORANGEFS_util_translate_mode(mode);		\
48062306a36Sopenharmony_ci	sys_attr.mtime = 0;						\
48162306a36Sopenharmony_ci	sys_attr.atime = 0;						\
48262306a36Sopenharmony_ci	sys_attr.ctime = 0;						\
48362306a36Sopenharmony_ci	sys_attr.mask = ORANGEFS_ATTR_SYS_ALL_SETABLE;			\
48462306a36Sopenharmony_ci} while (0)
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_cistatic inline void orangefs_set_timeout(struct dentry *dentry)
48762306a36Sopenharmony_ci{
48862306a36Sopenharmony_ci	unsigned long time = jiffies + orangefs_dcache_timeout_msecs*HZ/1000;
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ci	dentry->d_fsdata = (void *) time;
49162306a36Sopenharmony_ci}
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci#endif /* __ORANGEFSKERNEL_H */
494