protocol.h 14 KB

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