From 5ecb7fd0b0af45a94af94ddaaa4f4fe1e59162bf Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Fri, 30 May 2014 09:54:57 -0400 Subject: [PATCH] LU-4416 osd-ldiskfs: vfs structs use fully typed uid/gid Since Linux 3.5, struct inode and iattr have used type kuid_t and kgid_t for uids and gids. There was a compatibility mode to avoid build failures with older code but it was removed in 3.14. Furthermode, SLES12 builds with UIDGID_STRICT_TYPE_CHECKS enabled, and needs to use the shim interfaces to build. This patch provides the shims for older releases without them. Signed-off-by: Jeff Mahoney Signed-off-by: James Simmons Change-Id: If4c70b10b4bc13aa90d729d56b25edbe1f52fa98 Reviewed-on: http://review.whamcloud.com/10161 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Peng Tao Reviewed-by: Bob Glossman Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 22 +++++++- lustre/osd-ldiskfs/osd_handler.c | 109 ++++++++++++++++++++------------------ lustre/osd-ldiskfs/osd_internal.h | 22 ++++++++ lustre/osd-ldiskfs/osd_io.c | 11 ++-- 4 files changed, 104 insertions(+), 60 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 81c6d7f..4264cd2 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -219,7 +219,7 @@ shrink_control, [ # # LIBCFS_PROCESS_NAMESPACE # -# 3.4 introduced process namespace +# 3.5 introduced process namespace AC_DEFUN([LIBCFS_PROCESS_NAMESPACE], [ LB_CHECK_LINUX_HEADER([linux/uidgid.h], [ AC_DEFINE(HAVE_UIDGID_HEADER, 1, @@ -227,6 +227,23 @@ LB_CHECK_LINUX_HEADER([linux/uidgid.h], [ ]) # LIBCFS_PROCESS_NAMESPACE # +# LIBCFS_I_UID_READ +# +# 3.5 added helpers to read the new uid/gid types from VFS structures +# SLE11 SP3 has uidgid.h but not the helpers +# +AC_DEFUN([LIBCFS_I_UID_READ], [ +LB_CHECK_COMPILE([if 'i_uid_read' is present], +i_uid_read, [ + #include +],[ + i_uid_read(NULL); +],[ + AC_DEFINE(HAVE_I_UID_READ, 1, [i_uid_read is present]) +]) +]) # LIBCFS_I_UID_READ + +# # LIBCFS_SOCK_ALLOC_FILE # # FC18 3.7.2-201 unexport sock_map_fd() change to @@ -331,8 +348,9 @@ LIBCFS_DUMP_TRACE_ADDRESS LC_SHRINK_CONTROL # 3.0 LIBCFS_STACKTRACE_WARNING -# 3.4 +# 3.5 LIBCFS_PROCESS_NAMESPACE +LIBCFS_I_UID_READ # 3.7 LIBCFS_SOCK_ALLOC_FILE # 3.8 diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index c9834e1..469a83d 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -1191,8 +1191,8 @@ static void osd_object_delete(const struct lu_env *env, struct lu_object *l) osd_index_fini(obj); if (inode != NULL) { struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave; - qid_t uid = inode->i_uid; - qid_t gid = inode->i_gid; + qid_t uid = i_uid_read(inode); + qid_t gid = i_gid_read(inode); iput(inode); obj->oo_inode = NULL; @@ -1687,26 +1687,26 @@ static struct timespec *osd_inode_time(const struct lu_env *env, static void osd_inode_getattr(const struct lu_env *env, - struct inode *inode, struct lu_attr *attr) -{ - attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE | - LA_SIZE | LA_BLOCKS | LA_UID | LA_GID | - LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE | - LA_TYPE; - - attr->la_atime = LTIME_S(inode->i_atime); - attr->la_mtime = LTIME_S(inode->i_mtime); - attr->la_ctime = LTIME_S(inode->i_ctime); - attr->la_mode = inode->i_mode; - attr->la_size = i_size_read(inode); - attr->la_blocks = inode->i_blocks; - attr->la_uid = inode->i_uid; - attr->la_gid = inode->i_gid; - attr->la_flags = LDISKFS_I(inode)->i_flags; - attr->la_nlink = inode->i_nlink; - attr->la_rdev = inode->i_rdev; - attr->la_blksize = 1 << inode->i_blkbits; - attr->la_blkbits = inode->i_blkbits; + struct inode *inode, struct lu_attr *attr) +{ + attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE | + LA_SIZE | LA_BLOCKS | LA_UID | LA_GID | + LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE | + LA_TYPE; + + attr->la_atime = LTIME_S(inode->i_atime); + attr->la_mtime = LTIME_S(inode->i_mtime); + attr->la_ctime = LTIME_S(inode->i_ctime); + attr->la_mode = inode->i_mode; + attr->la_size = i_size_read(inode); + attr->la_blocks = inode->i_blocks; + attr->la_uid = i_uid_read(inode); + attr->la_gid = i_gid_read(inode); + attr->la_flags = LDISKFS_I(inode)->i_flags; + attr->la_nlink = inode->i_nlink; + attr->la_rdev = inode->i_rdev; + attr->la_blksize = 1 << inode->i_blkbits; + attr->la_blkbits = inode->i_blkbits; } static int osd_attr_get(const struct lu_env *env, @@ -1737,6 +1737,8 @@ static int osd_declare_attr_set(const struct lu_env *env, struct osd_object *obj; struct osd_thread_info *info = osd_oti_get(env); struct lquota_id_info *qi = &info->oti_qi; + qid_t uid; + qid_t gid; long long bspace; int rc = 0; bool allocated; @@ -1768,7 +1770,7 @@ static int osd_declare_attr_set(const struct lu_env *env, * credits for updating quota accounting files and to trigger quota * space adjustment once the operation is completed.*/ if ((attr->la_valid & LA_UID) != 0 && - attr->la_uid != obj->oo_inode->i_uid) { + attr->la_uid != (uid = i_uid_read(obj->oo_inode))) { qi->lqi_type = USRQUOTA; /* inode accounting */ @@ -1785,7 +1787,7 @@ static int osd_declare_attr_set(const struct lu_env *env, RETURN(rc); /* and one less inode for the current uid */ - qi->lqi_id.qid_uid = obj->oo_inode->i_uid; + qi->lqi_id.qid_uid = uid; qi->lqi_space = -1; rc = osd_declare_qid(env, oh, qi, true, NULL); if (rc == -EDQUOT || rc == -EINPROGRESS) @@ -1807,7 +1809,7 @@ static int osd_declare_attr_set(const struct lu_env *env, RETURN(rc); /* and finally less blocks for the current owner */ - qi->lqi_id.qid_uid = obj->oo_inode->i_uid; + qi->lqi_id.qid_uid = uid; qi->lqi_space = -bspace; rc = osd_declare_qid(env, oh, qi, true, NULL); if (rc == -EDQUOT || rc == -EINPROGRESS) @@ -1817,7 +1819,7 @@ static int osd_declare_attr_set(const struct lu_env *env, } if (attr->la_valid & LA_GID && - attr->la_gid != obj->oo_inode->i_gid) { + attr->la_gid != (gid = i_gid_read(obj->oo_inode))) { qi->lqi_type = GRPQUOTA; /* inode accounting */ @@ -1834,7 +1836,7 @@ static int osd_declare_attr_set(const struct lu_env *env, RETURN(rc); /* and one less inode for the current gid */ - qi->lqi_id.qid_gid = obj->oo_inode->i_gid; + qi->lqi_id.qid_gid = gid; qi->lqi_space = -1; rc = osd_declare_qid(env, oh, qi, true, NULL); if (rc == -EDQUOT || rc == -EINPROGRESS) @@ -1856,7 +1858,7 @@ static int osd_declare_attr_set(const struct lu_env *env, RETURN(rc); /* and finally less blocks for the current owner */ - qi->lqi_id.qid_gid = obj->oo_inode->i_gid; + qi->lqi_id.qid_gid = gid; qi->lqi_space = -bspace; rc = osd_declare_qid(env, oh, qi, true, NULL); if (rc == -EDQUOT || rc == -EINPROGRESS) @@ -1892,17 +1894,17 @@ static int osd_inode_setattr(const struct lu_env *env, if (bits & LA_BLOCKS) inode->i_blocks = attr->la_blocks; #endif - if (bits & LA_MODE) - inode->i_mode = (inode->i_mode & S_IFMT) | - (attr->la_mode & ~S_IFMT); - if (bits & LA_UID) - inode->i_uid = attr->la_uid; - if (bits & LA_GID) - inode->i_gid = attr->la_gid; - if (bits & LA_NLINK) + if (bits & LA_MODE) + inode->i_mode = (inode->i_mode & S_IFMT) | + (attr->la_mode & ~S_IFMT); + if (bits & LA_UID) + i_uid_write(inode, attr->la_uid); + if (bits & LA_GID) + i_gid_write(inode, attr->la_gid); + if (bits & LA_NLINK) set_nlink(inode, attr->la_nlink); - if (bits & LA_RDEV) - inode->i_rdev = attr->la_rdev; + if (bits & LA_RDEV) + inode->i_rdev = attr->la_rdev; if (bits & LA_FLAGS) { /* always keep S_NOCMTIME */ @@ -1914,8 +1916,8 @@ static int osd_inode_setattr(const struct lu_env *env, static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr) { - if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) || - (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) { + if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) || + (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) { struct iattr iattr; int rc; @@ -1924,8 +1926,8 @@ static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr) iattr.ia_valid |= ATTR_UID; if (attr->la_valid & LA_GID) iattr.ia_valid |= ATTR_GID; - iattr.ia_uid = attr->la_uid; - iattr.ia_gid = attr->la_gid; + iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid); + iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid); rc = ll_vfs_dq_transfer(inode, &iattr); if (rc) { @@ -2443,13 +2445,13 @@ static int osd_declare_object_destroy(const struct lu_env *env, osd_trans_declare_op(env, oh, OSD_OT_DELETE, osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3); /* one less inode */ - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh, - false, true, NULL, false); + rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), + -1, oh, false, true, NULL, false); if (rc) RETURN(rc); /* data to be truncated */ - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh, - true, true, NULL, false); + rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), + 0, oh, true, true, NULL, false); RETURN(rc); } @@ -3133,16 +3135,16 @@ static struct obd_capa *osd_capa_get(const struct lu_env *env, case LC_ID_NONE: RETURN(NULL); case LC_ID_PLAIN: - capa->lc_uid = obj->oo_inode->i_uid; - capa->lc_gid = obj->oo_inode->i_gid; + capa->lc_uid = i_uid_read(obj->oo_inode); + capa->lc_gid = i_gid_read(obj->oo_inode); capa->lc_flags = LC_ID_PLAIN; break; case LC_ID_CONVERT: { __u32 d[4], s[4]; - s[0] = obj->oo_inode->i_uid; + s[0] = i_uid_read(obj->oo_inode); cfs_get_random_bytes(&(s[1]), sizeof(__u32)); - s[2] = obj->oo_inode->i_gid; + s[2] = i_uid_read(obj->oo_inode); cfs_get_random_bytes(&(s[3]), sizeof(__u32)); rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN); if (unlikely(rc)) @@ -3534,8 +3536,8 @@ static int osd_index_declare_ea_delete(const struct lu_env *env, inode = osd_dt_obj(dt)->oo_inode; LASSERT(inode); - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh, - true, true, NULL, false); + rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), + 0, oh, true, true, NULL, false); RETURN(rc); } @@ -4293,7 +4295,8 @@ static int osd_index_declare_ea_insert(const struct lu_env *env, /* We ignore block quota on meta pool (MDTs), so needn't * calculate how many blocks will be consumed by this index * insert */ - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, + rc = osd_declare_inode_qid(env, i_uid_read(inode), + i_gid_read(inode), 0, oh, true, true, NULL, false); } diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 856d66b..b248e05 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -726,6 +726,28 @@ static inline bool is_quota_glb_feat(const struct dt_index_features *feat) feat == &dt_quota_bgrp_features) ? true : false; } +#ifndef HAVE_I_UID_READ +static inline uid_t i_uid_read(const struct inode *inode) +{ + return inode->i_uid; +} + +static inline gid_t i_gid_read(const struct inode *inode) +{ + return inode->i_gid; +} + +static inline void i_uid_write(struct inode *inode, uid_t uid) +{ + inode->i_uid = uid; +} + +static inline void i_gid_write(struct inode *inode, gid_t gid) +{ + inode->i_gid = gid; +} +#endif + /* * Invariants, assertions. */ diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index 1e4e915..555b9fc 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -1036,7 +1036,7 @@ static int osd_declare_write_commit(const struct lu_env *env, /* make sure the over quota flags were not set */ lnb[0].flags &= ~(OBD_BRW_OVER_USRQUOTA | OBD_BRW_OVER_GRPQUOTA); - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, + rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), quota_space, oh, true, true, &flags, ignore_quota); @@ -1446,8 +1446,9 @@ out: * as llog or last_rcvd files. We needn't enforce quota on those * objects, so always set the lqi_space as 0. */ if (inode != NULL) - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, - 0, oh, true, true, NULL, false); + rc = osd_declare_inode_qid(env, i_uid_read(inode), + i_gid_read(inode), 0, oh, true, + true, NULL, false); RETURN(rc); } @@ -1611,8 +1612,8 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt, inode = osd_dt_obj(dt)->oo_inode; LASSERT(inode); - rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh, - true, true, NULL, false); + rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode), + 0, oh, true, true, NULL, false); RETURN(rc); } -- 1.8.3.1