Whamcloud - gitweb
LU-12885 llite: add enum ll_file_flags for clarity 24/45924/14
authorAndreas Dilger <adilger@whamcloud.com>
Wed, 6 Jul 2022 20:55:32 +0000 (14:55 -0600)
committerOleg Drokin <green@whamcloud.com>
Fri, 2 May 2025 02:17:17 +0000 (02:17 +0000)
Use enum ll_file_flags to store Lustre-internal flags on the open
file descriptor, instead of a generic "__u32 fd_flags", which can
easily be confused with any number of other flags in the code.

Rename variable "fd_flags" to "lfd_file_flags" to make this clear.

Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Idb4013610b9ef6f9461c8de275f6b5b4763ebbe5
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/45924
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Rajeev Mishra <rajeevm@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/scripts/spelling.txt
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/file.c
lustre/llite/llite_internal.h
lustre/llite/vvp_io.c

index 98bcd59..f8c6308 100644 (file)
@@ -52,6 +52,7 @@ DN_OLD_MAX_BONUSLEN||DN_BONUS_SIZE(DNODE_MIN_SIZE)
 ENOTSUPP||EOPNOTSUPP
 ERR_PTR.PTR_ERR||ERR_CAST
 EWOULDBLOCK||EAGAIN
+fd_flags||lfd_file_flags
 from_timer||cfs_from_timer
 ft_nob||ft_bytes
 f_dentry||f_path.dentry
index e0b2566..0f4595a 100644 (file)
@@ -763,11 +763,13 @@ struct fsxattr {
  */
 #define O_CIPHERTEXT           (O_NOCTTY | O_NDELAY | O_DSYNC)
 
-#define LL_FILE_IGNORE_LOCK     0x00000001
-#define LL_FILE_GROUP_LOCKED    0x00000002
-#define LL_FILE_READAHEA        0x00000004
-#define LL_FILE_LOCKED_DIRECTIO 0x00000008 /* client-side locks with dio */
-#define LL_FILE_FLOCK_WARNING   0x00000020 /* warned about disabled flock */
+enum ll_file_flags {
+       LL_FILE_IGNORE_LOCK     = 0x00000001,
+       LL_FILE_GROUP_LOCKED    = 0x00000002,
+       LL_FILE_READAHEA        = 0x00000004,
+       LL_FILE_LOCKED_DIRECTIO = 0x00000008, /* client-side locks with dio */
+       LL_FILE_FLOCK_WARNING   = 0x00000020, /* warned about disabled flock */
+};
 
 #define LOV_USER_MAGIC_V1      0x0BD10BD0
 #define LOV_USER_MAGIC         LOV_USER_MAGIC_V1
index ca812e7..8e01c17 100644 (file)
@@ -336,7 +336,7 @@ static int ll_md_close(struct inode *inode, struct file *file)
 
        ENTRY;
        /* clear group lock, if present */
-       if (unlikely(lfd->fd_flags & LL_FILE_GROUP_LOCKED))
+       if (unlikely(lfd->lfd_file_flags & LL_FILE_GROUP_LOCKED))
                ll_put_grouplock(inode, file, lfd->fd_grouplock.lg_gid);
 
        mutex_lock(&lli->lli_och_mutex);
@@ -2041,7 +2041,7 @@ restart:
                 */
                if (((iot == CIT_WRITE) ||
                    (iot == CIT_READ && iocb_ki_flags_check(flags, DIRECT))) &&
-                   !(vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
+                   !(vio->vui_fd->lfd_file_flags & LL_FILE_GROUP_LOCKED)) {
                        CDEBUG(D_VFSTRACE, "Range lock "RL_FMT"\n",
                               RL_PARA(&range));
                        rc = range_lock(&lli->lli_write_tree, &range);
@@ -3121,8 +3121,8 @@ ll_get_grouplock(struct inode *inode, struct file *file, unsigned long arg)
 
        if (arg == 0) {
                rc = -EINVAL;
-               CWARN("%s: group id for group lock must not be 0: rc = %d\n",
-                     ll_i2sbi(inode)->ll_fsname, rc);
+               CWARN("%s: group id for group lock on "DFID" is 0: rc = %d\n",
+                     ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid), rc);
                RETURN(rc);
        }
 
@@ -3136,10 +3136,11 @@ retry:
                mutex_lock(&lli->lli_group_mutex);
        }
 
-       if (lfd->fd_flags & LL_FILE_GROUP_LOCKED) {
-               rc = -EINVAL;
-               CWARN("%s: group lock already existed with gid %lu: rc = %d\n",
-                     ll_i2sbi(inode)->ll_fsname, lfd->fd_grouplock.lg_gid, rc);
+       if (lfd->lfd_file_flags & LL_FILE_GROUP_LOCKED) {
+               rc =  -EINVAL;
+               CWARN("%s: group lock already exists with gid %lu on "DFID": rc = %d\n",
+                     ll_i2sbi(inode)->ll_fsname, lfd->fd_grouplock.lg_gid,
+                     PFID(&lli->lli_fid), rc);
                GOTO(out, rc);
        }
        if (arg != lli->lli_group_gid && lli->lli_group_users != 0) {
@@ -3187,13 +3188,14 @@ retry:
        if (rc)
                GOTO(out, rc);
 
-       lfd->fd_flags |= LL_FILE_GROUP_LOCKED;
+       lfd->lfd_file_flags |= LL_FILE_GROUP_LOCKED;
        lfd->fd_grouplock = grouplock;
        if (lli->lli_group_users == 0)
                lli->lli_group_gid = grouplock.lg_gid;
        lli->lli_group_users++;
 
-       CDEBUG(D_INFO, "group lock %lu obtained\n", arg);
+       CDEBUG(D_INFO, "group lock %lu obtained on "DFID"\n",
+              arg, PFID(&lli->lli_fid));
 out:
        mutex_unlock(&lli->lli_group_mutex);
 
@@ -3210,10 +3212,10 @@ static int ll_put_grouplock(struct inode *inode, struct file *file,
 
        ENTRY;
        mutex_lock(&lli->lli_group_mutex);
-       if (!(lfd->fd_flags & LL_FILE_GROUP_LOCKED)) {
+       if (!(lfd->lfd_file_flags & LL_FILE_GROUP_LOCKED)) {
                rc = -EINVAL;
-               CWARN("%s: no group lock held: rc = %d\n",
-                     ll_i2sbi(inode)->ll_fsname, rc);
+               CWARN("%s: no group lock held on "DFID": rc = %d\n",
+                     ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid), rc);
                GOTO(out, rc);
        }
 
@@ -3221,15 +3223,15 @@ static int ll_put_grouplock(struct inode *inode, struct file *file,
 
        if (lfd->fd_grouplock.lg_gid != arg) {
                rc = -EINVAL;
-               CWARN("%s: group lock %lu not match current id %lu: rc = %d\n",
+               CWARN("%s: group lock %lu doesn't match current id %lu on "DFID": rc = %d\n",
                      ll_i2sbi(inode)->ll_fsname, arg, lfd->fd_grouplock.lg_gid,
-                     rc);
+                     PFID(&lli->lli_fid), rc);
                GOTO(out, rc);
        }
 
        grouplock = lfd->fd_grouplock;
        memset(&lfd->fd_grouplock, 0, sizeof(lfd->fd_grouplock));
-       lfd->fd_flags &= ~LL_FILE_GROUP_LOCKED;
+       lfd->lfd_file_flags &= ~LL_FILE_GROUP_LOCKED;
 
        cl_put_grouplock(&grouplock);
 
@@ -3238,7 +3240,8 @@ static int ll_put_grouplock(struct inode *inode, struct file *file,
                lli->lli_group_gid = 0;
                wake_up_var(&lli->lli_group_users);
        }
-       CDEBUG(D_INFO, "group lock %lu released\n", arg);
+       CDEBUG(D_INFO, "group lock %lu on "DFID" released\n", arg,
+              PFID(&lli->lli_fid));
        GOTO(out, rc = 0);
 out:
        mutex_unlock(&lli->lli_group_mutex);
@@ -4652,7 +4655,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        struct ll_file_data *lfd = file->private_data;
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        void __user *uarg = (void __user *)arg;
-       int flags, rc;
+       int rc;
 
        ENTRY;
        CDEBUG(D_VFSTRACE|D_IOCTL, "VFS Op:inode="DFID"(%pK) cmd=%x arg=%lx\n",
@@ -4668,23 +4671,25 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
         */
        switch (cmd) {
        case LL_IOC_GETFLAGS:
-               /* Get the current value of the file flags */
-               return put_user(lfd->fd_flags, (int __user *)arg);
+               /* Get the current value of the Lustre file flags */
+               return put_user(lfd->lfd_file_flags, (int __user *)arg);
        case LL_IOC_SETFLAGS:
-       case LL_IOC_CLRFLAGS:
-               /* Set or clear specific file flags */
+       case LL_IOC_CLRFLAGS: {
+               enum ll_file_flags lfd_file_flags;
+
+               /* Set or clear specific Lustre file flags */
                /* XXX This probably needs checks to ensure the flags are
                 *     not abused, and to handle any flag side effects.
                 */
-               if (get_user(flags, (int __user *)arg))
+               if (get_user(lfd_file_flags, (int __user *)arg))
                        RETURN(-EFAULT);
 
                /* LL_FILE_GROUP_LOCKED is managed via its own ioctls */
-               if (flags & LL_FILE_GROUP_LOCKED)
+               if (lfd_file_flags & LL_FILE_GROUP_LOCKED)
                        RETURN(-EINVAL);
 
                if (cmd == LL_IOC_SETFLAGS) {
-                       if ((flags & LL_FILE_IGNORE_LOCK) &&
+                       if ((lfd_file_flags & LL_FILE_IGNORE_LOCK) &&
                            !(file->f_flags & O_DIRECT)) {
                                rc = -EINVAL;
                                CERROR("%s: unable to disable locking on non-O_DIRECT file "DFID": rc = %d\n",
@@ -4693,11 +4698,12 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                RETURN(rc);
                        }
 
-                       lfd->fd_flags |= flags;
+                       lfd->lfd_file_flags |= lfd_file_flags;
                } else {
-                       lfd->fd_flags &= ~flags;
+                       lfd->lfd_file_flags &= ~lfd_file_flags;
                }
                RETURN(0);
+       }
        case LL_IOC_LOV_SETSTRIPE:
        case LL_IOC_LOV_SETSTRIPE_NEW:
                if (sbi->ll_enable_setstripe_gid != -1 &&
@@ -5055,12 +5061,12 @@ out_ladvise:
                RETURN(rc ? -EFAULT : 0);
        }
        case LL_IOC_HEAT_SET: {
-               __u64 flags;
+               __u64 heat_flags;
 
-               if (copy_from_user(&flags, uarg, sizeof(flags)))
+               if (copy_from_user(&heat_flags, uarg, sizeof(heat_flags)))
                        RETURN(-EFAULT);
 
-               rc = ll_heat_set(inode, flags);
+               rc = ll_heat_set(inode, heat_flags);
                RETURN(rc);
        }
        case LL_IOC_PCC_ATTACH: {
@@ -6032,8 +6038,8 @@ ll_file_noflock(struct file *file, int cmd, struct file_lock *file_lock)
         * for one file. And the entire message rate on the client is limited
         * by CDEBUG_LIMIT too.
         */
-       if (!(lfd->fd_flags & LL_FILE_FLOCK_WARNING)) {
-               lfd->fd_flags |= LL_FILE_FLOCK_WARNING;
+       if (!(lfd->lfd_file_flags & LL_FILE_FLOCK_WARNING)) {
+               lfd->lfd_file_flags |= LL_FILE_FLOCK_WARNING;
                CDEBUG_LIMIT(D_CONSOLE,
                             "flock disabled, mount with '-o [local]flock' to enable\r\n");
        }
index d54961c..5f9febb 100644 (file)
@@ -141,6 +141,7 @@ struct ll_inode_info {
 
        __u32                           lli_projid;   /* project id */
 
+       /* BIT(enum ll_file_internal_flags) */
        volatile unsigned long          lli_flags;
        struct posix_acl                *lli_posix_acl;
 
@@ -512,7 +513,7 @@ static inline void ll_layout_version_set(struct ll_inode_info *lli, __u32 gen)
        spin_unlock(&lli->lli_layout_lock);
 }
 
-enum ll_inode_flags {
+enum ll_file_internal_flags {
        /* File data is modified. */
        LLIF_DATA_MODIFIED      = 0,
        /* File is being restored */
@@ -528,10 +529,9 @@ enum ll_inode_flags {
        /* 6 is not used for now */
        /* Xattr cache is filled */
        LLIF_XATTR_CACHE_FILLED = 7,
-
-/* New flags added to this enum potentially need to be handled in
- * ll_inode2ext_flags/ll_set_inode_flags
- */
+       /* New flags added to this enum potentially need to be handled in
+        * ll_inode2ext_flags/ll_set_inode_flags
+        */
 };
 
 int ll_xattr_cache_destroy(struct inode *inode);
@@ -1158,7 +1158,7 @@ struct ll_file_data {
         */
        bool                            fd_write_failed;
        unsigned int                    lfd_lock_no_expand:1;
-       __u32                           fd_flags;
+       enum ll_file_flags              lfd_file_flags;
        enum mds_open_flags             fd_open_mode;
        /* striped directory may read partially if some stripe inaccessible,
         * -errno is saved here, and will return to user in close().
@@ -2007,7 +2007,7 @@ static inline int ll_file_nolock(const struct file *file)
        struct inode *inode = file_inode((struct file *)file);
 
        LASSERT(fd != NULL);
-       return ((fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
+       return ((fd->lfd_file_flags & LL_FILE_IGNORE_LOCK) ||
                test_bit(LL_SBI_NOLCK, ll_i2sbi(inode)->ll_flags));
 }
 
index 65e5d9b..cf8bf44 100644 (file)
@@ -200,7 +200,8 @@ static int vvp_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
 
        memset(&vio->vui_link, 0, sizeof(vio->vui_link));
 
-       if (vio->vui_fd && (vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
+       if (vio->vui_fd &&
+           (vio->vui_fd->lfd_file_flags & LL_FILE_GROUP_LOCKED)) {
                descr->cld_mode = CLM_GROUP;
                descr->cld_gid  = vio->vui_fd->fd_grouplock.lg_gid;
                enqflags |= CEF_LOCK_MATCH;
@@ -550,7 +551,7 @@ static int vvp_io_rw_lock(const struct lu_env *env, struct cl_io *io,
                int flags;
 
                /* Group lock held means no lockless any more */
-               if (vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)
+               if (vio->vui_fd->lfd_file_flags & LL_FILE_GROUP_LOCKED)
                        io->ci_dio_lock = 1;
 
                flags = iocb_ki_flags_get(vio->vui_iocb->ki_filp,
@@ -1721,7 +1722,8 @@ static int vvp_io_read_ahead(const struct lu_env *env,
            ios->cis_io->ci_type == CIT_FAULT) {
                struct vvp_io *vio = cl2vvp_io(env, ios);
 
-               if (unlikely(vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
+               if (unlikely(vio->vui_fd->lfd_file_flags &
+                            LL_FILE_GROUP_LOCKED)) {
                        ra->cra_end_idx = CL_PAGE_EOF;
                        result = 1; /* no need to call down */
                }