1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * fs/hmdfs/comm/protocol.h 4 * 5 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 6 */ 7 8 #ifndef HMDFS_PROTOCOL_H 9 #define HMDFS_PROTOCOL_H 10 11 #include <linux/kref.h> 12 #include <linux/wait.h> 13 #include <linux/workqueue.h> 14 #include <linux/namei.h> 15 16 struct hmdfs_cmd { 17 __u8 reserved; 18 __u8 cmd_flag; 19 __u8 command; 20 __u8 reserved2; 21 } __packed; 22 23 #define HMDFS_MSG_MAGIC 0xF7 24 #define HMDFS_MAX_MESSAGE_LEN (8 * 1024 * 1024) 25 26 struct hmdfs_head_cmd { 27 __u8 magic; 28 __u8 version; 29 __le16 reserved; 30 __le32 data_len; 31 struct hmdfs_cmd operations; 32 __le32 ret_code; 33 __le32 msg_id; 34 __le32 reserved1; 35 } __packed; 36 37 enum FILE_RECV_STATE { 38 FILE_RECV_PROCESS = 0, 39 FILE_RECV_SUCC, 40 FILE_RECV_ERR_NET, 41 FILE_RECV_ERR_SPC, 42 }; 43 44 struct file_recv_info { 45 void *local_filp; 46 atomic_t local_fslices; 47 atomic_t state; 48 }; 49 50 enum MSG_IDR_TYPE { 51 MSG_IDR_1_0_NONE = 0, 52 MSG_IDR_1_0_MESSAGE_SYNC, 53 MSG_IDR_1_0_PAGE, 54 MSG_IDR_MESSAGE_SYNC, 55 MSG_IDR_MESSAGE_ASYNC, 56 MSG_IDR_PAGE, 57 MSG_IDR_MAX, 58 }; 59 60 struct hmdfs_msg_idr_head { 61 __u32 type; 62 __u32 msg_id; 63 struct kref ref; 64 struct hmdfs_peer *peer; 65 }; 66 67 struct sendmsg_wait_queue { 68 struct hmdfs_msg_idr_head head; 69 wait_queue_head_t response_q; 70 struct list_head async_msg; 71 atomic_t valid; 72 __u32 size; 73 void *buf; 74 __u32 ret; 75 unsigned long start; 76 struct file_recv_info recv_info; 77 }; 78 79 struct hmdfs_send_command { 80 struct hmdfs_cmd operations; 81 void *data; 82 size_t len; 83 void *local_filp; 84 void *out_buf; 85 size_t out_len; 86 __u32 ret_code; 87 }; 88 89 struct hmdfs_req { 90 struct hmdfs_cmd operations; 91 /* 92 * Normally, the caller ought set timeout to TIMEOUT_CONFIG, so that 93 * hmdfs_send_async_request will search s_cmd_timeout for the user- 94 * configured timeout values. 95 * 96 * However, consider the given scenery: 97 * The caller may want to issue multiple requests sharing the same 98 * timeout value, but the users may update the value during the gap. 99 * To ensure the "atomicty" of timeout-using for these requests, we 100 * provide the timeout field for hacking. 101 */ 102 unsigned int timeout; 103 void *data; 104 size_t data_len; 105 106 void *private; // optional 107 size_t private_len; // optional 108 }; 109 110 struct hmdfs_resp { 111 void *out_buf; 112 size_t out_len; 113 __u32 ret_code; 114 }; 115 116 struct hmdfs_msg_parasite { 117 struct hmdfs_msg_idr_head head; 118 struct delayed_work d_work; 119 bool wfired; 120 struct hmdfs_req req; 121 struct hmdfs_resp resp; 122 unsigned long start; 123 }; 124 125 struct hmdfs_send_data { 126 // sect1: head 127 void *head; 128 size_t head_len; 129 130 // sect2: <optional> slice descriptor 131 void *sdesc; 132 size_t sdesc_len; 133 134 // sect3: request / response / file slice 135 void *data; 136 size_t len; 137 }; 138 139 struct slice_descriptor { 140 __le32 num_slices; 141 __le32 slice_size; 142 __le32 slice_sn; 143 __le32 content_size; 144 } __packed; 145 146 enum DFS_VERSION { 147 HMDFS_VERSION = 0x40, 148 MAX_VERSION = 0xFF 149 }; 150 151 enum CMD_FLAG { C_REQUEST = 0, C_RESPONSE = 1, C_FLAG_SIZE }; 152 153 enum FILE_CMD { 154 F_OPEN = 0, 155 F_RELEASE = 1, 156 F_READPAGE = 2, 157 F_WRITEPAGE = 3, 158 F_ITERATE = 4, 159 F_RESERVED_1 = 5, 160 F_RESERVED_2 = 6, 161 F_RESERVED_3 = 7, 162 F_RESERVED_4 = 8, 163 F_MKDIR = 9, 164 F_RMDIR = 10, 165 F_CREATE = 11, 166 F_UNLINK = 12, 167 F_RENAME = 13, 168 F_SETATTR = 14, 169 F_RESERVED_5 = 15, 170 F_STATFS = 16, 171 F_CONNECT_REKEY = 17, 172 F_DROP_PUSH = 18, 173 F_RESERVED_6 = 19, 174 F_GETATTR = 20, 175 F_FSYNC = 21, 176 F_SYNCFS = 22, 177 F_GETXATTR = 23, 178 F_SETXATTR = 24, 179 F_LISTXATTR = 25, 180 F_RESERVED_7 = 26, 181 F_RESERVED_8 = 27, 182 F_ATOMIC_OPEN = 28, 183 F_SIZE, 184 }; 185 186 struct open_request { 187 __u8 file_type; 188 __le32 flags; 189 __le32 path_len; 190 char buf[0]; 191 } __packed; 192 193 struct open_response { 194 __le32 change_detect_cap; 195 __le64 file_ver; 196 __le32 file_id; 197 __le64 file_size; 198 __le64 ino; 199 __le64 ctime; 200 __le32 ctime_nsec; 201 __le64 mtime; 202 __le32 mtime_nsec; 203 __le64 stable_ctime; 204 __le32 stable_ctime_nsec; 205 __le64 ichange_count; 206 } __packed; 207 208 enum hmdfs_open_flags { 209 HMDFS_O_TRUNC = O_TRUNC, 210 HMDFS_O_EXCL = O_EXCL, 211 }; 212 213 struct atomic_open_request { 214 __le32 open_flags; 215 __le16 mode; 216 __le16 reserved1; 217 __le32 path_len; 218 __le32 file_len; 219 __le64 reserved2[4]; 220 char buf[0]; 221 } __packed; 222 223 struct atomic_open_response { 224 __le32 fno; 225 __le16 i_mode; 226 __le16 reserved1; 227 __le32 i_flags; 228 __le32 reserved2; 229 __le64 reserved3[4]; 230 struct open_response open_resp; 231 } __packed; 232 233 struct release_request { 234 __le64 file_ver; 235 __le32 file_id; 236 } __packed; 237 238 struct fsync_request { 239 __le64 file_ver; 240 __le32 file_id; 241 __le32 datasync; 242 __le64 start; 243 __le64 end; 244 } __packed; 245 246 struct readpage_request { 247 __le64 file_ver; 248 __le32 file_id; 249 __le32 size; 250 __le64 index; 251 } __packed; 252 253 struct readpage_response { 254 char buf[0]; 255 } __packed; 256 257 struct writepage_request { 258 __le64 file_ver; 259 __le32 file_id; 260 __le64 index; 261 __le32 count; 262 char buf[0]; 263 } __packed; 264 265 struct writepage_response { 266 __le64 ichange_count; 267 __le64 ctime; 268 __le32 ctime_nsec; 269 } __packed; 270 271 struct readdir_request { 272 __le64 dcache_crtime; 273 __le64 dcache_crtime_nsec; 274 __le64 dentry_ctime; 275 __le64 dentry_ctime_nsec; 276 __le64 num; 277 __le32 verify_cache; 278 __le32 path_len; 279 char path[0]; 280 } __packed; 281 282 struct hmdfs_inodeinfo_response { 283 __le64 i_size; 284 __le64 i_mtime; 285 __le32 i_mtime_nsec; 286 __le32 fno; 287 __le16 i_mode; 288 __le64 i_ino; 289 __le32 i_flags; 290 __le32 i_reserved; 291 } __packed; 292 293 struct mkdir_request { 294 __le32 path_len; 295 __le32 name_len; 296 __le16 mode; 297 char path[0]; 298 } __packed; 299 300 struct create_request { 301 __le32 path_len; 302 __le32 name_len; 303 __le16 mode; 304 __u8 want_excl; 305 char path[0]; 306 } __packed; 307 308 struct rmdir_request { 309 __le32 path_len; 310 __le32 name_len; 311 char path[0]; 312 } __packed; 313 314 struct unlink_request { 315 __le32 path_len; 316 __le32 name_len; 317 char path[0]; 318 } __packed; 319 320 struct rename_request { 321 __le32 old_path_len; 322 __le32 new_path_len; 323 __le32 old_name_len; 324 __le32 new_name_len; 325 __le32 flags; 326 char path[0]; 327 } __packed; 328 329 struct drop_push_request { 330 __le32 path_len; 331 char path[0]; 332 } __packed; 333 334 struct setattr_request { 335 __le64 size; 336 __le32 valid; 337 __le16 mode; 338 __le32 uid; 339 __le32 gid; 340 __le64 atime; 341 __le32 atime_nsec; 342 __le64 mtime; 343 __le32 mtime_nsec; 344 __le32 path_len; 345 char buf[0]; 346 } __packed; 347 348 struct getattr_request { 349 __le32 lookup_flags; 350 __le32 path_len; 351 char buf[0]; 352 } __packed; 353 354 struct getattr_response { 355 __le32 change_detect_cap; 356 __le32 result_mask; 357 __le32 flags; 358 __le64 fsid; 359 __le16 mode; 360 __le32 nlink; 361 __le32 uid; 362 __le32 gid; 363 __le32 rdev; 364 __le64 ino; 365 __le64 size; 366 __le64 blocks; 367 __le32 blksize; 368 __le64 atime; 369 __le32 atime_nsec; 370 __le64 mtime; 371 __le32 mtime_nsec; 372 __le64 ctime; 373 __le32 ctime_nsec; 374 __le64 crtime; 375 __le32 crtime_nsec; 376 __le64 ichange_count; 377 } __packed; 378 379 struct statfs_request { 380 __le32 path_len; 381 char path[0]; 382 } __packed; 383 384 struct statfs_response { 385 __le64 f_type; 386 __le64 f_bsize; 387 __le64 f_blocks; 388 __le64 f_bfree; 389 __le64 f_bavail; 390 __le64 f_files; 391 __le64 f_ffree; 392 __le32 f_fsid_0; 393 __le32 f_fsid_1; 394 __le64 f_namelen; 395 __le64 f_frsize; 396 __le64 f_flags; 397 __le64 f_spare_0; 398 __le64 f_spare_1; 399 __le64 f_spare_2; 400 __le64 f_spare_3; 401 } __packed; 402 403 struct syncfs_request { 404 __le64 version; 405 __le32 flags; 406 } __packed; 407 408 struct getxattr_request { 409 __le32 path_len; 410 __le32 name_len; 411 __le32 size; 412 char buf[0]; 413 } __packed; 414 415 struct getxattr_response { 416 __le32 size; 417 char value[0]; /* xattr value may non-printable */ 418 } __packed; 419 420 struct setxattr_request { 421 __le32 path_len; 422 __le32 name_len; 423 __le32 size; 424 __le32 flags; 425 __u8 del; /* remove xattr */ 426 char buf[0]; 427 } __packed; 428 429 struct listxattr_request { 430 __le32 path_len; 431 __le32 size; 432 char buf[0]; 433 } __packed; 434 435 struct listxattr_response { 436 __le32 size; 437 char list[0]; 438 } __packed; 439 440 struct connection_rekey_request { 441 __le32 update_request; 442 } __packed; 443 444 enum CONNECTION_KEY_UPDATE_REQUEST { 445 UPDATE_NOT_REQUESTED = 0, 446 UPDATE_REQUESTED = 1 447 }; 448 449 enum MSG_QUEUE_STATUS { 450 MSG_Q_SEND = 0, 451 MSG_Q_END_RECV, 452 }; 453 #endif 454