protocol.h 14 KB

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