1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * fs/hmdfs/hmdfs_client.h
4 *
5 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
6 */
7
8#ifndef HMDFS_CLIENT_H
9#define HMDFS_CLIENT_H
10
11#include "comm/transport.h"
12#include "hmdfs_dentryfile.h"
13#include "hmdfs_device_view.h"
14
15struct hmdfs_open_ret {
16	struct hmdfs_fid fid;
17	__u64 file_size;
18	__u64 ino;
19	struct hmdfs_time_t remote_ctime;
20	struct hmdfs_time_t stable_ctime;
21};
22
23struct hmdfs_writepage_context {
24	struct hmdfs_fid fid;
25	uint32_t count;
26	bool sync_all;
27	bool rsem_held;
28	unsigned long timeout;
29	struct task_struct *caller;
30	struct page *page;
31	struct delayed_work retry_dwork;
32};
33
34int hmdfs_client_start_readdir(struct hmdfs_peer *con, struct file *filp,
35			       const char *path, int path_len,
36			       struct hmdfs_dcache_header *header);
37int hmdfs_client_start_mkdir(struct hmdfs_peer *con,
38			     const char *path, const char *name,
39			     umode_t mode, struct hmdfs_lookup_ret *mkdir_ret);
40int hmdfs_client_start_create(struct hmdfs_peer *con,
41			      const char *path, const char *name,
42			      umode_t mode, bool want_excl,
43			      struct hmdfs_lookup_ret *create_ret);
44int hmdfs_client_start_rmdir(struct hmdfs_peer *con, const char *path,
45			     const char *name);
46int hmdfs_client_start_unlink(struct hmdfs_peer *con, const char *path,
47			      const char *name);
48int hmdfs_client_start_rename(struct hmdfs_peer *con, const char *old_path,
49			      const char *old_name, const char *new_path,
50			      const char *new_name, unsigned int flags);
51
52static inline bool hmdfs_is_offline_err(int err)
53{
54	/*
55	 * writepage() will get -EBADF if peer is online
56	 * again during offline stash, and -EBADF also
57	 * needs redo.
58	 */
59	return (err == -EAGAIN || err == -ESHUTDOWN || err == -EBADF);
60}
61
62static inline bool hmdfs_is_offline_or_timeout_err(int err)
63{
64	return hmdfs_is_offline_err(err) || err == -ETIME;
65}
66
67static inline bool hmdfs_need_redirty_page(const struct hmdfs_inode_info *info,
68					   int err)
69{
70	/*
71	 * 1. stash is enabled
72	 * 2. offline related error
73	 * 3. no restore
74	 */
75	return hmdfs_is_stash_enabled(info->conn->sbi) &&
76	       hmdfs_is_offline_err(err) &&
77	       READ_ONCE(info->stash_status) != HMDFS_REMOTE_INODE_RESTORING;
78}
79
80bool hmdfs_usr_sig_pending(struct task_struct *p);
81void hmdfs_writepage_cb(struct hmdfs_peer *peer, const struct hmdfs_req *req,
82			const struct hmdfs_resp *resp);
83int hmdfs_client_writepage(struct hmdfs_peer *con,
84			   struct hmdfs_writepage_context *param);
85int hmdfs_remote_do_writepage(struct hmdfs_peer *con,
86			      struct hmdfs_writepage_context *ctx);
87void hmdfs_remote_writepage_retry(struct work_struct *work);
88
89void hmdfs_client_writepage_done(struct hmdfs_inode_info *info,
90				 struct hmdfs_writepage_context *ctx);
91
92int hmdfs_send_open(struct hmdfs_peer *con, const char *send_buf,
93		    __u8 file_type, struct hmdfs_open_ret *open_ret);
94void hmdfs_send_close(struct hmdfs_peer *con, const struct hmdfs_fid *fid);
95int hmdfs_send_fsync(struct hmdfs_peer *con, const struct hmdfs_fid *fid,
96		     __s64 start, __s64 end, __s32 datasync);
97int hmdfs_client_readpage(struct hmdfs_peer *con, const struct hmdfs_fid *fid,
98			  struct page *page);
99
100int hmdfs_send_setattr(struct hmdfs_peer *con, const char *send_buf,
101		       struct setattr_info *attr_info);
102int hmdfs_send_getattr(struct hmdfs_peer *con, const char *send_buf,
103		       unsigned int lookup_flags,
104		       struct hmdfs_getattr_ret *getattr_result);
105int hmdfs_send_statfs(struct hmdfs_peer *con, const char *path,
106		      struct kstatfs *buf);
107void hmdfs_client_recv_readpage(struct hmdfs_head_cmd *head, int err,
108				struct hmdfs_async_work *async_work);
109int hmdfs_send_syncfs(struct hmdfs_peer *con, int syncfs_timeout);
110int hmdfs_send_getxattr(struct hmdfs_peer *con, const char *send_buf,
111			const char *name, void *value, size_t size);
112int hmdfs_send_setxattr(struct hmdfs_peer *con, const char *send_buf,
113			const char *name, const void *val,
114			size_t size, int flags);
115ssize_t hmdfs_send_listxattr(struct hmdfs_peer *con, const char *send_buf,
116			     char *list, size_t size);
117void hmdfs_recv_syncfs_cb(struct hmdfs_peer *peer, const struct hmdfs_req *req,
118			  const struct hmdfs_resp *resp);
119
120void __init hmdfs_client_add_node_evt_cb(void);
121#endif
122