Whamcloud - gitweb
LU-12885 mds: add enums for MDS_OPEN flags (4/4) 12/56812/12
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Mon, 28 Oct 2024 04:56:56 +0000 (00:56 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 13 Mar 2025 17:06:28 +0000 (17:06 +0000)
This patch is fourth of the series of patch that separates
kernel open flags from MDS open flags

This patch adds function ll_kernel_to_mds_open_flags() for
one place convert of kernel flags (fmode) to MDS flags

This patch removes macros O_LOV_DELAY_CREATE_1_8 and
O_LOV_DELAY_CREATE_MASK everywhere as it is was only
required for interop with applications written for Lustre
1.8 clients and not used any more

This patch adds function ll_lov_delay_create_is_set() and
ll_lov_delay_create_clear() to set and remove O_LOV_DELAY_CREATE
flag if found in struct file->fmode

This patch removes remaining fmode to mds_open_flags wherever
it was remaining

Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: Ic125dc0c7fa54888fddf435c117de9d304ea8708
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56812
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lustre_mdc.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/file.c
lustre/llite/llite_internal.h
lustre/llite/namei.c

index 5202e2a..c5424a1 100644 (file)
@@ -75,18 +75,15 @@ static inline void mdc_update_max_ea_from_body(struct obd_export *exp,
 /* mdc/mdc_locks.c */
 int it_open_error(int phase, struct lookup_intent *it);
 
-static inline bool cl_is_lov_delay_create(unsigned int flags)
+static inline bool cl_is_lov_delay_create(enum mds_open_flags flags)
 {
-       return  (flags & O_LOV_DELAY_CREATE_1_8) != 0 ||
-               (flags & O_LOV_DELAY_CREATE_MASK) == O_LOV_DELAY_CREATE_MASK;
+       return (flags & O_LOV_DELAY_CREATE) == O_LOV_DELAY_CREATE;
 }
 
 static inline void cl_lov_delay_create_clear(unsigned int *flags)
 {
-       if ((*flags & O_LOV_DELAY_CREATE_1_8) != 0)
-               *flags &= ~O_LOV_DELAY_CREATE_1_8;
-       if ((*flags & O_LOV_DELAY_CREATE_MASK) == O_LOV_DELAY_CREATE_MASK)
-               *flags &= ~O_LOV_DELAY_CREATE_MASK;
+       if ((*flags & O_LOV_DELAY_CREATE) == O_LOV_DELAY_CREATE)
+               *flags &= ~O_LOV_DELAY_CREATE;
 }
 
 /** @} mdc */
index 097690e..7721903 100644 (file)
@@ -700,13 +700,13 @@ struct fsxattr {
 /* To be compatible with old statically linked binary we keep the check for
  * the older 0100000000 flag.  This is already removed upstream.  LU-812.
  */
-#define O_LOV_DELAY_CREATE_1_8 0100000000 /* FMODE_NONOTIFY masked in 2.6.36 */
 #ifndef FASYNC
 #define FASYNC                 00020000   /* fcntl, for BSD compatibility */
 #endif
-#define O_LOV_DELAY_CREATE_MASK        (O_NOCTTY | FASYNC)
-#define O_LOV_DELAY_CREATE             (O_LOV_DELAY_CREATE_1_8 | \
-                                        O_LOV_DELAY_CREATE_MASK)
+/* This is Lustre-specific flag that defines O_LOV_DELAY_CREATE. There is no
+ * clash anywhere with these value and can be used safely
+ */
+#define O_LOV_DELAY_CREATE             (O_NOCTTY | FASYNC)
 /* O_CIPHERTEXT principle is similar to O_LOV_DELAY_CREATE above,
  * for access to encrypted files without the encryption key.
  */
@@ -1681,15 +1681,25 @@ enum mds_open_flags {
        MDS_FMODE_CLOSED        =                 00000000,
        MDS_FMODE_READ          =                 00000001,
        MDS_FMODE_WRITE         =                 00000002,
+       /* MAY_EXEC checks for permission eg inode_permission(). Different from
+        * MDS_FMODE_EXECUTE which is permission check via execve
+        */
        MDS_FMODE_EXEC          =                 00000004,
        MDS_OPEN_CREATED        =                 00000010,
 /*     MDS_OPEN_CROSS          =                 00000020, obsolete in 2.12, internal use only */
+       /* open for execution via execve */
+       MDS_FMODE_EXECUTE       =                 00000020,
        MDS_OPEN_CREAT          =                 00000100,
        MDS_OPEN_EXCL           =                 00000200,
+       MDS_OPEN_NOCTTY         =                 00000400,
        MDS_OPEN_TRUNC          =                 00001000,
        MDS_OPEN_APPEND         =                 00002000,
+       MDS_OPEN_NONBLOCK       =                 00004000,
        MDS_OPEN_SYNC           =                 00010000,
+       MDS_OPEN_FASYNC         =                 00020000,
+       MDS_OPEN_LARGEFILE      =                 00100000,
        MDS_OPEN_DIRECTORY      =                 00200000,
+       MDS_OPEN_NOFOLLOW       =                 00400000,
 /*     MDS_FMODE_EPOCH         =                 01000000, obsolete in 2.8.0 */
 /*     MDS_FMODE_TRUNC         =                 02000000, obsolete in 2.8.0 */
 /*     MDS_FMODE_SOM           =                 04000000, obsolete in 2.8.0 */
index fd40dd5..817cf70 100644 (file)
@@ -776,6 +776,73 @@ static int ll_och_fill(struct obd_export *md_exp, struct lookup_intent *it,
        return md_set_open_replay_data(md_exp, och, it);
 }
 
+/**
+ * ll_kernel_to_mds_open_flags() - Convert kernel flags to MDS flags (Access
+ *                                mode)
+ *
+ * @kernel_open_flags: kernel input (struct file.f_flags)
+ *
+ * Returns:
+ * * mds_open_flags
+ */
+enum mds_open_flags ll_kernel_to_mds_open_flags(unsigned int kernel_open_flags)
+{
+       enum mds_open_flags mds_open_flags = MDS_FMODE_CLOSED;
+
+       if (kernel_open_flags & FMODE_READ)
+               mds_open_flags |= MDS_FMODE_READ;
+
+       if (kernel_open_flags & FMODE_WRITE)
+               mds_open_flags |= MDS_FMODE_WRITE;
+
+       if (kernel_open_flags & O_CREAT)
+               mds_open_flags |= MDS_OPEN_CREAT;
+
+       if (kernel_open_flags & O_EXCL)
+               mds_open_flags |= MDS_OPEN_EXCL;
+
+       if (kernel_open_flags & O_TRUNC)
+               mds_open_flags |= MDS_OPEN_TRUNC;
+
+       if (kernel_open_flags & O_APPEND)
+               mds_open_flags |= MDS_OPEN_APPEND;
+
+       if (kernel_open_flags & O_SYNC)
+               mds_open_flags |= MDS_OPEN_SYNC;
+
+       if (kernel_open_flags & O_DIRECTORY)
+               mds_open_flags |= MDS_OPEN_DIRECTORY;
+
+       /* FMODE_EXEC is only valid with fmode_t, use __FMODE_EXEC instead
+        * which indicates file is opened for execution with sys_execve
+        */
+       if (kernel_open_flags & __FMODE_EXEC)
+               mds_open_flags |= MDS_FMODE_EXECUTE;
+
+       if (ll_lov_delay_create_is_set(kernel_open_flags))
+               mds_open_flags |= O_LOV_DELAY_CREATE;
+
+       if (kernel_open_flags & O_LARGEFILE)
+               mds_open_flags |= MDS_OPEN_LARGEFILE;
+
+       if (kernel_open_flags & O_NONBLOCK)
+               mds_open_flags |= MDS_OPEN_NORESTORE;
+
+       if (kernel_open_flags & O_NOCTTY)
+               mds_open_flags |= MDS_OPEN_NOCTTY;
+
+       if (kernel_open_flags & O_NONBLOCK)
+               mds_open_flags |= MDS_OPEN_NONBLOCK;
+
+       if (kernel_open_flags & O_NOFOLLOW)
+               mds_open_flags |= MDS_OPEN_NOFOLLOW;
+
+       if (kernel_open_flags & FASYNC)
+               mds_open_flags |= MDS_OPEN_FASYNC;
+
+       return mds_open_flags;
+}
+
 static int ll_local_open(struct file *file, struct lookup_intent *it,
                         struct ll_file_data *lfd,
                         struct obd_client_handle *och)
@@ -893,11 +960,16 @@ int ll_file_open(struct inode *inode, struct file *file)
        }
 
        if (!it || !it->it_disposition) {
+               unsigned int kernel_flags = file->f_flags;
+
                /* Convert f_flags into access mode. We cannot use file->f_mode,
                 * because everything but O_ACCMODE mask was stripped from there
                 */
-               if ((oit.it_open_flags + 1) & O_ACCMODE)
-                       oit.it_open_flags++;
+               if ((oit.it_open_flags + MDS_FMODE_READ) & O_ACCMODE)
+                       kernel_flags++;
+
+               oit.it_open_flags = ll_kernel_to_mds_open_flags(kernel_flags);
+
                if (file->f_flags & O_TRUNC)
                        oit.it_open_flags |= MDS_FMODE_WRITE;
 
@@ -2660,6 +2732,7 @@ static ssize_t ll_file_read(struct file *file, char __user *buf, size_t count,
        RETURN(result);
 }
 
+/* Write to a file (through the page cache). AIO stuff */
 static ssize_t ll_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
                                 unsigned long nr_segs, loff_t pos)
 {
@@ -3790,7 +3863,8 @@ out:
        RETURN(rc);
 }
 
-static inline long ll_lease_type_from_fmode(enum mds_open_flags fd_open_mode)
+static inline long ll_lease_type_from_open_flags(enum mds_open_flags
+                                                fd_open_mode)
 {
        return ((fd_open_mode & MDS_FMODE_READ) ? LL_LEASE_RDLCK : 0) |
               ((fd_open_mode & MDS_FMODE_WRITE) ? LL_LEASE_WRLCK : 0);
@@ -4262,7 +4336,7 @@ static long ll_file_unlock_lease(struct file *file, struct ll_ioc_lease *ioc,
        struct split_param sp;
        struct pcc_param param;
        bool lease_broken = false;
-       enum mds_open_flags fmode = MDS_FMODE_CLOSED;
+       enum mds_open_flags open_flags = MDS_FMODE_CLOSED;
        enum mds_op_bias bias = 0;
        __u32 fdv;
        struct file *layout_file = NULL;
@@ -4282,7 +4356,7 @@ static long ll_file_unlock_lease(struct file *file, struct ll_ioc_lease *ioc,
        if (och == NULL)
                RETURN(-ENOLCK);
 
-       fmode = och->och_flags;
+       open_flags = och->och_flags;
 
        switch (ioc->lil_flags) {
        case LL_LEASE_RESYNC_DONE:
@@ -4386,7 +4460,7 @@ out_lease_close:
                GOTO(out, rc);
 
        if (lease_broken)
-               fmode = MDS_FMODE_CLOSED;
+               open_flags = MDS_FMODE_CLOSED;
        EXIT;
 
 out:
@@ -4408,7 +4482,7 @@ out:
        ll_layout_refresh(inode, &lfd->fd_layout_version);
 
        if (!rc)
-               rc = ll_lease_type_from_fmode(fmode);
+               rc = ll_lease_type_from_open_flags(open_flags);
        RETURN(rc);
 }
 
@@ -4770,7 +4844,7 @@ skip_copy:
        case LL_IOC_GET_LEASE: {
                struct ll_inode_info *lli = ll_i2info(inode);
                struct ldlm_lock *lock = NULL;
-               enum mds_open_flags fmode = MDS_FMODE_CLOSED;
+               enum mds_open_flags open_flags = MDS_FMODE_CLOSED;
 
                mutex_lock(&lli->lli_och_mutex);
                if (lfd->fd_lease_och != NULL) {
@@ -4780,7 +4854,7 @@ skip_copy:
                        if (lock != NULL) {
                                lock_res_and_lock(lock);
                                if (!ldlm_is_cancel(lock))
-                                       fmode = och->och_flags;
+                                       open_flags = och->och_flags;
 
                                unlock_res_and_lock(lock);
                                ldlm_lock_put(lock);
@@ -4788,7 +4862,7 @@ skip_copy:
                }
                mutex_unlock(&lli->lli_och_mutex);
 
-               RETURN(ll_lease_type_from_fmode(fmode));
+               RETURN(ll_lease_type_from_open_flags(open_flags));
        }
        case LL_IOC_HSM_IMPORT: {
                struct hsm_user_import *hui;
index 6b2ebd6..cc88465 100644 (file)
@@ -1331,6 +1331,21 @@ void ll_quota_iter_check_and_cleanup(struct ll_sb_info *sbi, bool check);
 /* llite/namei.c */
 extern const struct inode_operations ll_special_inode_operations;
 
+/* Return True if (file.f_flag) has O_LOV_DELAY_CREATE(volatile) flag set */
+static inline bool ll_lov_delay_create_is_set(unsigned int kernel_open_flags)
+{
+       return (kernel_open_flags & O_LOV_DELAY_CREATE) == O_LOV_DELAY_CREATE;
+}
+
+/* Clear (file.f_flag) O_LOV_DELAY_CREATE(volatile) flag */
+static inline void ll_lov_delay_create_clear(unsigned int *kernel_open_flags)
+{
+       if (ll_lov_delay_create_is_set(*kernel_open_flags))
+               *kernel_open_flags &= ~O_LOV_DELAY_CREATE;
+}
+
+enum mds_open_flags ll_kernel_to_mds_open_flags(unsigned int kernel_open_flags);
+
 struct inode *ll_iget(struct super_block *sb, ino_t hash,
                      struct lustre_md *lic);
 int ll_test_inode_by_fid(struct inode *inode, void *opaque);
index a7adafb..d4c486e 100644 (file)
@@ -261,24 +261,24 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock,
                                lock->l_req_mode, 0);
 
        if (bits & MDS_INODELOCK_OPEN) {
-               enum mds_open_flags fmode = MDS_FMODE_CLOSED;
+               enum mds_open_flags open_flags = MDS_FMODE_CLOSED;
 
                switch (lock->l_req_mode) {
                case LCK_CW:
-                       fmode = MDS_FMODE_WRITE;
+                       open_flags = MDS_FMODE_WRITE;
                        break;
                case LCK_PR:
-                       fmode = MDS_FMODE_EXEC;
+                       open_flags = MDS_FMODE_EXEC;
                        break;
                case LCK_CR:
-                       fmode = MDS_FMODE_READ;
+                       open_flags = MDS_FMODE_READ;
                        break;
                default:
                        LDLM_ERROR(lock, "bad lock mode for OPEN lock");
                        LBUG();
                }
 
-               ll_md_real_close(inode, fmode);
+               ll_md_real_close(inode, open_flags);
 
                bits &= ~MDS_INODELOCK_OPEN;
        }