protocol.h 13 KB

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