Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #include <linux/kernel.h>
0003 #include <linux/types.h>
0004 #include <linux/spinlock_types.h>
0005 #include <linux/slab.h>
0006 #include <linux/ioctl.h>
0007 
0008 /* khandle stuff  ***********************************************************/
0009 
0010 /*
0011  * The 2.9 core will put 64 bit handles in here like this:
0012  *    1234 0000 0000 5678
0013  * The 3.0 and beyond cores will put 128 bit handles in here like this:
0014  *    1234 5678 90AB CDEF
0015  * The kernel module will always use the first four bytes and
0016  * the last four bytes as an inum.
0017  */
0018 struct orangefs_khandle {
0019     unsigned char u[16];
0020 }  __aligned(8);
0021 
0022 /*
0023  * kernel version of an object ref.
0024  */
0025 struct orangefs_object_kref {
0026     struct orangefs_khandle khandle;
0027     __s32 fs_id;
0028     __s32 __pad1;
0029 };
0030 
0031 /*
0032  * compare 2 khandles assumes little endian thus from large address to
0033  * small address
0034  */
0035 static inline int ORANGEFS_khandle_cmp(const struct orangefs_khandle *kh1,
0036                    const struct orangefs_khandle *kh2)
0037 {
0038     int i;
0039 
0040     for (i = 15; i >= 0; i--) {
0041         if (kh1->u[i] > kh2->u[i])
0042             return 1;
0043         if (kh1->u[i] < kh2->u[i])
0044             return -1;
0045     }
0046 
0047     return 0;
0048 }
0049 
0050 static inline void ORANGEFS_khandle_to(const struct orangefs_khandle *kh,
0051                    void *p, int size)
0052 {
0053 
0054     memcpy(p, kh->u, 16);
0055     memset(p + 16, 0, size - 16);
0056 
0057 }
0058 
0059 static inline void ORANGEFS_khandle_from(struct orangefs_khandle *kh,
0060                      void *p, int size)
0061 {
0062     memset(kh, 0, 16);
0063     memcpy(kh->u, p, 16);
0064 
0065 }
0066 
0067 /* pvfs2-types.h ************************************************************/
0068 
0069 #define ORANGEFS_SUPER_MAGIC 0x20030528
0070 
0071 /*
0072  * ORANGEFS error codes are a signed 32-bit integer. Error codes are negative, but
0073  * the sign is stripped before decoding.
0074  */
0075 
0076 /* Bit 31 is not used since it is the sign. */
0077 
0078 /*
0079  * Bit 30 specifies that this is a ORANGEFS error. A ORANGEFS error is either an
0080  * encoded errno value or a ORANGEFS protocol error.
0081  */
0082 #define ORANGEFS_ERROR_BIT (1 << 30)
0083 
0084 /*
0085  * Bit 29 specifies that this is a ORANGEFS protocol error and not an encoded
0086  * errno value.
0087  */
0088 #define ORANGEFS_NON_ERRNO_ERROR_BIT (1 << 29)
0089 
0090 /*
0091  * Bits 9, 8, and 7 specify the error class, which encodes the section of
0092  * server code the error originated in for logging purposes. It is not used
0093  * in the kernel except to be masked out.
0094  */
0095 #define ORANGEFS_ERROR_CLASS_BITS 0x380
0096 
0097 /* Bits 6 - 0 are reserved for the actual error code. */
0098 #define ORANGEFS_ERROR_NUMBER_BITS 0x7f
0099 
0100 /* Encoded errno values decoded by PINT_errno_mapping in orangefs-utils.c. */
0101 
0102 /* Our own ORANGEFS protocol error codes. */
0103 #define ORANGEFS_ECANCEL    (1|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0104 #define ORANGEFS_EDEVINIT   (2|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0105 #define ORANGEFS_EDETAIL    (3|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0106 #define ORANGEFS_EHOSTNTFD  (4|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0107 #define ORANGEFS_EADDRNTFD  (5|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0108 #define ORANGEFS_ENORECVR   (6|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0109 #define ORANGEFS_ETRYAGAIN  (7|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0110 #define ORANGEFS_ENOTPVFS   (8|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0111 #define ORANGEFS_ESECURITY  (9|ORANGEFS_NON_ERRNO_ERROR_BIT|ORANGEFS_ERROR_BIT)
0112 
0113 /* permission bits */
0114 #define ORANGEFS_O_EXECUTE (1 << 0)
0115 #define ORANGEFS_O_WRITE   (1 << 1)
0116 #define ORANGEFS_O_READ    (1 << 2)
0117 #define ORANGEFS_G_EXECUTE (1 << 3)
0118 #define ORANGEFS_G_WRITE   (1 << 4)
0119 #define ORANGEFS_G_READ    (1 << 5)
0120 #define ORANGEFS_U_EXECUTE (1 << 6)
0121 #define ORANGEFS_U_WRITE   (1 << 7)
0122 #define ORANGEFS_U_READ    (1 << 8)
0123 /* no ORANGEFS_U_VTX (sticky bit) */
0124 #define ORANGEFS_G_SGID    (1 << 10)
0125 #define ORANGEFS_U_SUID    (1 << 11)
0126 
0127 #define ORANGEFS_ITERATE_START    2147483646
0128 #define ORANGEFS_ITERATE_END      2147483645
0129 #define ORANGEFS_IMMUTABLE_FL FS_IMMUTABLE_FL
0130 #define ORANGEFS_APPEND_FL    FS_APPEND_FL
0131 #define ORANGEFS_NOATIME_FL   FS_NOATIME_FL
0132 #define ORANGEFS_MIRROR_FL    0x01000000ULL
0133 #define ORANGEFS_FS_ID_NULL       ((__s32)0)
0134 #define ORANGEFS_ATTR_SYS_UID                   (1 << 0)
0135 #define ORANGEFS_ATTR_SYS_GID                   (1 << 1)
0136 #define ORANGEFS_ATTR_SYS_PERM                  (1 << 2)
0137 #define ORANGEFS_ATTR_SYS_ATIME                 (1 << 3)
0138 #define ORANGEFS_ATTR_SYS_CTIME                 (1 << 4)
0139 #define ORANGEFS_ATTR_SYS_MTIME                 (1 << 5)
0140 #define ORANGEFS_ATTR_SYS_TYPE                  (1 << 6)
0141 #define ORANGEFS_ATTR_SYS_ATIME_SET             (1 << 7)
0142 #define ORANGEFS_ATTR_SYS_MTIME_SET             (1 << 8)
0143 #define ORANGEFS_ATTR_SYS_SIZE                  (1 << 20)
0144 #define ORANGEFS_ATTR_SYS_LNK_TARGET            (1 << 24)
0145 #define ORANGEFS_ATTR_SYS_DFILE_COUNT           (1 << 25)
0146 #define ORANGEFS_ATTR_SYS_DIRENT_COUNT          (1 << 26)
0147 #define ORANGEFS_ATTR_SYS_BLKSIZE               (1 << 28)
0148 #define ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT   (1 << 29)
0149 #define ORANGEFS_ATTR_SYS_COMMON_ALL    \
0150     (ORANGEFS_ATTR_SYS_UID  |   \
0151      ORANGEFS_ATTR_SYS_GID  |   \
0152      ORANGEFS_ATTR_SYS_PERM |   \
0153      ORANGEFS_ATTR_SYS_ATIME    |   \
0154      ORANGEFS_ATTR_SYS_CTIME    |   \
0155      ORANGEFS_ATTR_SYS_MTIME    |   \
0156      ORANGEFS_ATTR_SYS_TYPE)
0157 
0158 #define ORANGEFS_ATTR_SYS_ALL_SETABLE       \
0159 (ORANGEFS_ATTR_SYS_COMMON_ALL-ORANGEFS_ATTR_SYS_TYPE)
0160 
0161 #define ORANGEFS_ATTR_SYS_ALL_NOHINT            \
0162     (ORANGEFS_ATTR_SYS_COMMON_ALL       |   \
0163      ORANGEFS_ATTR_SYS_SIZE         |   \
0164      ORANGEFS_ATTR_SYS_LNK_TARGET       |   \
0165      ORANGEFS_ATTR_SYS_DFILE_COUNT      |   \
0166      ORANGEFS_ATTR_SYS_MIRROR_COPIES_COUNT  |   \
0167      ORANGEFS_ATTR_SYS_DIRENT_COUNT     |   \
0168      ORANGEFS_ATTR_SYS_BLKSIZE)
0169 
0170 #define ORANGEFS_XATTR_REPLACE 0x2
0171 #define ORANGEFS_XATTR_CREATE  0x1
0172 #define ORANGEFS_MAX_SERVER_ADDR_LEN 256
0173 #define ORANGEFS_NAME_MAX                256
0174 /*
0175  * max extended attribute name len as imposed by the VFS and exploited for the
0176  * upcall request types.
0177  * NOTE: Please retain them as multiples of 8 even if you wish to change them
0178  * This is *NECESSARY* for supporting 32 bit user-space binaries on a 64-bit
0179  * kernel. Due to implementation within DBPF, this really needs to be
0180  * ORANGEFS_NAME_MAX, which it was the same value as, but no reason to let it
0181  * break if that changes in the future.
0182  */
0183 #define ORANGEFS_MAX_XATTR_NAMELEN   ORANGEFS_NAME_MAX  /* Not the same as
0184                          * XATTR_NAME_MAX defined
0185                          * by <linux/xattr.h>
0186                          */
0187 #define ORANGEFS_MAX_XATTR_VALUELEN  8192   /* Not the same as XATTR_SIZE_MAX
0188                      * defined by <linux/xattr.h>
0189                      */
0190 #define ORANGEFS_MAX_XATTR_LISTLEN   16 /* Not the same as XATTR_LIST_MAX
0191                      * defined by <linux/xattr.h>
0192                      */
0193 /*
0194  * ORANGEFS I/O operation types, used in both system and server interfaces.
0195  */
0196 enum ORANGEFS_io_type {
0197     ORANGEFS_IO_READ = 1,
0198     ORANGEFS_IO_WRITE = 2
0199 };
0200 
0201 /*
0202  * If this enum is modified the server parameters related to the precreate pool
0203  * batch and low threshold sizes may need to be modified  to reflect this
0204  * change.
0205  */
0206 enum orangefs_ds_type {
0207     ORANGEFS_TYPE_NONE = 0,
0208     ORANGEFS_TYPE_METAFILE = (1 << 0),
0209     ORANGEFS_TYPE_DATAFILE = (1 << 1),
0210     ORANGEFS_TYPE_DIRECTORY = (1 << 2),
0211     ORANGEFS_TYPE_SYMLINK = (1 << 3),
0212     ORANGEFS_TYPE_DIRDATA = (1 << 4),
0213     ORANGEFS_TYPE_INTERNAL = (1 << 5)   /* for the server's private use */
0214 };
0215 
0216 /* This structure is used by the VFS-client interaction alone */
0217 struct ORANGEFS_keyval_pair {
0218     char key[ORANGEFS_MAX_XATTR_NAMELEN];
0219     __s32 key_sz;   /* __s32 for portable, fixed-size structures */
0220     __s32 val_sz;
0221     char val[ORANGEFS_MAX_XATTR_VALUELEN];
0222 };
0223 
0224 /* pvfs2-sysint.h ***********************************************************/
0225 /* Describes attributes for a file, directory, or symlink. */
0226 struct ORANGEFS_sys_attr_s {
0227     __u32 owner;
0228     __u32 group;
0229     __u32 perms;
0230     __u64 atime;
0231     __u64 mtime;
0232     __u64 ctime;
0233     __s64 size;
0234 
0235     /* NOTE: caller must free if valid */
0236     char *link_target;
0237 
0238     /* Changed to __s32 so that size of structure does not change */
0239     __s32 dfile_count;
0240 
0241     /* Changed to __s32 so that size of structure does not change */
0242     __s32 distr_dir_servers_initial;
0243 
0244     /* Changed to __s32 so that size of structure does not change */
0245     __s32 distr_dir_servers_max;
0246 
0247     /* Changed to __s32 so that size of structure does not change */
0248     __s32 distr_dir_split_size;
0249 
0250     __u32 mirror_copies_count;
0251 
0252     /* NOTE: caller must free if valid */
0253     char *dist_name;
0254 
0255     /* NOTE: caller must free if valid */
0256     char *dist_params;
0257 
0258     __s64 dirent_count;
0259     enum orangefs_ds_type objtype;
0260     __u64 flags;
0261     __u32 mask;
0262     __s64 blksize;
0263 };
0264 
0265 #define ORANGEFS_LOOKUP_LINK_NO_FOLLOW 0
0266 
0267 /* pint-dev.h ***************************************************************/
0268 
0269 /* parameter structure used in ORANGEFS_DEV_DEBUG ioctl command */
0270 struct dev_mask_info_s {
0271     enum {
0272         KERNEL_MASK,
0273         CLIENT_MASK,
0274     } mask_type;
0275     __u64 mask_value;
0276 };
0277 
0278 struct dev_mask2_info_s {
0279     __u64 mask1_value;
0280     __u64 mask2_value;
0281 };
0282 
0283 /* pvfs2-util.h *************************************************************/
0284 __s32 ORANGEFS_util_translate_mode(int mode);
0285 
0286 /* pvfs2-debug.h ************************************************************/
0287 #include "orangefs-debug.h"
0288 
0289 /* pvfs2-internal.h *********************************************************/
0290 #define llu(x) (unsigned long long)(x)
0291 #define lld(x) (long long)(x)
0292 
0293 /* pint-dev-shared.h ********************************************************/
0294 #define ORANGEFS_DEV_MAGIC 'k'
0295 
0296 #define ORANGEFS_READDIR_DEFAULT_DESC_COUNT  5
0297 
0298 #define DEV_GET_MAGIC           0x1
0299 #define DEV_GET_MAX_UPSIZE      0x2
0300 #define DEV_GET_MAX_DOWNSIZE    0x3
0301 #define DEV_MAP                 0x4
0302 #define DEV_REMOUNT_ALL         0x5
0303 #define DEV_DEBUG               0x6
0304 #define DEV_UPSTREAM            0x7
0305 #define DEV_CLIENT_MASK         0x8
0306 #define DEV_CLIENT_STRING       0x9
0307 #define DEV_MAX_NR              0xa
0308 
0309 /* supported ioctls, codes are with respect to user-space */
0310 enum {
0311     ORANGEFS_DEV_GET_MAGIC = _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAGIC, __s32),
0312     ORANGEFS_DEV_GET_MAX_UPSIZE =
0313         _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAX_UPSIZE, __s32),
0314     ORANGEFS_DEV_GET_MAX_DOWNSIZE =
0315         _IOW(ORANGEFS_DEV_MAGIC, DEV_GET_MAX_DOWNSIZE, __s32),
0316     ORANGEFS_DEV_MAP = _IO(ORANGEFS_DEV_MAGIC, DEV_MAP),
0317     ORANGEFS_DEV_REMOUNT_ALL = _IO(ORANGEFS_DEV_MAGIC, DEV_REMOUNT_ALL),
0318     ORANGEFS_DEV_DEBUG = _IOR(ORANGEFS_DEV_MAGIC, DEV_DEBUG, __s32),
0319     ORANGEFS_DEV_UPSTREAM = _IOW(ORANGEFS_DEV_MAGIC, DEV_UPSTREAM, int),
0320     ORANGEFS_DEV_CLIENT_MASK = _IOW(ORANGEFS_DEV_MAGIC,
0321                     DEV_CLIENT_MASK,
0322                     struct dev_mask2_info_s),
0323     ORANGEFS_DEV_CLIENT_STRING = _IOW(ORANGEFS_DEV_MAGIC,
0324                       DEV_CLIENT_STRING,
0325                       char *),
0326     ORANGEFS_DEV_MAXNR = DEV_MAX_NR,
0327 };
0328 
0329 /*
0330  * version number for use in communicating between kernel space and user
0331  * space. Zero signifies the upstream version of the kernel module.
0332  */
0333 #define ORANGEFS_KERNEL_PROTO_VERSION 0
0334 #define ORANGEFS_MINIMUM_USERSPACE_VERSION 20903
0335 
0336 /*
0337  * describes memory regions to map in the ORANGEFS_DEV_MAP ioctl.
0338  * NOTE: See devorangefs-req.c for 32 bit compat structure.
0339  * Since this structure has a variable-sized layout that is different
0340  * on 32 and 64 bit platforms, we need to normalize to a 64 bit layout
0341  * on such systems before servicing ioctl calls from user-space binaries
0342  * that may be 32 bit!
0343  */
0344 struct ORANGEFS_dev_map_desc {
0345     void __user *ptr;
0346     __s32 total_size;
0347     __s32 size;
0348     __s32 count;
0349 };
0350 
0351 /* gossip.h *****************************************************************/
0352 
0353 extern __u64 orangefs_gossip_debug_mask;
0354 
0355 /* try to avoid function call overhead by checking masks in macro */
0356 #define gossip_debug(mask, fmt, ...)                    \
0357 do {                                    \
0358     if (orangefs_gossip_debug_mask & (mask))            \
0359         printk(KERN_DEBUG fmt, ##__VA_ARGS__);          \
0360 } while (0)
0361 
0362 #define gossip_err pr_err