void mdd_buf_put(struct lu_buf *buf)
{
- if (buf == NULL || buf->lb_buf == NULL)
- return;
- OBD_FREE_LARGE(buf->lb_buf, buf->lb_len);
- buf->lb_buf = NULL;
- buf->lb_len = 0;
+ if (buf == NULL || buf->lb_buf == NULL)
+ return;
+ OBD_FREE_LARGE(buf->lb_buf, buf->lb_len);
+ *buf = LU_BUF_NULL;
}
const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len)
{
- struct lu_buf *buf = &mdd_env_info(env)->mti_big_buf;
+ struct lu_buf *buf = &mdd_env_info(env)->mti_big_buf;
- if ((len > buf->lb_len) && (buf->lb_buf != NULL)) {
- OBD_FREE_LARGE(buf->lb_buf, buf->lb_len);
- buf->lb_buf = NULL;
- }
- if (buf->lb_buf == NULL) {
- buf->lb_len = len;
- OBD_ALLOC_LARGE(buf->lb_buf, buf->lb_len);
- if (buf->lb_buf == NULL)
- buf->lb_len = 0;
- }
- return buf;
+ if ((len > buf->lb_len) && (buf->lb_buf != NULL)) {
+ OBD_FREE_LARGE(buf->lb_buf, buf->lb_len);
+ *buf = LU_BUF_NULL;
+ }
+ if (memcmp(buf, &LU_BUF_NULL, sizeof(*buf)) == 0) {
+ buf->lb_len = len;
+ OBD_ALLOC_LARGE(buf->lb_buf, buf->lb_len);
+ if (buf->lb_buf == NULL)
+ *buf = LU_BUF_NULL;
+ }
+ return buf;
}
/** Increase the size of the \a mti_big_buf.
/* Verify that our path hasn't changed since we started the lookup.
Record the current index, and verify the path resolves to the
same fid. If it does, then the path is correct as of this index. */
- cfs_spin_lock(&mdd->mdd_cl.mc_lock);
- pli->pli_currec = mdd->mdd_cl.mc_index;
- cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+ spin_lock(&mdd->mdd_cl.mc_lock);
+ pli->pli_currec = mdd->mdd_cl.mc_index;
+ spin_unlock(&mdd->mdd_cl.mc_lock);
rc = mdd_path2fid(env, mdd, ptr, &pli->pli_fid);
if (rc) {
CDEBUG(D_INFO, "mdd_path2fid(%s) failed %d\n", ptr, rc);
struct lu_attr *la, const unsigned long flags)
{
struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
- struct md_ucred *uc;
+ struct lu_ucred *uc;
int rc;
ENTRY;
if (la->la_valid & (LA_NLINK | LA_RDEV | LA_BLKSIZE))
RETURN(-EPERM);
- /* export destroy does not have ->le_ses, but we may want
- * to drop LUSTRE_SOM_FL. */
- if (!env->le_ses)
- RETURN(0);
-
- uc = md_ucred(env);
+ /* export destroy does not have ->le_ses, but we may want
+ * to drop LUSTRE_SOM_FL. */
+ uc = lu_ucred_check(env);
+ if (uc == NULL)
+ RETURN(0);
rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA);
if (rc)
unsigned int newflags = la->la_flags &
(LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL);
- if ((uc->mu_fsuid != tmp_la->la_uid) &&
- !mdd_capable(uc, CFS_CAP_FOWNER))
- RETURN(-EPERM);
+ if ((uc->uc_fsuid != tmp_la->la_uid) &&
+ !mdd_capable(uc, CFS_CAP_FOWNER))
+ RETURN(-EPERM);
/* XXX: the IMMUTABLE and APPEND_ONLY flags can
* only be changed by the relevant capability. */
!(flags & MDS_PERM_BYPASS))
RETURN(-EPERM);
- /* Check for setting the obj time. */
- if ((la->la_valid & (LA_MTIME | LA_ATIME | LA_CTIME)) &&
- !(la->la_valid & ~(LA_MTIME | LA_ATIME | LA_CTIME))) {
- if ((uc->mu_fsuid != tmp_la->la_uid) &&
- !mdd_capable(uc, CFS_CAP_FOWNER)) {
+ /* Check for setting the obj time. */
+ if ((la->la_valid & (LA_MTIME | LA_ATIME | LA_CTIME)) &&
+ !(la->la_valid & ~(LA_MTIME | LA_ATIME | LA_CTIME))) {
+ if ((uc->uc_fsuid != tmp_la->la_uid) &&
+ !mdd_capable(uc, CFS_CAP_FOWNER)) {
rc = mdd_permission_internal(env, obj, tmp_la,
MAY_WRITE);
- if (rc)
- RETURN(rc);
- }
- }
+ if (rc)
+ RETURN(rc);
+ }
+ }
if (la->la_valid & LA_KILL_SUID) {
la->la_valid &= ~LA_KILL_SUID;
/* Make sure a caller can chmod. */
if (la->la_valid & LA_MODE) {
if (!(flags & MDS_PERM_BYPASS) &&
- (uc->mu_fsuid != tmp_la->la_uid) &&
- !mdd_capable(uc, CFS_CAP_FOWNER))
- RETURN(-EPERM);
+ (uc->uc_fsuid != tmp_la->la_uid) &&
+ !mdd_capable(uc, CFS_CAP_FOWNER))
+ RETURN(-EPERM);
if (la->la_mode == (cfs_umode_t) -1)
la->la_mode = tmp_la->la_mode;
if (la->la_valid & LA_UID) {
if (la->la_uid == (uid_t) -1)
la->la_uid = tmp_la->la_uid;
- if (((uc->mu_fsuid != tmp_la->la_uid) ||
- (la->la_uid != tmp_la->la_uid)) &&
- !mdd_capable(uc, CFS_CAP_CHOWN))
- RETURN(-EPERM);
+ if (((uc->uc_fsuid != tmp_la->la_uid) ||
+ (la->la_uid != tmp_la->la_uid)) &&
+ !mdd_capable(uc, CFS_CAP_CHOWN))
+ RETURN(-EPERM);
/* If the user or group of a non-directory has been
* changed by a non-root user, remove the setuid bit.
if (la->la_valid & LA_GID) {
if (la->la_gid == (gid_t) -1)
la->la_gid = tmp_la->la_gid;
- if (((uc->mu_fsuid != tmp_la->la_uid) ||
- ((la->la_gid != tmp_la->la_gid) &&
- !lustre_in_group_p(uc, la->la_gid))) &&
- !mdd_capable(uc, CFS_CAP_CHOWN))
- RETURN(-EPERM);
+ if (((uc->uc_fsuid != tmp_la->la_uid) ||
+ ((la->la_gid != tmp_la->la_gid) &&
+ !lustre_in_group_p(uc, la->la_gid))) &&
+ !mdd_capable(uc, CFS_CAP_CHOWN))
+ RETURN(-EPERM);
/* Likewise, if the user or group of a non-directory
* has been changed by a non-root user, remove the
} else {
if (la->la_valid & (LA_SIZE | LA_BLOCKS)) {
if (!((flags & MDS_OPEN_OWNEROVERRIDE) &&
- (uc->mu_fsuid == tmp_la->la_uid)) &&
+ (uc->uc_fsuid == tmp_la->la_uid)) &&
!(flags & MDS_PERM_BYPASS)) {
rc = mdd_permission_internal(env, obj,
tmp_la, MAY_WRITE);
}
static int mdd_xattr_sanity_check(const struct lu_env *env,
- struct mdd_object *obj)
+ struct mdd_object *obj)
{
- struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
- struct md_ucred *uc = md_ucred(env);
- int rc;
- ENTRY;
+ struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
+ struct lu_ucred *uc = lu_ucred_assert(env);
+ int rc;
+ ENTRY;
- if (mdd_is_immutable(obj) || mdd_is_append(obj))
- RETURN(-EPERM);
+ if (mdd_is_immutable(obj) || mdd_is_append(obj))
+ RETURN(-EPERM);
- rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA);
- if (rc)
- RETURN(rc);
+ rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA);
+ if (rc)
+ RETURN(rc);
- if ((uc->mu_fsuid != tmp_la->la_uid) &&
- !mdd_capable(uc, CFS_CAP_FOWNER))
- RETURN(-EPERM);
+ if ((uc->uc_fsuid != tmp_la->la_uid) &&
+ !mdd_capable(uc, CFS_CAP_FOWNER))
+ RETURN(-EPERM);
- RETURN(rc);
+ RETURN(rc);
}
static int mdd_declare_xattr_set(const struct lu_env *env,
*/
int accmode(const struct lu_env *env, struct lu_attr *la, int flags)
{
- int res = 0;
-
- /* Sadly, NFSD reopens a file repeatedly during operation, so the
- * "acc_mode = 0" allowance for newly-created files isn't honoured.
- * NFSD uses the MDS_OPEN_OWNEROVERRIDE flag to say that a file
- * owner can write to a file even if it is marked readonly to hide
- * its brokenness. (bug 5781) */
- if (flags & MDS_OPEN_OWNEROVERRIDE) {
- struct md_ucred *uc = md_ucred(env);
-
- if ((uc == NULL) || (uc->mu_valid == UCRED_INIT) ||
- (la->la_uid == uc->mu_fsuid))
- return 0;
- }
+ int res = 0;
+
+ /* Sadly, NFSD reopens a file repeatedly during operation, so the
+ * "acc_mode = 0" allowance for newly-created files isn't honoured.
+ * NFSD uses the MDS_OPEN_OWNEROVERRIDE flag to say that a file
+ * owner can write to a file even if it is marked readonly to hide
+ * its brokenness. (bug 5781) */
+ if (flags & MDS_OPEN_OWNEROVERRIDE) {
+ struct lu_ucred *uc = lu_ucred_check(env);
+
+ if ((uc == NULL) || (la->la_uid == uc->uc_fsuid))
+ return 0;
+ }
- if (flags & FMODE_READ)
- res |= MAY_READ;
- if (flags & (FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
- res |= MAY_WRITE;
- if (flags & MDS_FMODE_EXEC)
- res = MAY_EXEC;
- return res;
+ if (flags & FMODE_READ)
+ res |= MAY_READ;
+ if (flags & (FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
+ res |= MAY_WRITE;
+ if (flags & MDS_FMODE_EXEC)
+ res = MAY_EXEC;
+ return res;
}
static int mdd_open_sanity_check(const struct lu_env *env,
* Now, flag -- O_NOATIME does not be packed by client.
*/
if (flag & O_NOATIME) {
- struct md_ucred *uc = md_ucred(env);
+ struct lu_ucred *uc = lu_ucred(env);
- if (uc && ((uc->mu_valid == UCRED_OLD) ||
- (uc->mu_valid == UCRED_NEW)) &&
- (uc->mu_fsuid != tmp_la->la_uid) &&
- !mdd_capable(uc, CFS_CAP_FOWNER))
- RETURN(-EPERM);
+ if (uc && ((uc->uc_valid == UCRED_OLD) ||
+ (uc->uc_valid == UCRED_NEW)) &&
+ (uc->uc_fsuid != tmp_la->la_uid) &&
+ !mdd_capable(uc, CFS_CAP_FOWNER))
+ RETURN(-EPERM);
}
#endif