Skip to content

Commit 26c5eaa

Browse files
committed
Merge tag 'ceph-for-4.12-rc1' of git://github.com/ceph/ceph-client
Pull ceph updates from Ilya Dryomov: "The two main items are support for disabling automatic rbd exclusive lock transfers from myself and the long awaited -ENOSPC handling series from Jeff. The former will allow rbd users to take advantage of exclusive lock's built-in blacklist/break-lock functionality while staying in control of who owns the lock. With the latter in place, we will abort filesystem writes on -ENOSPC instead of having them block indefinitely. Beyond that we've got the usual pile of filesystem fixes from Zheng, some refcount_t conversion patches from Elena and a patch for an ancient open() flags handling bug from Alexander" * tag 'ceph-for-4.12-rc1' of git://github.com/ceph/ceph-client: (31 commits) ceph: fix memory leak in __ceph_setxattr() ceph: fix file open flags on ppc64 ceph: choose readdir frag based on previous readdir reply rbd: exclusive map option rbd: return ResponseMessage result from rbd_handle_request_lock() rbd: kill rbd_is_lock_supported() rbd: support updating the lock cookie without releasing the lock rbd: store lock cookie rbd: ignore unlock errors rbd: fix error handling around rbd_init_disk() rbd: move rbd_unregister_watch() call into rbd_dev_image_release() rbd: move rbd_dev_destroy() call out of rbd_dev_image_release() ceph: when seeing write errors on an inode, switch to sync writes Revert "ceph: SetPageError() for writeback pages if writepages fails" ceph: handle epoch barriers in cap messages libceph: add an epoch_barrier field to struct ceph_osd_client libceph: abort already submitted but abortable requests when map or pool goes full libceph: allow requests to return immediately on full conditions if caller wishes libceph: remove req->r_replay_version ceph: make seeky readdir more efficient ...
2 parents 1176032 + eeca958 commit 26c5eaa

27 files changed

Lines changed: 706 additions & 277 deletions

‎drivers/block/rbd.c‎

Lines changed: 215 additions & 144 deletions
Large diffs are not rendered by default.

‎fs/ceph/addr.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,12 @@ static void writepages_finish(struct ceph_osd_request *req)
670670
bool remove_page;
671671

672672
dout("writepages_finish %p rc %d\n", inode, rc);
673-
if (rc < 0)
673+
if (rc < 0) {
674674
mapping_set_error(mapping, rc);
675+
ceph_set_error_write(ci);
676+
} else {
677+
ceph_clear_error_write(ci);
678+
}
675679

676680
/*
677681
* We lost the cache cap, need to truncate the page before
@@ -703,9 +707,6 @@ static void writepages_finish(struct ceph_osd_request *req)
703707
clear_bdi_congested(inode_to_bdi(inode),
704708
BLK_RW_ASYNC);
705709

706-
if (rc < 0)
707-
SetPageError(page);
708-
709710
ceph_put_snap_context(page_snap_context(page));
710711
page->private = 0;
711712
ClearPagePrivate(page);
@@ -1892,6 +1893,7 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
18921893
err = ceph_osdc_start_request(&fsc->client->osdc, rd_req, false);
18931894

18941895
wr_req->r_mtime = ci->vfs_inode.i_mtime;
1896+
wr_req->r_abort_on_full = true;
18951897
err2 = ceph_osdc_start_request(&fsc->client->osdc, wr_req, false);
18961898

18971899
if (!err)

‎fs/ceph/caps.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ static int send_cap_msg(struct cap_msg_args *arg)
10151015
void *p;
10161016
size_t extra_len;
10171017
struct timespec zerotime = {0};
1018+
struct ceph_osd_client *osdc = &arg->session->s_mdsc->fsc->client->osdc;
10181019

10191020
dout("send_cap_msg %s %llx %llx caps %s wanted %s dirty %s"
10201021
" seq %u/%u tid %llu/%llu mseq %u follows %lld size %llu/%llu"
@@ -1076,8 +1077,12 @@ static int send_cap_msg(struct cap_msg_args *arg)
10761077
ceph_encode_64(&p, arg->inline_data ? 0 : CEPH_INLINE_NONE);
10771078
/* inline data size */
10781079
ceph_encode_32(&p, 0);
1079-
/* osd_epoch_barrier (version 5) */
1080-
ceph_encode_32(&p, 0);
1080+
/*
1081+
* osd_epoch_barrier (version 5)
1082+
* The epoch_barrier is protected osdc->lock, so READ_ONCE here in
1083+
* case it was recently changed
1084+
*/
1085+
ceph_encode_32(&p, READ_ONCE(osdc->epoch_barrier));
10811086
/* oldest_flush_tid (version 6) */
10821087
ceph_encode_64(&p, arg->oldest_flush_tid);
10831088

@@ -1389,7 +1394,7 @@ static void __ceph_flush_snaps(struct ceph_inode_info *ci,
13891394
first_tid = cf->tid + 1;
13901395

13911396
capsnap = container_of(cf, struct ceph_cap_snap, cap_flush);
1392-
atomic_inc(&capsnap->nref);
1397+
refcount_inc(&capsnap->nref);
13931398
spin_unlock(&ci->i_ceph_lock);
13941399

13951400
dout("__flush_snaps %p capsnap %p tid %llu %s\n",
@@ -2202,7 +2207,7 @@ static void __kick_flushing_caps(struct ceph_mds_client *mdsc,
22022207
inode, capsnap, cf->tid,
22032208
ceph_cap_string(capsnap->dirty));
22042209

2205-
atomic_inc(&capsnap->nref);
2210+
refcount_inc(&capsnap->nref);
22062211
spin_unlock(&ci->i_ceph_lock);
22072212

22082213
ret = __send_flush_snap(inode, session, capsnap, cap->mseq,
@@ -3633,13 +3638,19 @@ void ceph_handle_caps(struct ceph_mds_session *session,
36333638
p += inline_len;
36343639
}
36353640

3641+
if (le16_to_cpu(msg->hdr.version) >= 5) {
3642+
struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc;
3643+
u32 epoch_barrier;
3644+
3645+
ceph_decode_32_safe(&p, end, epoch_barrier, bad);
3646+
ceph_osdc_update_epoch_barrier(osdc, epoch_barrier);
3647+
}
3648+
36363649
if (le16_to_cpu(msg->hdr.version) >= 8) {
36373650
u64 flush_tid;
36383651
u32 caller_uid, caller_gid;
3639-
u32 osd_epoch_barrier;
36403652
u32 pool_ns_len;
3641-
/* version >= 5 */
3642-
ceph_decode_32_safe(&p, end, osd_epoch_barrier, bad);
3653+
36433654
/* version >= 6 */
36443655
ceph_decode_64_safe(&p, end, flush_tid, bad);
36453656
/* version >= 7 */

‎fs/ceph/debugfs.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@ static int mdsmap_show(struct seq_file *s, void *p)
2222
{
2323
int i;
2424
struct ceph_fs_client *fsc = s->private;
25+
struct ceph_mdsmap *mdsmap;
2526

2627
if (fsc->mdsc == NULL || fsc->mdsc->mdsmap == NULL)
2728
return 0;
28-
seq_printf(s, "epoch %d\n", fsc->mdsc->mdsmap->m_epoch);
29-
seq_printf(s, "root %d\n", fsc->mdsc->mdsmap->m_root);
30-
seq_printf(s, "session_timeout %d\n",
31-
fsc->mdsc->mdsmap->m_session_timeout);
32-
seq_printf(s, "session_autoclose %d\n",
33-
fsc->mdsc->mdsmap->m_session_autoclose);
34-
for (i = 0; i < fsc->mdsc->mdsmap->m_max_mds; i++) {
35-
struct ceph_entity_addr *addr =
36-
&fsc->mdsc->mdsmap->m_info[i].addr;
37-
int state = fsc->mdsc->mdsmap->m_info[i].state;
38-
29+
mdsmap = fsc->mdsc->mdsmap;
30+
seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
31+
seq_printf(s, "root %d\n", mdsmap->m_root);
32+
seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
33+
seq_printf(s, "session_timeout %d\n", mdsmap->m_session_timeout);
34+
seq_printf(s, "session_autoclose %d\n", mdsmap->m_session_autoclose);
35+
for (i = 0; i < mdsmap->m_num_mds; i++) {
36+
struct ceph_entity_addr *addr = &mdsmap->m_info[i].addr;
37+
int state = mdsmap->m_info[i].state;
3938
seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,
4039
ceph_pr_addr(&addr->in_addr),
4140
ceph_mds_state_name(state));

‎fs/ceph/dir.c‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
294294
struct ceph_mds_client *mdsc = fsc->mdsc;
295295
int i;
296296
int err;
297-
u32 ftype;
297+
unsigned frag = -1;
298298
struct ceph_mds_reply_info_parsed *rinfo;
299299

300300
dout("readdir %p file %p pos %llx\n", inode, file, ctx->pos);
@@ -341,7 +341,6 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
341341
/* do we have the correct frag content buffered? */
342342
if (need_send_readdir(fi, ctx->pos)) {
343343
struct ceph_mds_request *req;
344-
unsigned frag;
345344
int op = ceph_snap(inode) == CEPH_SNAPDIR ?
346345
CEPH_MDS_OP_LSSNAP : CEPH_MDS_OP_READDIR;
347346

@@ -352,8 +351,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
352351
}
353352

354353
if (is_hash_order(ctx->pos)) {
355-
frag = ceph_choose_frag(ci, fpos_hash(ctx->pos),
356-
NULL, NULL);
354+
/* fragtree isn't always accurate. choose frag
355+
* based on previous reply when possible. */
356+
if (frag == (unsigned)-1)
357+
frag = ceph_choose_frag(ci, fpos_hash(ctx->pos),
358+
NULL, NULL);
357359
} else {
358360
frag = fpos_frag(ctx->pos);
359361
}
@@ -378,7 +380,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
378380
ceph_mdsc_put_request(req);
379381
return -ENOMEM;
380382
}
383+
} else if (is_hash_order(ctx->pos)) {
384+
req->r_args.readdir.offset_hash =
385+
cpu_to_le32(fpos_hash(ctx->pos));
381386
}
387+
382388
req->r_dir_release_cnt = fi->dir_release_count;
383389
req->r_dir_ordered_cnt = fi->dir_ordered_count;
384390
req->r_readdir_cache_idx = fi->readdir_cache_idx;
@@ -476,6 +482,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
476482
struct ceph_mds_reply_dir_entry *rde = rinfo->dir_entries + i;
477483
struct ceph_vino vino;
478484
ino_t ino;
485+
u32 ftype;
479486

480487
BUG_ON(rde->offset < ctx->pos);
481488

@@ -498,15 +505,17 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
498505
ctx->pos++;
499506
}
500507

508+
ceph_mdsc_put_request(fi->last_readdir);
509+
fi->last_readdir = NULL;
510+
501511
if (fi->next_offset > 2) {
502-
ceph_mdsc_put_request(fi->last_readdir);
503-
fi->last_readdir = NULL;
512+
frag = fi->frag;
504513
goto more;
505514
}
506515

507516
/* more frags? */
508517
if (!ceph_frag_is_rightmost(fi->frag)) {
509-
unsigned frag = ceph_frag_next(fi->frag);
518+
frag = ceph_frag_next(fi->frag);
510519
if (is_hash_order(ctx->pos)) {
511520
loff_t new_pos = ceph_make_fpos(ceph_frag_value(frag),
512521
fi->next_offset, true);

‎fs/ceph/file.c‎

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,38 @@
1313
#include "mds_client.h"
1414
#include "cache.h"
1515

16+
static __le32 ceph_flags_sys2wire(u32 flags)
17+
{
18+
u32 wire_flags = 0;
19+
20+
switch (flags & O_ACCMODE) {
21+
case O_RDONLY:
22+
wire_flags |= CEPH_O_RDONLY;
23+
break;
24+
case O_WRONLY:
25+
wire_flags |= CEPH_O_WRONLY;
26+
break;
27+
case O_RDWR:
28+
wire_flags |= CEPH_O_RDWR;
29+
break;
30+
}
31+
32+
#define ceph_sys2wire(a) if (flags & a) { wire_flags |= CEPH_##a; flags &= ~a; }
33+
34+
ceph_sys2wire(O_CREAT);
35+
ceph_sys2wire(O_EXCL);
36+
ceph_sys2wire(O_TRUNC);
37+
ceph_sys2wire(O_DIRECTORY);
38+
ceph_sys2wire(O_NOFOLLOW);
39+
40+
#undef ceph_sys2wire
41+
42+
if (flags)
43+
dout("unused open flags: %x", flags);
44+
45+
return cpu_to_le32(wire_flags);
46+
}
47+
1648
/*
1749
* Ceph file operations
1850
*
@@ -120,7 +152,7 @@ prepare_open_request(struct super_block *sb, int flags, int create_mode)
120152
if (IS_ERR(req))
121153
goto out;
122154
req->r_fmode = ceph_flags_to_mode(flags);
123-
req->r_args.open.flags = cpu_to_le32(flags);
155+
req->r_args.open.flags = ceph_flags_sys2wire(flags);
124156
req->r_args.open.mode = cpu_to_le32(create_mode);
125157
out:
126158
return req;
@@ -189,7 +221,7 @@ int ceph_renew_caps(struct inode *inode)
189221
spin_lock(&ci->i_ceph_lock);
190222
wanted = __ceph_caps_file_wanted(ci);
191223
if (__ceph_is_any_real_caps(ci) &&
192-
(!(wanted & CEPH_CAP_ANY_WR) == 0 || ci->i_auth_cap)) {
224+
(!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap)) {
193225
int issued = __ceph_caps_issued(ci, NULL);
194226
spin_unlock(&ci->i_ceph_lock);
195227
dout("renew caps %p want %s issued %s updating mds_wanted\n",
@@ -778,6 +810,7 @@ static void ceph_aio_retry_work(struct work_struct *work)
778810
req->r_callback = ceph_aio_complete_req;
779811
req->r_inode = inode;
780812
req->r_priv = aio_req;
813+
req->r_abort_on_full = true;
781814

782815
ret = ceph_osdc_start_request(req->r_osdc, req, false);
783816
out:
@@ -1085,19 +1118,22 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
10851118

10861119
out:
10871120
ceph_osdc_put_request(req);
1088-
if (ret == 0) {
1089-
pos += len;
1090-
written += len;
1091-
1092-
if (pos > i_size_read(inode)) {
1093-
check_caps = ceph_inode_set_size(inode, pos);
1094-
if (check_caps)
1095-
ceph_check_caps(ceph_inode(inode),
1096-
CHECK_CAPS_AUTHONLY,
1097-
NULL);
1098-
}
1099-
} else
1121+
if (ret != 0) {
1122+
ceph_set_error_write(ci);
11001123
break;
1124+
}
1125+
1126+
ceph_clear_error_write(ci);
1127+
pos += len;
1128+
written += len;
1129+
if (pos > i_size_read(inode)) {
1130+
check_caps = ceph_inode_set_size(inode, pos);
1131+
if (check_caps)
1132+
ceph_check_caps(ceph_inode(inode),
1133+
CHECK_CAPS_AUTHONLY,
1134+
NULL);
1135+
}
1136+
11011137
}
11021138

11031139
if (ret != -EOLDSNAPC && written > 0) {
@@ -1303,6 +1339,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
13031339
}
13041340

13051341
retry_snap:
1342+
/* FIXME: not complete since it doesn't account for being at quota */
13061343
if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL)) {
13071344
err = -ENOSPC;
13081345
goto out;
@@ -1324,7 +1361,8 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
13241361
inode, ceph_vinop(inode), pos, count, ceph_cap_string(got));
13251362

13261363
if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
1327-
(iocb->ki_flags & IOCB_DIRECT) || (fi->flags & CEPH_F_SYNC)) {
1364+
(iocb->ki_flags & IOCB_DIRECT) || (fi->flags & CEPH_F_SYNC) ||
1365+
(ci->i_ceph_flags & CEPH_I_ERROR_WRITE)) {
13281366
struct ceph_snap_context *snapc;
13291367
struct iov_iter data;
13301368
inode_unlock(inode);

‎fs/ceph/inode.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,10 +1482,17 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
14821482
if (test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags))
14831483
return readdir_prepopulate_inodes_only(req, session);
14841484

1485-
if (rinfo->hash_order && req->r_path2) {
1486-
last_hash = ceph_str_hash(ci->i_dir_layout.dl_dir_hash,
1487-
req->r_path2, strlen(req->r_path2));
1488-
last_hash = ceph_frag_value(last_hash);
1485+
if (rinfo->hash_order) {
1486+
if (req->r_path2) {
1487+
last_hash = ceph_str_hash(ci->i_dir_layout.dl_dir_hash,
1488+
req->r_path2,
1489+
strlen(req->r_path2));
1490+
last_hash = ceph_frag_value(last_hash);
1491+
} else if (rinfo->offset_hash) {
1492+
/* mds understands offset_hash */
1493+
WARN_ON_ONCE(req->r_readdir_offset != 2);
1494+
last_hash = le32_to_cpu(rhead->args.readdir.offset_hash);
1495+
}
14891496
}
14901497

14911498
if (rinfo->dir_dir &&
@@ -1510,7 +1517,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
15101517
}
15111518

15121519
if (ceph_frag_is_leftmost(frag) && req->r_readdir_offset == 2 &&
1513-
!(rinfo->hash_order && req->r_path2)) {
1520+
!(rinfo->hash_order && last_hash)) {
15141521
/* note dir version at start of readdir so we can tell
15151522
* if any dentries get dropped */
15161523
req->r_dir_release_cnt = atomic64_read(&ci->i_release_count);

0 commit comments

Comments
 (0)