protocol.h 14.0 KB
Newer Older
M
Mike Marshall 已提交
1
#include <linux/types.h>
2
#include <linux/spinlock_types.h>
M
Mike Marshall 已提交
3
#include <linux/slab.h>
M
Mike Marshall 已提交
4
#include <linux/ioctl.h>
M
Mike Marshall 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

extern struct client_debug_mask *cdm_array;
extern char *debug_help_string;
extern int help_string_initialized;
extern struct dentry *debug_dir;
extern struct dentry *help_file_dentry;
extern struct dentry *client_debug_dentry;
extern const struct file_operations debug_help_fops;
extern int client_all_index;
extern int client_verbose_index;
extern int cdm_element_count;
#define DEBUG_HELP_STRING_SIZE 4096
#define HELP_STRING_UNINITIALIZED \
	"Client Debug Keywords are unknown until the first time\n" \
	"the client is started after boot.\n"
#define ORANGEFS_KMOD_DEBUG_HELP_FILE "debug-help"
#define ORANGEFS_KMOD_DEBUG_FILE "kernel-debug"
#define ORANGEFS_CLIENT_DEBUG_FILE "client-debug"
23 24
#define ORANGEFS_VERBOSE "verbose"
#define ORANGEFS_ALL "all"
M
Mike Marshall 已提交
25 26

/* pvfs2-config.h ***********************************************************/
27 28 29
#define ORANGEFS_VERSION_MAJOR 2
#define ORANGEFS_VERSION_MINOR 9
#define ORANGEFS_VERSION_SUB 0
M
Mike Marshall 已提交
30 31 32 33 34 35 36 37 38 39 40

/* khandle stuff  ***********************************************************/

/*
 * The 2.9 core will put 64 bit handles in here like this:
 *    1234 0000 0000 5678
 * The 3.0 and beyond cores will put 128 bit handles in here like this:
 *    1234 5678 90AB CDEF
 * The kernel module will always use the first four bytes and
 * the last four bytes as an inum.
 */
41
struct orangefs_khandle {
M
Mike Marshall 已提交
42 43 44 45 46 47
	unsigned char u[16];
}  __aligned(8);

/*
 * kernel version of an object ref.
 */
48 49
struct orangefs_object_kref {
	struct orangefs_khandle khandle;
M
Mike Marshall 已提交
50 51 52 53 54 55 56 57
	__s32 fs_id;
	__s32 __pad1;
};

/*
 * compare 2 khandles assumes little endian thus from large address to
 * small address
 */
58 59
static inline int ORANGEFS_khandle_cmp(const struct orangefs_khandle *kh1,
				   const struct orangefs_khandle *kh2)
M
Mike Marshall 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72
{
	int i;

	for (i = 15; i >= 0; i--) {
		if (kh1->u[i] > kh2->u[i])
			return 1;
		if (kh1->u[i] < kh2->u[i])
			return -1;
	}

	return 0;
}

73
static inline void ORANGEFS_khandle_to(const struct orangefs_khandle *kh,
M
Mike Marshall 已提交
74 75 76 77
				   void *p, int size)
{

	memset(p, 0, size);
M
Mike Marshall 已提交
78
	memcpy(p, kh->u, 16);
M
Mike Marshall 已提交
79 80 81

}

82
static inline void ORANGEFS_khandle_from(struct orangefs_khandle *kh,
M
Mike Marshall 已提交
83 84 85
				     void *p, int size)
{
	memset(kh, 0, 16);
M
Mike Marshall 已提交
86
	memcpy(kh->u, p, 16);
M
Mike Marshall 已提交
87 88 89 90

}

/* pvfs2-types.h ************************************************************/
91 92 93 94 95 96 97 98 99 100 101 102
typedef __u32 ORANGEFS_uid;
typedef __u32 ORANGEFS_gid;
typedef __s32 ORANGEFS_fs_id;
typedef __u32 ORANGEFS_permissions;
typedef __u64 ORANGEFS_time;
typedef __s64 ORANGEFS_size;
typedef __u64 ORANGEFS_flags;
typedef __u64 ORANGEFS_ds_position;
typedef __s32 ORANGEFS_error;
typedef __s64 ORANGEFS_offset;

#define ORANGEFS_SUPER_MAGIC 0x20030528
M
Mike Marshall 已提交
103

104
/*
105
 * ORANGEFS error codes are a signed 32-bit integer. Error codes are negative, but
106 107
 * the sign is stripped before decoding.
 */
M
Mike Marshall 已提交
108

109
/* Bit 31 is not used since it is the sign. */
M
Mike Marshall 已提交
110

111
/*
112 113
 * Bit 30 specifies that this is a ORANGEFS error. A ORANGEFS error is either an
 * encoded errno value or a ORANGEFS protocol error.
114
 */
115
#define ORANGEFS_ERROR_BIT (1 << 30)
M
Mike Marshall 已提交
116

117
/*
118
 * Bit 29 specifies that this is a ORANGEFS protocol error and not an encoded
119 120
 * errno value.
 */
121
#define ORANGEFS_NON_ERRNO_ERROR_BIT (1 << 29)
M
Mike Marshall 已提交
122

123 124
/*
 * Bits 9, 8, and 7 specify the error class, which encodes the section of
125
 * server code the error originated in for logging purposes. It is not used
126 127
 * in the kernel except to be masked out.
 */
128
#define ORANGEFS_ERROR_CLASS_BITS 0x380
129 130

/* Bits 6 - 0 are reserved for the actual error code. */
131
#define ORANGEFS_ERROR_NUMBER_BITS 0x7f
132 133 134

/* Encoded errno values are decoded by PINT_errno_mapping in pvfs2-utils.c. */

135 136 137 138 139 140 141 142 143 144
/* Our own ORANGEFS protocol error codes. */
#define ORANGEFS_ECANCEL    (1|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_EDEVINIT   (2|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_EDETAIL    (3|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_EHOSTNTFD  (4|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_EADDRNTFD  (5|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_ENORECVR   (6|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_ETRYAGAIN  (7|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_ENOTPVFS   (8|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
#define ORANGEFS_ESECURITY  (9|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
M
Mike Marshall 已提交
145 146

/* permission bits */
147 148 149 150 151 152 153 154 155 156 157 158
#define ORANGEFS_O_EXECUTE (1 << 0)
#define ORANGEFS_O_WRITE   (1 << 1)
#define ORANGEFS_O_READ    (1 << 2)
#define ORANGEFS_G_EXECUTE (1 << 3)
#define ORANGEFS_G_WRITE   (1 << 4)
#define ORANGEFS_G_READ    (1 << 5)
#define ORANGEFS_U_EXECUTE (1 << 6)
#define ORANGEFS_U_WRITE   (1 << 7)
#define ORANGEFS_U_READ    (1 << 8)
/* no ORANGEFS_U_VTX (sticky bit) */
#define ORANGEFS_G_SGID    (1 << 10)
#define ORANGEFS_U_SUID    (1 << 11)
M
Mike Marshall 已提交
159 160 161

/* definition taken from stdint.h */
#define INT32_MAX (2147483647)
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
#define ORANGEFS_ITERATE_START    (INT32_MAX - 1)
#define ORANGEFS_ITERATE_END      (INT32_MAX - 2)
#define ORANGEFS_ITERATE_NEXT     (INT32_MAX - 3)
#define ORANGEFS_READDIR_START ORANGEFS_ITERATE_START
#define ORANGEFS_READDIR_END   ORANGEFS_ITERATE_END
#define ORANGEFS_IMMUTABLE_FL FS_IMMUTABLE_FL
#define ORANGEFS_APPEND_FL    FS_APPEND_FL
#define ORANGEFS_NOATIME_FL   FS_NOATIME_FL
#define ORANGEFS_MIRROR_FL    0x01000000ULL
#define ORANGEFS_O_EXECUTE (1 << 0)
#define ORANGEFS_FS_ID_NULL       ((__s32)0)
#define ORANGEFS_ATTR_SYS_UID                   (1 << 0)
#define ORANGEFS_ATTR_SYS_GID                   (1 << 1)
#define ORANGEFS_ATTR_SYS_PERM                  (1 << 2)
#define ORANGEFS_ATTR_SYS_ATIME                 (1 << 3)
#define ORANGEFS_ATTR_SYS_CTIME                 (1 << 4)
#define ORANGEFS_ATTR_SYS_MTIME                 (1 << 5)
#define ORANGEFS_ATTR_SYS_TYPE                  (1 << 6)
#define ORANGEFS_ATTR_SYS_ATIME_SET             (1 << 7)
#define ORANGEFS_ATTR_SYS_MTIME_SET             (1 << 8)
#define ORANGEFS_ATTR_SYS_SIZE                  (1 << 20)
#define ORANGEFS_ATTR_SYS_LNK_TARGET            (1 << 24)
#define ORANGEFS_ATTR_SYS_DFILE_COUNT           (1 << 25)
#define ORANGEFS_ATTR_SYS_DIRENT_COUNT          (1 << 26)
#define ORANGEFS_ATTR_SYS_BLKSIZE               (1 << 28)
#define ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT   (1 << 29)
#define ORANGEFS_ATTR_SYS_COMMON_ALL	\
	(ORANGEFS_ATTR_SYS_UID	|	\
	 ORANGEFS_ATTR_SYS_GID	|	\
	 ORANGEFS_ATTR_SYS_PERM	|	\
	 ORANGEFS_ATTR_SYS_ATIME	|	\
	 ORANGEFS_ATTR_SYS_CTIME	|	\
	 ORANGEFS_ATTR_SYS_MTIME	|	\
	 ORANGEFS_ATTR_SYS_TYPE)

#define ORANGEFS_ATTR_SYS_ALL_SETABLE		\
(ORANGEFS_ATTR_SYS_COMMON_ALL-ORANGEFS_ATTR_SYS_TYPE)

#define ORANGEFS_ATTR_SYS_ALL_NOHINT			\
	(ORANGEFS_ATTR_SYS_COMMON_ALL		|	\
	 ORANGEFS_ATTR_SYS_SIZE			|	\
	 ORANGEFS_ATTR_SYS_LNK_TARGET		|	\
	 ORANGEFS_ATTR_SYS_DFILE_COUNT		|	\
	 ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT	|	\
	 ORANGEFS_ATTR_SYS_DIRENT_COUNT		|	\
	 ORANGEFS_ATTR_SYS_BLKSIZE)
#define ORANGEFS_XATTR_REPLACE 0x2
#define ORANGEFS_XATTR_CREATE  0x1
#define ORANGEFS_MAX_SERVER_ADDR_LEN 256
#define ORANGEFS_NAME_MAX                256
M
Mike Marshall 已提交
212 213 214 215 216 217
/*
 * max extended attribute name len as imposed by the VFS and exploited for the
 * upcall request types.
 * NOTE: Please retain them as multiples of 8 even if you wish to change them
 * This is *NECESSARY* for supporting 32 bit user-space binaries on a 64-bit
 * kernel. Due to implementation within DBPF, this really needs to be
218
 * ORANGEFS_NAME_MAX, which it was the same value as, but no reason to let it
M
Mike Marshall 已提交
219 220
 * break if that changes in the future.
 */
221
#define ORANGEFS_MAX_XATTR_NAMELEN   ORANGEFS_NAME_MAX	/* Not the same as
M
Mike Marshall 已提交
222 223 224
						 * XATTR_NAME_MAX defined
						 * by <linux/xattr.h>
						 */
225
#define ORANGEFS_MAX_XATTR_VALUELEN  8192	/* Not the same as XATTR_SIZE_MAX
M
Mike Marshall 已提交
226 227
					 * defined by <linux/xattr.h>
					 */
228
#define ORANGEFS_MAX_XATTR_LISTLEN   16	/* Not the same as XATTR_LIST_MAX
M
Mike Marshall 已提交
229 230 231
					 * defined by <linux/xattr.h>
					 */
/*
232
 * ORANGEFS I/O operation types, used in both system and server interfaces.
M
Mike Marshall 已提交
233
 */
234 235 236
enum ORANGEFS_io_type {
	ORANGEFS_IO_READ = 1,
	ORANGEFS_IO_WRITE = 2
M
Mike Marshall 已提交
237 238 239 240 241 242 243
};

/*
 * If this enum is modified the server parameters related to the precreate pool
 * batch and low threshold sizes may need to be modified  to reflect this
 * change.
 */
244 245 246 247 248 249 250 251
enum orangefs_ds_type {
	ORANGEFS_TYPE_NONE = 0,
	ORANGEFS_TYPE_METAFILE = (1 << 0),
	ORANGEFS_TYPE_DATAFILE = (1 << 1),
	ORANGEFS_TYPE_DIRECTORY = (1 << 2),
	ORANGEFS_TYPE_SYMLINK = (1 << 3),
	ORANGEFS_TYPE_DIRDATA = (1 << 4),
	ORANGEFS_TYPE_INTERNAL = (1 << 5)	/* for the server's private use */
M
Mike Marshall 已提交
252 253 254
};

/*
255
 * ORANGEFS_certificate simply stores a buffer with the buffer size.
M
Mike Marshall 已提交
256 257
 * The buffer can be converted to an OpenSSL X509 struct for use.
 */
258
struct ORANGEFS_certificate {
M
Mike Marshall 已提交
259 260 261 262 263 264 265 266
	__u32 buf_size;
	unsigned char *buf;
};

/*
 * A credential identifies a user and is signed by the client/user
 * private key.
 */
267
struct ORANGEFS_credential {
M
Mike Marshall 已提交
268 269 270 271 272 273 274
	__u32 userid;	/* user id */
	__u32 num_groups;	/* length of group_array */
	__u32 *group_array;	/* groups for which the user is a member */
	char *issuer;		/* alias of the issuing server */
	__u64 timeout;	/* seconds after epoch to time out */
	__u32 sig_size;	/* length of the signature in bytes */
	unsigned char *signature;	/* digital signature */
275
	struct ORANGEFS_certificate certificate;	/* user certificate buffer */
M
Mike Marshall 已提交
276
};
277
#define extra_size_ORANGEFS_credential (ORANGEFS_REQ_LIMIT_GROUPS	*	\
M
Mike Marshall 已提交
278
				    sizeof(__u32)		+	\
279 280 281
				    ORANGEFS_REQ_LIMIT_ISSUER	+	\
				    ORANGEFS_REQ_LIMIT_SIGNATURE	+	\
				    extra_size_ORANGEFS_certificate)
M
Mike Marshall 已提交
282 283

/* This structure is used by the VFS-client interaction alone */
284 285
struct ORANGEFS_keyval_pair {
	char key[ORANGEFS_MAX_XATTR_NAMELEN];
M
Mike Marshall 已提交
286 287
	__s32 key_sz;	/* __s32 for portable, fixed-size structures */
	__s32 val_sz;
288
	char val[ORANGEFS_MAX_XATTR_VALUELEN];
M
Mike Marshall 已提交
289 290 291 292
};

/* pvfs2-sysint.h ***********************************************************/
/* Describes attributes for a file, directory, or symlink. */
293
struct ORANGEFS_sys_attr_s {
M
Mike Marshall 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
	__u32 owner;
	__u32 group;
	__u32 perms;
	__u64 atime;
	__u64 mtime;
	__u64 ctime;
	__s64 size;

	/* NOTE: caller must free if valid */
	char *link_target;

	/* Changed to __s32 so that size of structure does not change */
	__s32 dfile_count;

	/* Changed to __s32 so that size of structure does not change */
	__s32 distr_dir_servers_initial;

	/* Changed to __s32 so that size of structure does not change */
	__s32 distr_dir_servers_max;

	/* Changed to __s32 so that size of structure does not change */
	__s32 distr_dir_split_size;

	__u32 mirror_copies_count;

	/* NOTE: caller must free if valid */
	char *dist_name;

	/* NOTE: caller must free if valid */
	char *dist_params;

	__s64 dirent_count;
326
	enum orangefs_ds_type objtype;
M
Mike Marshall 已提交
327 328 329 330 331
	__u64 flags;
	__u32 mask;
	__s64 blksize;
};

332 333
#define ORANGEFS_LOOKUP_LINK_NO_FOLLOW 0
#define ORANGEFS_LOOKUP_LINK_FOLLOW    1
M
Mike Marshall 已提交
334 335 336

/* pint-dev.h ***************************************************************/

337
/* parameter structure used in ORANGEFS_DEV_DEBUG ioctl command */
M
Mike Marshall 已提交
338 339 340 341 342 343 344 345 346 347 348 349 350 351
struct dev_mask_info_s {
	enum {
		KERNEL_MASK,
		CLIENT_MASK,
	} mask_type;
	__u64 mask_value;
};

struct dev_mask2_info_s {
	__u64 mask1_value;
	__u64 mask2_value;
};

/* pvfs2-util.h *************************************************************/
352
__s32 ORANGEFS_util_translate_mode(int mode);
M
Mike Marshall 已提交
353 354 355 356 357 358 359 360 361

/* pvfs2-debug.h ************************************************************/
#include "pvfs2-debug.h"

/* pvfs2-internal.h *********************************************************/
#define llu(x) (unsigned long long)(x)
#define lld(x) (long long)(x)

/* pint-dev-shared.h ********************************************************/
362
#define ORANGEFS_DEV_MAGIC 'k'
M
Mike Marshall 已提交
363

364
#define ORANGEFS_READDIR_DEFAULT_DESC_COUNT  5
M
Mike Marshall 已提交
365 366 367 368 369 370 371 372 373 374 375 376 377 378

#define DEV_GET_MAGIC           0x1
#define DEV_GET_MAX_UPSIZE      0x2
#define DEV_GET_MAX_DOWNSIZE    0x3
#define DEV_MAP                 0x4
#define DEV_REMOUNT_ALL         0x5
#define DEV_DEBUG               0x6
#define DEV_UPSTREAM            0x7
#define DEV_CLIENT_MASK         0x8
#define DEV_CLIENT_STRING       0x9
#define DEV_MAX_NR              0xa

/* supported ioctls, codes are with respect to user-space */
enum {
379 380 381 382 383 384 385 386 387 388
	ORANGEFS_DEV_GET_MAGIC = _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAGIC, __s32),
	ORANGEFS_DEV_GET_MAX_UPSIZE =
	    _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAX_UPSIZE, __s32),
	ORANGEFS_DEV_GET_MAX_DOWNSIZE =
	    _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAX_DOWNSIZE, __s32),
	ORANGEFS_DEV_MAP = _IO(ORANGEFS_DEV_MAGIC, DEV_MAP),
	ORANGEFS_DEV_REMOUNT_ALL = _IO(ORANGEFS_DEV_MAGIC, DEV_REMOUNT_ALL),
	ORANGEFS_DEV_DEBUG = _IOR(ORANGEFS_DEV_MAGIC, DEV_DEBUG, __s32),
	ORANGEFS_DEV_UPSTREAM = _IOW(ORANGEFS_DEV_MAGIC, DEV_UPSTREAM, int),
	ORANGEFS_DEV_CLIENT_MASK = _IOW(ORANGEFS_DEV_MAGIC,
M
Mike Marshall 已提交
389 390
				    DEV_CLIENT_MASK,
				    struct dev_mask2_info_s),
391
	ORANGEFS_DEV_CLIENT_STRING = _IOW(ORANGEFS_DEV_MAGIC,
M
Mike Marshall 已提交
392 393
				      DEV_CLIENT_STRING,
				      char *),
394
	ORANGEFS_DEV_MAXNR = DEV_MAX_NR,
M
Mike Marshall 已提交
395 396 397 398
};

/*
 * version number for use in communicating between kernel space and user
399
 * space. Zero signifies the upstream version of the kernel module.
M
Mike Marshall 已提交
400
 */
401
#define ORANGEFS_KERNEL_PROTO_VERSION 0
M
Mike Marshall 已提交
402 403

/*
404
 * describes memory regions to map in the ORANGEFS_DEV_MAP ioctl.
M
Mike Marshall 已提交
405 406 407 408 409 410
 * NOTE: See devpvfs2-req.c for 32 bit compat structure.
 * Since this structure has a variable-sized layout that is different
 * on 32 and 64 bit platforms, we need to normalize to a 64 bit layout
 * on such systems before servicing ioctl calls from user-space binaries
 * that may be 32 bit!
 */
411
struct ORANGEFS_dev_map_desc {
M
Mike Marshall 已提交
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
	void *ptr;
	__s32 total_size;
	__s32 size;
	__s32 count;
};

/* gossip.h *****************************************************************/

#ifdef GOSSIP_DISABLE_DEBUG
#define gossip_debug(mask, format, f...) do {} while (0)
#else
extern __u64 gossip_debug_mask;
extern struct client_debug_mask client_debug_mask;

/* try to avoid function call overhead by checking masks in macro */
#define gossip_debug(mask, format, f...)			\
do {								\
	if (gossip_debug_mask & mask)				\
		printk(format, ##f);				\
} while (0)
#endif /* GOSSIP_DISABLE_DEBUG */

/* do file and line number printouts w/ the GNU preprocessor */
#define gossip_ldebug(mask, format, f...)				\
		gossip_debug(mask, "%s: " format, __func__, ##f)

#define gossip_err printk
#define gossip_lerr(format, f...)					\
		gossip_err("%s line %d: " format,			\
			   __FILE__,					\
			   __LINE__,					\
			   ##f)