protocol.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <linux/kernel.h>
  3. #include <linux/types.h>
  4. #include <linux/spinlock_types.h>
  5. #include <linux/slab.h>
  6. #include <linux/ioctl.h>
  7. /* khandle stuff ***********************************************************/
  8. /*
  9. * The 2.9 core will put 64 bit handles in here like this:
  10. * 1234 0000 0000 5678
  11. * The 3.0 and beyond cores will put 128 bit handles in here like this:
  12. * 1234 5678 90AB CDEF
  13. * The kernel module will always use the first four bytes and
  14. * the last four bytes as an inum.
  15. */
  16. struct orangefs_khandle {
  17. unsigned char u[16];
  18. } __aligned(8);
  19. /*
  20. * kernel version of an object ref.
  21. */
  22. struct orangefs_object_kref {
  23. struct orangefs_khandle khandle;
  24. __s32 fs_id;
  25. __s32 __pad1;
  26. };
  27. /*
  28. * compare 2 khandles assumes little endian thus from large address to
  29. * small address
  30. */
  31. static inline int ORANGEFS_khandle_cmp(const struct orangefs_khandle *kh1,
  32. const struct orangefs_khandle *kh2)
  33. {
  34. int i;
  35. for (i = 15; i >= 0; i--) {
  36. if (kh1->u[i] > kh2->u[i])
  37. return 1;
  38. if (kh1->u[i] < kh2->u[i])
  39. return -1;
  40. }
  41. return 0;
  42. }
  43. static inline void ORANGEFS_khandle_to(const struct orangefs_khandle *kh,
  44. void *p, int size)
  45. {
  46. memcpy(p, kh->u, 16);
  47. memset(p + 16, 0, size - 16);
  48. }
  49. static inline void ORANGEFS_khandle_from(struct orangefs_khandle *kh,
  50. void *p, int size)
  51. {
  52. memset(kh, 0, 16);
  53. memcpy(kh->u, p, 16);
  54. }
  55. /* pvfs2-types.h ************************************************************/
  56. #define ORANGEFS_SUPER_MAGIC 0x20030528
  57. /*
  58. * ORANGEFS error codes are a signed 32-bit integer. Error codes are negative, but
  59. * the sign is stripped before decoding.
  60. */
  61. /* Bit 31 is not used since it is the sign. */
  62. /*
  63. * Bit 30 specifies that this is a ORANGEFS error. A ORANGEFS error is either an
  64. * encoded errno value or a ORANGEFS protocol error.
  65. */
  66. #define ORANGEFS_ERROR_BIT (1 << 30)
  67. /*
  68. * Bit 29 specifies that this is a ORANGEFS protocol error and not an encoded
  69. * errno value.
  70. */
  71. #define ORANGEFS_NON_ERRNO_ERROR_BIT (1 << 29)
  72. /*
  73. * Bits 9, 8, and 7 specify the error class, which encodes the section of
  74. * server code the error originated in for logging purposes. It is not used
  75. * in the kernel except to be masked out.
  76. */
  77. #define ORANGEFS_ERROR_CLASS_BITS 0x380
  78. /* Bits 6 - 0 are reserved for the actual error code. */
  79. #define ORANGEFS_ERROR_NUMBER_BITS 0x7f
  80. /* Encoded errno values decoded by PINT_errno_mapping in orangefs-utils.c. */
  81. /* Our own ORANGEFS protocol error codes. */
  82. #define ORANGEFS_ECANCEL (1|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  83. #define ORANGEFS_EDEVINIT (2|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  84. #define ORANGEFS_EDETAIL (3|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  85. #define ORANGEFS_EHOSTNTFD (4|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  86. #define ORANGEFS_EADDRNTFD (5|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  87. #define ORANGEFS_ENORECVR (6|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  88. #define ORANGEFS_ETRYAGAIN (7|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  89. #define ORANGEFS_ENOTPVFS (8|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  90. #define ORANGEFS_ESECURITY (9|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
  91. /* permission bits */
  92. #define ORANGEFS_O_EXECUTE (1 << 0)
  93. #define ORANGEFS_O_WRITE (1 << 1)
  94. #define ORANGEFS_O_READ (1 << 2)
  95. #define ORANGEFS_G_EXECUTE (1 << 3)
  96. #define ORANGEFS_G_WRITE (1 << 4)
  97. #define ORANGEFS_G_READ (1 << 5)
  98. #define ORANGEFS_U_EXECUTE (1 << 6)
  99. #define ORANGEFS_U_WRITE (1 << 7)
  100. #define ORANGEFS_U_READ (1 << 8)
  101. /* no ORANGEFS_U_VTX (sticky bit) */
  102. #define ORANGEFS_G_SGID (1 << 10)
  103. #define ORANGEFS_U_SUID (1 << 11)
  104. #define ORANGEFS_ITERATE_START 2147483646
  105. #define ORANGEFS_ITERATE_END 2147483645
  106. #define ORANGEFS_IMMUTABLE_FL FS_IMMUTABLE_FL
  107. #define ORANGEFS_APPEND_FL FS_APPEND_FL
  108. #define ORANGEFS_NOATIME_FL FS_NOATIME_FL
  109. #define ORANGEFS_MIRROR_FL 0x01000000ULL
  110. #define ORANGEFS_FS_ID_NULL ((__s32)0)
  111. #define ORANGEFS_ATTR_SYS_UID (1 << 0)
  112. #define ORANGEFS_ATTR_SYS_GID (1 << 1)
  113. #define ORANGEFS_ATTR_SYS_PERM (1 << 2)
  114. #define ORANGEFS_ATTR_SYS_ATIME (1 << 3)
  115. #define ORANGEFS_ATTR_SYS_CTIME (1 << 4)
  116. #define ORANGEFS_ATTR_SYS_MTIME (1 << 5)
  117. #define ORANGEFS_ATTR_SYS_TYPE (1 << 6)
  118. #define ORANGEFS_ATTR_SYS_ATIME_SET (1 << 7)
  119. #define ORANGEFS_ATTR_SYS_MTIME_SET (1 << 8)
  120. #define ORANGEFS_ATTR_SYS_SIZE (1 << 20)
  121. #define ORANGEFS_ATTR_SYS_LNK_TARGET (1 << 24)
  122. #define ORANGEFS_ATTR_SYS_DFILE_COUNT (1 << 25)
  123. #define ORANGEFS_ATTR_SYS_DIRENT_COUNT (1 << 26)
  124. #define ORANGEFS_ATTR_SYS_BLKSIZE (1 << 28)
  125. #define ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT (1 << 29)
  126. #define ORANGEFS_ATTR_SYS_COMMON_ALL \
  127. (ORANGEFS_ATTR_SYS_UID | \
  128. ORANGEFS_ATTR_SYS_GID | \
  129. ORANGEFS_ATTR_SYS_PERM | \
  130. ORANGEFS_ATTR_SYS_ATIME | \
  131. ORANGEFS_ATTR_SYS_CTIME | \
  132. ORANGEFS_ATTR_SYS_MTIME | \
  133. ORANGEFS_ATTR_SYS_TYPE)
  134. #define ORANGEFS_ATTR_SYS_ALL_SETABLE \
  135. (ORANGEFS_ATTR_SYS_COMMON_ALL-ORANGEFS_ATTR_SYS_TYPE)
  136. #define ORANGEFS_ATTR_SYS_ALL_NOHINT \
  137. (ORANGEFS_ATTR_SYS_COMMON_ALL | \
  138. ORANGEFS_ATTR_SYS_SIZE | \
  139. ORANGEFS_ATTR_SYS_LNK_TARGET | \
  140. ORANGEFS_ATTR_SYS_DFILE_COUNT | \
  141. ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT | \
  142. ORANGEFS_ATTR_SYS_DIRENT_COUNT | \
  143. ORANGEFS_ATTR_SYS_BLKSIZE)
  144. #define ORANGEFS_XATTR_REPLACE 0x2
  145. #define ORANGEFS_XATTR_CREATE 0x1
  146. #define ORANGEFS_MAX_SERVER_ADDR_LEN 256
  147. #define ORANGEFS_NAME_MAX 256
  148. /*
  149. * max extended attribute name len as imposed by the VFS and exploited for the
  150. * upcall request types.
  151. * NOTE: Please retain them as multiples of 8 even if you wish to change them
  152. * This is *NECESSARY* for supporting 32 bit user-space binaries on a 64-bit
  153. * kernel. Due to implementation within DBPF, this really needs to be
  154. * ORANGEFS_NAME_MAX, which it was the same value as, but no reason to let it
  155. * break if that changes in the future.
  156. */
  157. #define ORANGEFS_MAX_XATTR_NAMELEN ORANGEFS_NAME_MAX /* Not the same as
  158. * XATTR_NAME_MAX defined
  159. * by <linux/xattr.h>
  160. */
  161. #define ORANGEFS_MAX_XATTR_VALUELEN 8192 /* Not the same as XATTR_SIZE_MAX
  162. * defined by <linux/xattr.h>
  163. */
  164. #define ORANGEFS_MAX_XATTR_LISTLEN 16 /* Not the same as XATTR_LIST_MAX
  165. * defined by <linux/xattr.h>
  166. */
  167. /*
  168. * ORANGEFS I/O operation types, used in both system and server interfaces.
  169. */
  170. enum ORANGEFS_io_type {
  171. ORANGEFS_IO_READ = 1,
  172. ORANGEFS_IO_WRITE = 2
  173. };
  174. /*
  175. * If this enum is modified the server parameters related to the precreate pool
  176. * batch and low threshold sizes may need to be modified to reflect this
  177. * change.
  178. */
  179. enum orangefs_ds_type {
  180. ORANGEFS_TYPE_NONE = 0,
  181. ORANGEFS_TYPE_METAFILE = (1 << 0),
  182. ORANGEFS_TYPE_DATAFILE = (1 << 1),
  183. ORANGEFS_TYPE_DIRECTORY = (1 << 2),
  184. ORANGEFS_TYPE_SYMLINK = (1 << 3),
  185. ORANGEFS_TYPE_DIRDATA = (1 << 4),
  186. ORANGEFS_TYPE_INTERNAL = (1 << 5) /* for the server's private use */
  187. };
  188. /* This structure is used by the VFS-client interaction alone */
  189. struct ORANGEFS_keyval_pair {
  190. char key[ORANGEFS_MAX_XATTR_NAMELEN];
  191. __s32 key_sz; /* __s32 for portable, fixed-size structures */
  192. __s32 val_sz;
  193. char val[ORANGEFS_MAX_XATTR_VALUELEN];
  194. };
  195. /* pvfs2-sysint.h ***********************************************************/
  196. /* Describes attributes for a file, directory, or symlink. */
  197. struct ORANGEFS_sys_attr_s {
  198. __u32 owner;
  199. __u32 group;
  200. __u32 perms;
  201. __u64 atime;
  202. __u64 mtime;
  203. __u64 ctime;
  204. __s64 size;
  205. /* NOTE: caller must free if valid */
  206. char *link_target;
  207. /* Changed to __s32 so that size of structure does not change */
  208. __s32 dfile_count;
  209. /* Changed to __s32 so that size of structure does not change */
  210. __s32 distr_dir_servers_initial;
  211. /* Changed to __s32 so that size of structure does not change */
  212. __s32 distr_dir_servers_max;
  213. /* Changed to __s32 so that size of structure does not change */
  214. __s32 distr_dir_split_size;
  215. __u32 mirror_copies_count;
  216. /* NOTE: caller must free if valid */
  217. char *dist_name;
  218. /* NOTE: caller must free if valid */
  219. char *dist_params;
  220. __s64 dirent_count;
  221. enum orangefs_ds_type objtype;
  222. __u64 flags;
  223. __u32 mask;
  224. __s64 blksize;
  225. };
  226. #define ORANGEFS_LOOKUP_LINK_NO_FOLLOW 0
  227. /* pint-dev.h ***************************************************************/
  228. /* parameter structure used in ORANGEFS_DEV_DEBUG ioctl command */
  229. struct dev_mask_info_s {
  230. enum {
  231. KERNEL_MASK,
  232. CLIENT_MASK,
  233. } mask_type;
  234. __u64 mask_value;
  235. };
  236. struct dev_mask2_info_s {
  237. __u64 mask1_value;
  238. __u64 mask2_value;
  239. };
  240. /* pvfs2-util.h *************************************************************/
  241. __s32 ORANGEFS_util_translate_mode(int mode);
  242. /* pvfs2-debug.h ************************************************************/
  243. #include "orangefs-debug.h"
  244. /* pvfs2-internal.h *********************************************************/
  245. #define llu(x) (unsigned long long)(x)
  246. #define lld(x) (long long)(x)
  247. /* pint-dev-shared.h ********************************************************/
  248. #define ORANGEFS_DEV_MAGIC 'k'
  249. #define ORANGEFS_READDIR_DEFAULT_DESC_COUNT 5
  250. #define DEV_GET_MAGIC 0x1
  251. #define DEV_GET_MAX_UPSIZE 0x2
  252. #define DEV_GET_MAX_DOWNSIZE 0x3
  253. #define DEV_MAP 0x4
  254. #define DEV_REMOUNT_ALL 0x5
  255. #define DEV_DEBUG 0x6
  256. #define DEV_UPSTREAM 0x7
  257. #define DEV_CLIENT_MASK 0x8
  258. #define DEV_CLIENT_STRING 0x9
  259. #define DEV_MAX_NR 0xa
  260. /* supported ioctls, codes are with respect to user-space */
  261. enum {
  262. ORANGEFS_DEV_GET_MAGIC = _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAGIC, __s32),
  263. ORANGEFS_DEV_GET_MAX_UPSIZE =
  264. _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAX_UPSIZE, __s32),
  265. ORANGEFS_DEV_GET_MAX_DOWNSIZE =
  266. _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAX_DOWNSIZE, __s32),
  267. ORANGEFS_DEV_MAP = _IO(ORANGEFS_DEV_MAGIC, DEV_MAP),
  268. ORANGEFS_DEV_REMOUNT_ALL = _IO(ORANGEFS_DEV_MAGIC, DEV_REMOUNT_ALL),
  269. ORANGEFS_DEV_DEBUG = _IOR(ORANGEFS_DEV_MAGIC, DEV_DEBUG, __s32),
  270. ORANGEFS_DEV_UPSTREAM = _IOW(ORANGEFS_DEV_MAGIC, DEV_UPSTREAM, int),
  271. ORANGEFS_DEV_CLIENT_MASK = _IOW(ORANGEFS_DEV_MAGIC,
  272. DEV_CLIENT_MASK,
  273. struct dev_mask2_info_s),
  274. ORANGEFS_DEV_CLIENT_STRING = _IOW(ORANGEFS_DEV_MAGIC,
  275. DEV_CLIENT_STRING,
  276. char *),
  277. ORANGEFS_DEV_MAXNR = DEV_MAX_NR,
  278. };
  279. /*
  280. * version number for use in communicating between kernel space and user
  281. * space. Zero signifies the upstream version of the kernel module.
  282. */
  283. #define ORANGEFS_KERNEL_PROTO_VERSION 0
  284. #define ORANGEFS_MINIMUM_USERSPACE_VERSION 20903
  285. /*
  286. * describes memory regions to map in the ORANGEFS_DEV_MAP ioctl.
  287. * NOTE: See devorangefs-req.c for 32 bit compat structure.
  288. * Since this structure has a variable-sized layout that is different
  289. * on 32 and 64 bit platforms, we need to normalize to a 64 bit layout
  290. * on such systems before servicing ioctl calls from user-space binaries
  291. * that may be 32 bit!
  292. */
  293. struct ORANGEFS_dev_map_desc {
  294. void __user *ptr;
  295. __s32 total_size;
  296. __s32 size;
  297. __s32 count;
  298. };
  299. /* gossip.h *****************************************************************/
  300. extern __u64 orangefs_gossip_debug_mask;
  301. /* try to avoid function call overhead by checking masks in macro */
  302. #define gossip_debug(mask, fmt, ...) \
  303. do { \
  304. if (orangefs_gossip_debug_mask & (mask)) \
  305. printk(KERN_DEBUG fmt, ##__VA_ARGS__); \
  306. } while (0)
  307. #define gossip_err pr_err