Skip to content

Commit 2b14864

Browse files
committed
Merge tag 'ceph-for-5.16-rc6' of git://github.com/ceph/ceph-client
Pull ceph fixes from Ilya Dryomov: "An SGID directory handling fix (marked for stable), a metrics accounting fix and two fixups to appease static checkers" * tag 'ceph-for-5.16-rc6' of git://github.com/ceph/ceph-client: ceph: fix up non-directory creation in SGID directories ceph: initialize pathlen variable in reconnect_caps_cb ceph: initialize i_size variable in ceph_sync_read ceph: fix duplicate increment of opened_inodes metric
2 parents d9c1e64 + fd84bfd commit 2b14864

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

fs/ceph/caps.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,27 +4350,27 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
43504350
{
43514351
struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->vfs_inode.i_sb);
43524352
int bits = (fmode << 1) | 1;
4353-
bool is_opened = false;
4353+
bool already_opened = false;
43544354
int i;
43554355

43564356
if (count == 1)
43574357
atomic64_inc(&mdsc->metric.opened_files);
43584358

43594359
spin_lock(&ci->i_ceph_lock);
43604360
for (i = 0; i < CEPH_FILE_MODE_BITS; i++) {
4361-
if (bits & (1 << i))
4362-
ci->i_nr_by_mode[i] += count;
4363-
43644361
/*
4365-
* If any of the mode ref is larger than 1,
4362+
* If any of the mode ref is larger than 0,
43664363
* that means it has been already opened by
43674364
* others. Just skip checking the PIN ref.
43684365
*/
4369-
if (i && ci->i_nr_by_mode[i] > 1)
4370-
is_opened = true;
4366+
if (i && ci->i_nr_by_mode[i])
4367+
already_opened = true;
4368+
4369+
if (bits & (1 << i))
4370+
ci->i_nr_by_mode[i] += count;
43714371
}
43724372

4373-
if (!is_opened)
4373+
if (!already_opened)
43744374
percpu_counter_inc(&mdsc->metric.opened_inodes);
43754375
spin_unlock(&ci->i_ceph_lock);
43764376
}

fs/ceph/file.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,25 @@ static int ceph_finish_async_create(struct inode *dir, struct dentry *dentry,
605605
in.cap.realm = cpu_to_le64(ci->i_snap_realm->ino);
606606
in.cap.flags = CEPH_CAP_FLAG_AUTH;
607607
in.ctime = in.mtime = in.atime = iinfo.btime;
608-
in.mode = cpu_to_le32((u32)mode);
609608
in.truncate_seq = cpu_to_le32(1);
610609
in.truncate_size = cpu_to_le64(-1ULL);
611610
in.xattr_version = cpu_to_le64(1);
612611
in.uid = cpu_to_le32(from_kuid(&init_user_ns, current_fsuid()));
613-
in.gid = cpu_to_le32(from_kgid(&init_user_ns, dir->i_mode & S_ISGID ?
614-
dir->i_gid : current_fsgid()));
612+
if (dir->i_mode & S_ISGID) {
613+
in.gid = cpu_to_le32(from_kgid(&init_user_ns, dir->i_gid));
614+
615+
/* Directories always inherit the setgid bit. */
616+
if (S_ISDIR(mode))
617+
mode |= S_ISGID;
618+
else if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP) &&
619+
!in_group_p(dir->i_gid) &&
620+
!capable_wrt_inode_uidgid(&init_user_ns, dir, CAP_FSETID))
621+
mode &= ~S_ISGID;
622+
} else {
623+
in.gid = cpu_to_le32(from_kgid(&init_user_ns, current_fsgid()));
624+
}
625+
in.mode = cpu_to_le32((u32)mode);
626+
615627
in.nlink = cpu_to_le32(1);
616628
in.max_size = cpu_to_le64(lo->stripe_unit);
617629

@@ -847,7 +859,7 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
847859
ssize_t ret;
848860
u64 off = iocb->ki_pos;
849861
u64 len = iov_iter_count(to);
850-
u64 i_size;
862+
u64 i_size = i_size_read(inode);
851863

852864
dout("sync_read on file %p %llu~%u %s\n", file, off, (unsigned)len,
853865
(file->f_flags & O_DIRECT) ? "O_DIRECT" : "");

fs/ceph/mds_client.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,7 +3683,7 @@ static int reconnect_caps_cb(struct inode *inode, struct ceph_cap *cap,
36833683
struct ceph_pagelist *pagelist = recon_state->pagelist;
36843684
struct dentry *dentry;
36853685
char *path;
3686-
int pathlen, err;
3686+
int pathlen = 0, err;
36873687
u64 pathbase;
36883688
u64 snap_follows;
36893689

@@ -3703,7 +3703,6 @@ static int reconnect_caps_cb(struct inode *inode, struct ceph_cap *cap,
37033703
}
37043704
} else {
37053705
path = NULL;
3706-
pathlen = 0;
37073706
pathbase = 0;
37083707
}
37093708

0 commit comments

Comments
 (0)