From: Arshad Hussain Date: Thu, 5 Sep 2024 03:26:42 +0000 (-0400) Subject: LU-12885 mds: add enums for MDS_OPEN flags (3/4) X-Git-Tag: 2.16.52~40 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=948fcacd8be4e915219ada19e492e26486a231d3;p=fs%2Flustre-release.git LU-12885 mds: add enums for MDS_OPEN flags (3/4) This patch is third of the series of patch that separates kernel open flags from MDS open flags This third step completes all of the MDS-side changes This patch also changes/adds kernel-style doc instead of old doxygen style wherever required Signed-off-by: Arshad Hussain Change-Id: I209ce38b49f9ee3c39b2ed8d16d231291cf5cdd1 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56534 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre_mds.h b/lustre/include/lustre_mds.h index feac8bd..bc10473 100644 --- a/lustre/include/lustre_mds.h +++ b/lustre/include/lustre_mds.h @@ -37,7 +37,7 @@ struct md_rejig_data { #define MDD_OBD_NAME "mdd_obd" #define MDD_OBD_UUID "mdd_obd_uuid" -static inline int md_should_create(u64 open_flags) +static inline int md_should_create(enum mds_open_flags open_flags) { return !(open_flags & MDS_OPEN_DELAY_CREATE) && (open_flags & MDS_FMODE_WRITE) && @@ -45,7 +45,7 @@ static inline int md_should_create(u64 open_flags) } /* do NOT or the MAY_*'s, you'll get the weakest */ -static inline int mds_accmode(u64 open_flags) +static inline int mds_accmode(enum mds_open_flags open_flags) { unsigned int may_mask = 0; diff --git a/lustre/include/md_object.h b/lustre/include/md_object.h index 0800308..3e9a2f9 100644 --- a/lustre/include/md_object.h +++ b/lustre/include/md_object.h @@ -130,7 +130,7 @@ struct md_op_spec { } u; /** Open flags from client: such as MDS_OPEN_CREAT, and others. */ - __u64 sp_cr_flags; + enum mds_open_flags sp_cr_flags; /* File security context for creates. */ const char *sp_cr_file_secctx_name; /* (security) xattr name */ @@ -248,7 +248,7 @@ struct md_object_operations { struct md_device *m, const struct lu_fid *fid); int (*moo_open)(const struct lu_env *env, struct md_object *obj, - u64 open_flags, struct md_op_spec *spec); + enum mds_open_flags open_flags, struct md_op_spec *spc); int (*moo_close)(const struct lu_env *env, struct md_object *obj, struct md_attr *ma, u64 open_flags); diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 123c991..8e24a98 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -1246,7 +1246,7 @@ struct obd_client_handle { struct md_open_data *och_mod; struct lustre_handle och_lease_handle; /* open lock for lease */ __u32 och_magic; - int och_flags; + enum mds_open_flags och_flags; /* Open flags from client */ }; #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 1095a08..d3b52381 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -1964,7 +1964,7 @@ struct changelog_ext_nid { /* Changelog extra extension to include low 32 bits of MDS_OPEN_* flags. */ struct changelog_ext_openmode { - __u32 cr_openflags; + __u32 cr_openflags; /* enum mds_open_flags */ }; /* Changelog extra extension to include xattr */ diff --git a/lustre/llite/file.c b/lustre/llite/file.c index f19cd03..ea0b766 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -272,7 +272,17 @@ out: return rc; } -int ll_md_real_close(struct inode *inode, fmode_t fmode) +/** + * ll_md_real_close() - called when file is closed. Called from ll_file_release + * + * @inode: inode which is getting closed + * @fd_open_mode: MDS flags passed from client + * + * Return: + * * 0 on success + * * <0 on error + */ +int ll_md_real_close(struct inode *inode, enum mds_open_flags fd_open_mode) { struct ll_inode_info *lli = ll_i2info(inode); struct obd_client_handle **och_p; @@ -281,14 +291,14 @@ int ll_md_real_close(struct inode *inode, fmode_t fmode) int rc = 0; ENTRY; - if (fmode & FMODE_WRITE) { + if (fd_open_mode & MDS_FMODE_WRITE) { och_p = &lli->lli_mds_write_och; och_usecount = &lli->lli_open_fd_write_count; - } else if (fmode & FMODE_EXEC) { + } else if (fd_open_mode & MDS_FMODE_EXEC) { och_p = &lli->lli_mds_exec_och; och_usecount = &lli->lli_open_fd_exec_count; } else { - LASSERT(fmode & FMODE_READ); + LASSERT(fd_open_mode & MDS_FMODE_READ); och_p = &lli->lli_mds_read_och; och_usecount = &lli->lli_open_fd_read_count; } @@ -364,11 +374,11 @@ static int ll_md_close(struct inode *inode, struct file *file) /* Let's see if we have good enough OPEN lock on the file and if we can * skip talking to MDS */ - if (lfd->fd_omode & FMODE_WRITE) { + if (lfd->fd_open_mode & MDS_FMODE_WRITE) { lockmode = LCK_CW; LASSERT(lli->lli_open_fd_write_count); lli->lli_open_fd_write_count--; - } else if (lfd->fd_omode & FMODE_EXEC) { + } else if (lfd->fd_open_mode & MDS_FMODE_EXEC) { lockmode = LCK_PR; LASSERT(lli->lli_open_fd_exec_count); lli->lli_open_fd_exec_count--; @@ -383,7 +393,7 @@ static int ll_md_close(struct inode *inode, struct file *file) if ((lockmode == LCK_CW && inode->i_mode & 0111) || !md_lock_match(ll_i2mdexp(inode), flags, ll_inode2fid(inode), LDLM_IBITS, &policy, lockmode, 0, &lockh)) - rc = ll_md_real_close(inode, lfd->fd_omode); + rc = ll_md_real_close(inode, lfd->fd_open_mode); out: file->private_data = NULL; @@ -787,8 +797,9 @@ static int ll_local_open(struct file *file, struct lookup_intent *it, file->private_data = lfd; ll_readahead_init(inode, &lfd->fd_ras); - lfd->fd_omode = it->it_open_flags & (FMODE_READ | FMODE_WRITE | - FMODE_EXEC); + lfd->fd_open_mode = it->it_open_flags & (MDS_FMODE_READ | + MDS_FMODE_WRITE | + MDS_FMODE_EXEC); RETURN(0); } @@ -879,26 +890,26 @@ int ll_file_open(struct inode *inode, struct file *file) if ((oit.it_open_flags + 1) & O_ACCMODE) oit.it_open_flags++; if (file->f_flags & O_TRUNC) - oit.it_open_flags |= FMODE_WRITE; + oit.it_open_flags |= MDS_FMODE_WRITE; /* kernel only call f_op->open in dentry_open. filp_open calls * dentry_open after call to open_namei that checks permissions. * Only nfsd_open call dentry_open directly without checking * permissions and because of that this code below is safe. */ - if (oit.it_open_flags & (FMODE_WRITE | FMODE_READ)) + if (oit.it_open_flags & (MDS_FMODE_WRITE | MDS_FMODE_READ)) oit.it_open_flags |= MDS_OPEN_OWNEROVERRIDE; /* We do not want O_EXCL here, presumably we opened the file * already? XXX - NFS implications? */ - oit.it_open_flags &= ~O_EXCL; + oit.it_open_flags &= ~MDS_OPEN_EXCL; /* bug20584, if "it_open_flags" contains O_CREAT, file will be * created if necessary, then "IT_CREAT" should be set to keep * consistent with it */ - if (oit.it_open_flags & O_CREAT) + if (oit.it_open_flags & MDS_OPEN_CREAT) oit.it_op |= IT_CREAT; it = &oit; @@ -906,10 +917,10 @@ int ll_file_open(struct inode *inode, struct file *file) restart: /* Let's see if we have file open on MDS already. */ - if (it->it_open_flags & FMODE_WRITE) { + if (it->it_open_flags & MDS_FMODE_WRITE) { och_p = &lli->lli_mds_write_och; och_usecount = &lli->lli_open_fd_write_count; - } else if (it->it_open_flags & FMODE_EXEC) { + } else if (it->it_open_flags & MDS_FMODE_EXEC) { och_p = &lli->lli_mds_exec_och; och_usecount = &lli->lli_open_fd_exec_count; } else { @@ -1194,10 +1205,21 @@ static int ll_lease_och_release(struct inode *inode, struct file *file) RETURN(rc); } -/* Acquire a lease and open the file. */ +/** + * ll_lease_open() - Acquire a lease(block other open() call on this file) + * and open the file. + * + * @inode: mount point + * @file: file to open + * @fmode: Kernel mode open flag pass to open() (permissions) + * @open_flags: MDS flags passed from client + * + * Return: + * * populate obd_client_handle object on success + */ static struct obd_client_handle * ll_lease_open(struct inode *inode, struct file *file, fmode_t fmode, - __u64 open_flags) + enum mds_open_flags open_flags) { struct lookup_intent it = { .it_op = IT_OPEN }; struct ll_sb_info *sbi = ll_i2sbi(inode); @@ -2033,7 +2055,7 @@ out: RETURN(result > 0 ? result : rc); } -/** +/* * The purpose of fast read is to overcome per I/O overhead and improve IOPS * especially for small I/O. * @@ -2109,7 +2131,7 @@ ll_do_fast_read(struct kiocb *iocb, struct iov_iter *iter) return result; } -/** +/* * Confine read iter lest read beyond the EOF * * \param iocb [in] kernel iocb @@ -2428,7 +2450,7 @@ static ssize_t ll_do_tiny_write(struct kiocb *iocb, struct iov_iter *iter) RETURN(result); } -/* Write to a file (through the page cache). */ +/* Write to a file (through the page cache).*/ static ssize_t do_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; @@ -2620,7 +2642,6 @@ 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) { @@ -3434,8 +3455,6 @@ restart: } /* - * Read the data_version for inode. - * * This value is computed using stripe object version on OST. * Version is computed using server side locking. * @@ -3746,10 +3765,10 @@ out: RETURN(rc); } -static inline long ll_lease_type_from_fmode(fmode_t fmode) +static inline long ll_lease_type_from_fmode(enum mds_open_flags fd_open_mode) { - return ((fmode & FMODE_READ) ? LL_LEASE_RDLCK : 0) | - ((fmode & FMODE_WRITE) ? LL_LEASE_WRLCK : 0); + return ((fd_open_mode & MDS_FMODE_READ) ? LL_LEASE_RDLCK : 0) | + ((fd_open_mode & MDS_FMODE_WRITE) ? LL_LEASE_WRLCK : 0); } static int ll_file_futimes_3(struct file *file, const struct ll_futimes_3 *lfu) @@ -4215,7 +4234,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; - fmode_t fmode = 0; + enum mds_open_flags fmode = MDS_FMODE_CLOSED; enum mds_op_bias bias = 0; __u32 fdv; struct file *layout_file = NULL; @@ -4339,7 +4358,7 @@ out_lease_close: GOTO(out, rc); if (lease_broken) - fmode = 0; + fmode = MDS_FMODE_CLOSED; EXIT; out: @@ -4372,9 +4391,9 @@ static long ll_file_set_lease(struct file *file, struct ll_ioc_lease *ioc, struct ll_inode_info *lli = ll_i2info(inode); struct ll_file_data *lfd = file->private_data; struct obd_client_handle *och = NULL; - __u64 open_flags = 0; + enum mds_open_flags open_flags = MDS_FMODE_CLOSED; bool lease_broken; - fmode_t fmode; + fmode_t fmode; /* kernel permissions */ long rc; ENTRY; @@ -4723,7 +4742,7 @@ skip_copy: case LL_IOC_GET_LEASE: { struct ll_inode_info *lli = ll_i2info(inode); struct ldlm_lock *lock = NULL; - fmode_t fmode = 0; + enum mds_open_flags fmode = MDS_FMODE_CLOSED; mutex_lock(&lli->lli_och_mutex); if (lfd->fd_lease_och != NULL) { @@ -5164,7 +5183,6 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end, * null and dentry must be used directly rather than pulled from * file_dentry() as is done otherwise. */ - int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync) { struct dentry *dentry = file_dentry(file); @@ -6683,7 +6701,6 @@ out: /* Fetch layout from MDT with getxattr request, if it's not ready yet */ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) - { struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req; @@ -6890,7 +6907,7 @@ static int ll_layout_intent(struct inode *inode, struct layout_intent *intent) intent->lai_opc == LAYOUT_INTENT_TRUNC || intent->lai_opc == LAYOUT_INTENT_PCCRO_SET || intent->lai_opc == LAYOUT_INTENT_PCCRO_CLEAR) - it.it_open_flags = FMODE_WRITE; + it.it_open_flags = MDS_FMODE_WRITE; LDLM_DEBUG_NOLOCK("%s: requeue layout lock for file "DFID"(%p)", sbi->ll_fsname, PFID(&lli->lli_fid), inode); diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 2b49fe4..02d2e0e 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1146,7 +1146,7 @@ struct ll_file_data { struct ll_grouplock fd_grouplock; __u64 lfd_pos; __u32 fd_flags; - fmode_t fd_omode; + enum mds_open_flags fd_open_mode; /* openhandle if lease exists for this file. * Borrow lli->lli_och_mutex to protect assignment */ @@ -1376,7 +1376,7 @@ extern enum ldlm_mode ll_take_md_lock(struct inode *inode, __u64 bits, int ll_file_open(struct inode *inode, struct file *file); int ll_file_release(struct inode *inode, struct file *file); int ll_release_openhandle(struct dentry *d, struct lookup_intent *l); -int ll_md_real_close(struct inode *inode, fmode_t fmode); +int ll_md_real_close(struct inode *inode, enum mds_open_flags fd_open_mode); void ll_track_file_opens(struct inode *inode); extern void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, struct ll_file_data *file, loff_t pos, diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index f8f5d32..90c8681 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -261,17 +261,17 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, lock->l_req_mode, 0); if (bits & MDS_INODELOCK_OPEN) { - fmode_t fmode; + enum mds_open_flags fmode = MDS_FMODE_CLOSED; switch (lock->l_req_mode) { case LCK_CW: - fmode = FMODE_WRITE; + fmode = MDS_FMODE_WRITE; break; case LCK_PR: - fmode = FMODE_EXEC; + fmode = MDS_FMODE_EXEC; break; case LCK_CR: - fmode = FMODE_READ; + fmode = MDS_FMODE_READ; break; default: LDLM_ERROR(lock, "bad lock mode for OPEN lock"); @@ -1004,7 +1004,7 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry, RETURN(dentry == save ? NULL : dentry); } - if (it->it_op & IT_OPEN && it->it_open_flags & FMODE_WRITE && + if (it->it_op & IT_OPEN && it->it_open_flags & MDS_FMODE_WRITE && dentry->d_sb->s_flags & SB_RDONLY) RETURN(ERR_PTR(-EROFS)); @@ -1288,9 +1288,10 @@ do { \ #endif -/* - * For cached negative dentry and new dentry, handle lookup/create/open - * together. +/** + * ll_atomic_open() - For cached negative dentry and new dentry, handle + * lookup/create/open together. This method is only called + * if the last component is negative(needs lookup) */ static int ll_atomic_open(struct inode *dir, struct dentry *dentry, struct file *file, unsigned int open_flags, diff --git a/lustre/lmv/lmv_intent.c b/lustre/lmv/lmv_intent.c index 196221c..bc0174b 100644 --- a/lustre/lmv/lmv_intent.c +++ b/lustre/lmv/lmv_intent.c @@ -273,11 +273,11 @@ static int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data, ldlm_blocking_callback cb_blocking, __u64 extra_lock_flags) { + enum mds_open_flags flags = it->it_open_flags; struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; struct lmv_tgt_desc *tgt; struct mdt_body *body; - __u64 flags = it->it_open_flags; int rc; ENTRY; @@ -310,7 +310,7 @@ static int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data, * layout first, to avoid creating new file * under old layout, clear O_CREAT. */ - it->it_open_flags &= ~O_CREAT; + it->it_open_flags &= ~MDS_OPEN_CREAT; } } } diff --git a/lustre/mdc/mdc_lib.c b/lustre/mdc/mdc_lib.c index 2c431ae..8fed24a 100644 --- a/lustre/mdc/mdc_lib.c +++ b/lustre/mdc/mdc_lib.c @@ -21,7 +21,16 @@ #include #include "mdc_internal.h" -static void set_mrc_cr_flags(struct mdt_rec_create *mrc, __u64 flags) +/* + * set_mrc_cr_flags() - Move @flags into high(most significant bits (cr_flags_h) + * and low(least significant bits (cr_flags_l)) field under + * reint record + * + * @mrc: instance of mdt_reint_rec + * @flags: open flags passed from client + */ +static void set_mrc_cr_flags(struct mdt_rec_create *mrc, + enum mds_open_flags flags) { mrc->cr_flags_l = (__u32)(flags & 0xFFFFFFFFUll); mrc->cr_flags_h = (__u32)(flags >> 32); @@ -180,8 +189,8 @@ void mdc_create_pack(struct req_capsule *pill, struct md_op_data *op_data, struct sptlrpc_sepol *sepol) { struct mdt_rec_create *rec; + enum mds_open_flags flags; char *tmp; - __u64 flags; BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_create)); @@ -237,9 +246,9 @@ void mdc_create_pack(struct req_capsule *pill, struct md_op_data *op_data, mdc_file_sepol_pack(pill, sepol); } -static inline __u64 mds_pack_open_flags(__u64 flags) +static inline __u64 mds_pack_open_flags(enum mds_open_flags flags) { - __u64 cr_flags = (flags & MDS_OPEN_FL_INTERNAL); + enum mds_open_flags cr_flags = (flags & MDS_OPEN_FL_INTERNAL); if (flags & FMODE_READ) cr_flags |= MDS_FMODE_READ; @@ -276,8 +285,8 @@ void mdc_open_pack(struct req_capsule *pill, struct md_op_data *op_data, size_t lmmlen, struct sptlrpc_sepol *sepol) { struct mdt_rec_create *rec; + enum mds_open_flags cr_flags; char *tmp; - __u64 cr_flags; BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_create)); diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 9328652..12d7970 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -193,7 +193,7 @@ static int mdd_links_read_with_rec(const struct lu_env *env, * * \retval 0 if getting the parent FID succeeds. * \retval negative errno if getting the parent FID fails. - **/ + */ static inline int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj, const struct lu_attr *attr, @@ -386,7 +386,7 @@ int mdd_dir_is_empty(const struct lu_env *env, struct mdd_object *dir) RETURN(result); } -/** +/* * Determine if the target object can be hard linked, and right now it only * checks if the link count reach the maximum limit. Note: for ldiskfs, the * directory nlink count might exceed the maximum link count(see @@ -2285,7 +2285,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj, * XXX: Setting the lov ea is not locked but setting the attr is locked? * Should this be fixed? */ - CDEBUG(D_OTHER, "ea %p/%u, cr_flags %#llo, no_create %u\n", + CDEBUG(D_OTHER, "ea %p/%u, cr_flags %#lo, no_create %u\n", spec->u.sp_ea.eadata, spec->u.sp_ea.eadatalen, spec->sp_cr_flags, spec->no_create); diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index b753198..8ddeec4 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -34,7 +34,7 @@ static const struct lu_object_operations mdd_lu_obj_ops; struct mdd_object_user { struct list_head mou_list; /* linked off mod_users */ - u64 mou_open_flags; /* open mode by client */ + enum mds_open_flags mou_open_flags; /* open mode by client */ __u64 mou_uidgid; /* uid_gid on client */ int mou_opencount; /* # opened */ /* time of next access denied notificaiton */ @@ -56,8 +56,7 @@ static int mdd_changelog_data_store_by_fid(const struct lu_env *env, static inline bool has_prefix(const char *str, const char *prefix); - -static u32 flags_helper(u64 open_flags) +static u32 mdd_open_flags_to_mode(enum mds_open_flags open_flags) { u32 open_mode = 0; @@ -74,18 +73,21 @@ static u32 flags_helper(u64 open_flags) return open_mode; } -/** Allocate/init a user and its sub-structures. +/** + * mdd_obj_user_alloc() - Allocate/init a user and its sub-structures. + * + * @flags: open flags passed from client + * @uid: client uid + * @gid: client gid * - * \param flags [IN] - * \param uid [IN] - * \param gid [IN] - * \retval mou [OUT] success valid structure - * \retval mou [OUT] + * Return: + * * populate mdd_object_user with valid struct on success */ -static struct mdd_object_user *mdd_obj_user_alloc(u64 open_flags, +static struct mdd_object_user *mdd_obj_user_alloc(enum mds_open_flags o_flags, uid_t uid, gid_t gid) { struct mdd_object_user *mou; + enum mds_open_flags open_flags = o_flags; ENTRY; @@ -112,18 +114,21 @@ static void mdd_obj_user_free(struct mdd_object_user *mou) } /** - * Find if UID/GID already has this file open + * mdd_obj_user_find() - Find if UID/GID already has this file open * - * Caller should have write-locked \param mdd_obj. - * \param mdd_obj [IN] mdd_obj - * \param uid [IN] client uid - * \param gid [IN] client gid - * \retval user pointer or NULL if not found + * @mdd_obj: Metadata server side object + * @uid: Client UID + * @gid: Client GID + * @open_flags: MDS flags passed from client + * + * Caller should have write-locked on param @mdd_obj. + * + * Return: mdd_object_user pointer or NULL if not found */ static struct mdd_object_user *mdd_obj_user_find(struct mdd_object *mdd_obj, uid_t uid, gid_t gid, - u64 open_flags) + enum mds_open_flags open_flags) { struct mdd_object_user *mou; __u64 uidgid; @@ -133,8 +138,8 @@ struct mdd_object_user *mdd_obj_user_find(struct mdd_object *mdd_obj, uidgid = ((__u64)uid << 32) | gid; list_for_each_entry(mou, &mdd_obj->mod_users, mou_list) { if (mou->mou_uidgid == uidgid && - flags_helper(mou->mou_open_flags) == - flags_helper(open_flags)) + mdd_open_flags_to_mode(mou->mou_open_flags) == + mdd_open_flags_to_mode(open_flags)) RETURN(mou); } RETURN(NULL); @@ -177,6 +182,7 @@ static int mdd_obj_user_add(struct mdd_object *mdd_obj, RETURN(0); } + /** * Remove UID from the list * @@ -199,6 +205,7 @@ static int mdd_obj_user_remove(struct mdd_object *mdd_obj, RETURN(0); } + int mdd_la_get(const struct lu_env *env, struct mdd_object *obj, struct lu_attr *la) { @@ -3609,7 +3616,7 @@ void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent, } static int mdd_accmode(const struct lu_env *env, const struct lu_attr *la, - u64 open_flags) + enum mds_open_flags open_flags) { /* Sadly, NFSD reopens a file repeatedly during operation, so the * "acc_mode = 0" allowance for newly-created files isn't honoured. @@ -3627,10 +3634,23 @@ static int mdd_accmode(const struct lu_env *env, const struct lu_attr *la, return mds_accmode(open_flags); } +/** + * mdd_open_sanity_check() - Check if mdd object is valid(not unlinked) + * + * @env: execution environment for this thread + * @obj: metadata object + * @attr: common attribute of the object + * @open_flags: MDS flags passed from client + * @is_replay: Additional params passed to open/create + * + * Return: + * * O on success + * * negative errno on failure + */ static int mdd_open_sanity_check(const struct lu_env *env, struct mdd_object *obj, - const struct lu_attr *attr, u64 open_flags, - int is_replay) + const struct lu_attr *attr, + enum mds_open_flags open_flags, int is_replay) { unsigned int may_mask; int rc; @@ -3674,8 +3694,20 @@ static int mdd_open_sanity_check(const struct lu_env *env, RETURN(0); } +/** + * mdd_open() - Called when object under metadata is opened + * + * @env: execution environment for this thread + * @obj: metadata object + * @open_flags: MDS flags passed from client + * @spec: Additional params passed to open/create + * + * Return: + * * 0 on Success + * * <0 on Failure + */ static int mdd_open(const struct lu_env *env, struct md_object *obj, - u64 open_flags, struct md_op_spec *spec) + enum mds_open_flags open_flags, struct md_op_spec *spec) { struct mdd_object *mdd_obj = md2mdd_obj(obj); struct md_device *md_dev = lu2md_dev(mdd2lu_dev(mdo2mdd(obj))); diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 30593b6..19febc4 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -48,7 +48,7 @@ struct mdt_file_data { /* export data of portals_handle */ const struct mdt_export_data *mfd_owner; /** open mode provided by client */ - u64 mfd_open_flags; + enum mds_open_flags mfd_open_flags; /** protected by med_open_lock */ struct list_head mfd_list; /** xid of the open request */ @@ -901,7 +901,7 @@ int mdt_export_stats_init(struct obd_device *obd, struct obd_export *exp, int mdt_lock_new_child(struct mdt_thread_info *info, struct mdt_object *o, struct mdt_lock_handle *child_lockh); -void mdt_mfd_set_mode(struct mdt_file_data *mfd, u64 open_flags); +void mdt_mfd_set_mode(struct mdt_file_data *mfd, enum mds_open_flags o_flags); int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc); struct mdt_file_data *mdt_open_handle2mfd(struct mdt_export_data *med, const struct lustre_handle *open_handle, @@ -996,7 +996,8 @@ int mdt_pack_encctx_in_reply(struct mdt_thread_info *info, struct mdt_object *child); void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info, struct mdt_object *obj, struct md_attr *ma, - __u64 open_flags); + enum mds_open_flags open_flags); + static inline struct mdt_device *mdt_dev(struct lu_device *d) { diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 18a0ca5..0d81076 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -274,11 +274,17 @@ static void mdt_empty_transno(struct mdt_thread_info *info, int rc) EXIT; } -void mdt_mfd_set_mode(struct mdt_file_data *mfd, u64 open_flags) +/** + * mdt_mfd_set_mode() - Set MDS open flags into @mfd + * + * @mfd: mdt_file_data object per open handle + * @open_flags: open flags passed from client + */ +void mdt_mfd_set_mode(struct mdt_file_data *mfd, enum mds_open_flags open_flags) { LASSERT(mfd != NULL); - CDEBUG(D_DENTRY, DFID " Change mfd open_flags %#llo -> %#llo.\n", + CDEBUG(D_DENTRY, DFID " Change mfd open_flags %#lo -> %#lo.\n", PFID(mdt_object_fid(mfd->mfd_object)), mfd->mfd_open_flags, open_flags); @@ -286,11 +292,19 @@ void mdt_mfd_set_mode(struct mdt_file_data *mfd, u64 open_flags) } /** - * prep ma_lmm/ma_lmv for md_attr from reply + * mdt_prep_ma_buf_from_rep() - prep ma_lmm/ma_lmv for md_attr from reply + * + * @info: Common data shared by mdt-level handlers + * @obj: metadata object + * @ma: attributes to be evaluated for that object + * @open_flags: open flags passed from client + * + * Return: + * * void */ void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info, struct mdt_object *obj, struct md_attr *ma, - __u64 open_flags) + enum mds_open_flags open_flags) { struct req_capsule *pill; @@ -329,9 +343,23 @@ void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info, } } +/* + * mdt_mfd_open() - open object in metadata server + * + * @info: Common data shared by mdt-level handlers + * @p: Parent mdt object + * @o: Child mdt object + * @open_flags: open flags passed from client + * @created: Object already existing/created + * @rep: ldlm_reply object + * + * Return: + * * 0 on success + * * <0 on failure + */ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, - struct mdt_object *o, u64 open_flags, int created, - struct ldlm_reply *rep) + struct mdt_object *o, enum mds_open_flags open_flags, + int created, struct ldlm_reply *rep) { struct ptlrpc_request *req = mdt_info_req(info); struct mdt_export_data *med = &req->rq_export->exp_mdt_data; @@ -510,7 +538,7 @@ err_out: static int mdt_finish_open(struct mdt_thread_info *info, struct mdt_object *p, struct mdt_object *o, - u64 open_flags, + enum mds_open_flags open_flags, struct ldlm_reply *rep) { struct ptlrpc_request *req = mdt_info_req(info); @@ -705,7 +733,7 @@ out: static int mdt_open_by_fid(struct mdt_thread_info *info, struct ldlm_reply *rep, struct mdt_lock_handle *lhc) { - u64 open_flags = info->mti_spec.sp_cr_flags; + enum mds_open_flags open_flags = info->mti_spec.sp_cr_flags; struct mdt_reint_record *rr = &info->mti_rr; struct md_attr *ma = &info->mti_attr; struct mdt_object *o; @@ -767,7 +795,7 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, __u64 *ibits) { struct md_attr *ma = &info->mti_attr; - __u64 open_flags = info->mti_spec.sp_cr_flags; + enum mds_open_flags open_flags = info->mti_spec.sp_cr_flags; __u64 trybits = 0; enum ldlm_mode lm = LCK_PR; bool acq_lease = !!(open_flags & MDS_OPEN_LEASE); @@ -824,7 +852,7 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, /* Lease must be with open lock */ if (!(open_flags & MDS_OPEN_LOCK)) { CERROR("%s: Request lease for file:"DFID ", but open lock " - "is missed, open_flags = %#llo : rc = %d\n", + "is missed, open_flags = %#lo : rc = %d\n", mdt_obd_name(info->mti_mdt), PFID(mdt_object_fid(obj)), open_flags, -EPROTO); GOTO(out, rc = -EPROTO); @@ -899,7 +927,7 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, rc = mdt_object_lock_try(info, obj, lhc, ibits, trybits, lm); CDEBUG(D_INODE, "%s: Requested bits lock:"DFID ", ibits = %#llx/%#llx" - ", open_flags = %#llo, try_layout = %d : rc = %d\n", + ", open_flags = %#lo, try_layout = %d : rc = %d\n", mdt_obd_name(info->mti_mdt), PFID(mdt_object_fid(obj)), *ibits, trybits, open_flags, try_layout, rc); @@ -908,7 +936,7 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, struct mdt_lock_handle *ll = &info->mti_lh[MDT_LH_LAYOUT]; CDEBUG(D_INODE, "Will create layout, get EX layout lock:"DFID - ", open_flags = %#llo\n", + ", open_flags = %#lo\n", PFID(mdt_object_fid(obj)), open_flags); /* We cannot enqueue another lock for the same resource we @@ -976,7 +1004,7 @@ static void mdt_object_open_unlock(struct mdt_thread_info *info, struct mdt_lock_handle *lhc, __u64 ibits, int rc) { - __u64 open_flags = info->mti_spec.sp_cr_flags; + enum mds_open_flags open_flags = info->mti_spec.sp_cr_flags; struct mdt_lock_handle *ll = &info->mti_lh[MDT_LH_LOCAL]; ENTRY; @@ -1199,7 +1227,8 @@ out_parent_put: static int mdt_cross_open(struct mdt_thread_info *info, const struct lu_fid *parent_fid, const struct lu_fid *fid, - struct ldlm_reply *rep, u64 open_flags) + struct ldlm_reply *rep, + enum mds_open_flags open_flags) { struct md_attr *ma = &info->mti_attr; struct mdt_object *o; @@ -1325,7 +1354,7 @@ static int mdt_lock_root_xattr(struct mdt_thread_info *info, static inline enum ldlm_mode mdt_open_lock_mode(struct mdt_thread_info *info, struct mdt_object *p, struct lu_name *name, - u64 open_flags) + enum mds_open_flags open_flags) { int result; struct lu_fid fid; @@ -1384,7 +1413,7 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) struct lu_fid *child_fid = &info->mti_tmp_fid1; struct lu_ucred *uc = mdt_ucred(info); struct md_attr *ma = &info->mti_attr; - u64 open_flags = info->mti_spec.sp_cr_flags; + enum mds_open_flags open_flags = info->mti_spec.sp_cr_flags; u64 ibits = 0; struct mdt_reint_record *rr = &info->mti_rr; int result, rc; @@ -1417,7 +1446,7 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) GOTO(out, result = -EROFS); CDEBUG(D_INODE, "I am going to open "DFID"/("DNAME"->"DFID") " - "cr_flag=%#llo mode=0%06o msg_flag=0x%x\n", + "cr_flag=%#lo mode=0%06o msg_flag=0x%x\n", PFID(rr->rr_fid1), PNAME(&rr->rr_name), PFID(rr->rr_fid2), open_flags, ma->ma_attr.la_mode, msg_flags);