From ec616826acdff3419db4f1c55e1d87f35ec3a1d3 Mon Sep 17 00:00:00 2001 From: fanyong Date: Mon, 13 Nov 2006 06:15:54 +0000 Subject: [PATCH] (1) add some condition check. (2) simplify lprocfs_wr_identity_flush. (3) add some comment. --- lustre/mdt/mdt_identity.c | 2 +- lustre/mdt/mdt_idmap.c | 25 +++++++++++++++++-------- lustre/mdt/mdt_lproc.c | 18 +++++------------- lustre/mdt/mdt_rmtacl.c | 10 +++++----- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lustre/mdt/mdt_identity.c b/lustre/mdt/mdt_identity.c index 0db1208..5de5b57 100644 --- a/lustre/mdt/mdt_identity.c +++ b/lustre/mdt/mdt_identity.c @@ -127,7 +127,7 @@ static int mdt_identity_parse_downcall(struct upcall_cache *cache, LASSERT(data); if (data->idd_ngroups > NGROUPS_MAX) - return -E2BIG; + RETURN(-E2BIG); ginfo = groups_alloc(data->idd_ngroups); if (!ginfo) { diff --git a/lustre/mdt/mdt_idmap.c b/lustre/mdt/mdt_idmap.c index bd1deb0..0a22e4a 100644 --- a/lustre/mdt/mdt_idmap.c +++ b/lustre/mdt/mdt_idmap.c @@ -655,16 +655,24 @@ int mdt_remote_perm_reverse_idmap(struct ptlrpc_request *req, return -EPERM; } - fsuid = mdt_idmap_lookup_uid(med->med_idmap, 1, perm->rp_fsuid); - if (fsuid == MDT_IDMAP_NOTFOUND) { - CERROR("no mapping for fsuid %u\n", perm->rp_fsuid); - return -EPERM; + if (perm->rp_uid != perm->rp_fsuid) { + fsuid = mdt_idmap_lookup_uid(med->med_idmap, 1, perm->rp_fsuid); + if (fsuid == MDT_IDMAP_NOTFOUND) { + CERROR("no mapping for fsuid %u\n", perm->rp_fsuid); + return -EPERM; + } + } else { + fsuid = uid; } - fsgid = mdt_idmap_lookup_gid(med->med_idmap, 1, perm->rp_fsgid); - if (fsgid == MDT_IDMAP_NOTFOUND) { - CERROR("no mapping for fsgid %u\n", perm->rp_fsgid); - return -EPERM; + if (perm->rp_gid != perm->rp_fsgid) { + fsgid = mdt_idmap_lookup_gid(med->med_idmap, 1, perm->rp_fsgid); + if (fsgid == MDT_IDMAP_NOTFOUND) { + CERROR("no mapping for fsgid %u\n", perm->rp_fsgid); + return -EPERM; + } + } else { + fsgid = gid; } perm->rp_uid = uid; @@ -698,6 +706,7 @@ int mdt_fix_attr_ucred(struct mdt_thread_info *info, __u32 op) if ((attr->la_valid & LA_GID) && (attr->la_gid != -1)) attr->la_gid = uc->mu_fsgid; } else { + /* for S_ISGID, inherit gid from his parent */ if (!(attr->la_mode & S_ISGID) && (attr->la_gid != -1)) attr->la_gid = uc->mu_fsgid; } diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index c4f885e..00b2511 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -60,7 +60,7 @@ static int lprocfs_rd_identity_expire(char *page, char **start, off_t off, { struct obd_device *obd = data; struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); - + *eof = 1; return snprintf(page, count, "%lu\n", mdt->mdt_identity_cache->uc_entry_expire / HZ); @@ -154,19 +154,11 @@ static int lprocfs_wr_identity_flush(struct file *file, const char *buffer, { struct obd_device *obd = data; struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); - char tmp[8]; - int uid; - - memset(tmp, 0, 8); - if (copy_from_user(tmp, buffer, (count > 7) ? 7 : count)) { - CERROR("%s: bad data\n", obd->obd_name); - return -EFAULT; - } + int rc, uid; - if (sscanf(tmp, "%d", &uid) != 1) { - CERROR("%s: invalid uid\n", obd->obd_name); - return -EFAULT; - } + rc = lprocfs_write_helper(buffer, count, &uid); + if (rc) + return rc; mdt_flush_identity(mdt->mdt_identity_cache, uid); return count; diff --git a/lustre/mdt/mdt_rmtacl.c b/lustre/mdt/mdt_rmtacl.c index 82325b6..c973679 100644 --- a/lustre/mdt/mdt_rmtacl.c +++ b/lustre/mdt/mdt_rmtacl.c @@ -198,15 +198,15 @@ struct upcall_cache_ops mdt_rmtacl_upcall_cache_ops = { int mdt_rmtacl_upcall(struct mdt_thread_info *info, unsigned long key, char *cmd, struct lu_buf *buf) { - struct ptlrpc_request *req = mdt_info_req(info); - struct obd_device *obd = req->rq_export->exp_obd; - struct mdt_device *mdt = info->mti_mdt; + struct ptlrpc_request *req = mdt_info_req(info); + struct obd_device *obd = req->rq_export->exp_obd; + struct mdt_device *mdt = info->mti_mdt; struct lvfs_ucred uc; struct md_ucred *uc0 = mdt_ucred(info); struct lvfs_run_ctxt saved; struct rmtacl_upcall_data data; - struct upcall_cache_entry *entry; - char *tmp = NULL; + struct upcall_cache_entry *entry; + char *tmp = NULL; int rc = 0; ENTRY; -- 1.8.3.1