Skip to content

Commit 7731032

Browse files
ukernelidryomov
authored andcommitted
ceph: renew caps for read/write if mds session got killed.
When mds session gets killed, read/write operation may hang. Client waits for Frw caps, but mds does not know what caps client wants. To recover this, client sends an open request to mds. The request will tell mds what caps client wants. Signed-off-by: Yan, Zheng <zyan@redhat.com>
1 parent d463a43 commit 7731032

4 files changed

Lines changed: 93 additions & 11 deletions

File tree

‎fs/ceph/caps.c‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
23172317

23182318
/* make sure file is actually open */
23192319
file_wanted = __ceph_caps_file_wanted(ci);
2320-
if ((file_wanted & need) == 0) {
2320+
if ((file_wanted & need) != need) {
23212321
dout("try_get_cap_refs need %s file_wanted %s, EBADF\n",
23222322
ceph_cap_string(need), ceph_cap_string(file_wanted));
23232323
*err = -EBADF;
@@ -2412,12 +2412,26 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
24122412
goto out_unlock;
24132413
}
24142414

2415-
if (!__ceph_is_any_caps(ci) &&
2416-
ACCESS_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) {
2417-
dout("get_cap_refs %p forced umount\n", inode);
2418-
*err = -EIO;
2419-
ret = 1;
2420-
goto out_unlock;
2415+
if (ci->i_ceph_flags & CEPH_I_CAP_DROPPED) {
2416+
int mds_wanted;
2417+
if (ACCESS_ONCE(mdsc->fsc->mount_state) ==
2418+
CEPH_MOUNT_SHUTDOWN) {
2419+
dout("get_cap_refs %p forced umount\n", inode);
2420+
*err = -EIO;
2421+
ret = 1;
2422+
goto out_unlock;
2423+
}
2424+
mds_wanted = __ceph_caps_mds_wanted(ci);
2425+
if ((mds_wanted & need) != need) {
2426+
dout("get_cap_refs %p caps were dropped"
2427+
" (session killed?)\n", inode);
2428+
*err = -ESTALE;
2429+
ret = 1;
2430+
goto out_unlock;
2431+
}
2432+
if ((mds_wanted & file_wanted) ==
2433+
(file_wanted & (CEPH_CAP_FILE_RD|CEPH_CAP_FILE_WR)))
2434+
ci->i_ceph_flags &= ~CEPH_I_CAP_DROPPED;
24212435
}
24222436

24232437
dout("get_cap_refs %p have %s needed %s\n", inode,
@@ -2487,7 +2501,7 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
24872501
if (err == -EAGAIN)
24882502
continue;
24892503
if (err < 0)
2490-
return err;
2504+
ret = err;
24912505
} else {
24922506
ret = wait_event_interruptible(ci->i_cap_wq,
24932507
try_get_cap_refs(ci, need, want, endoff,
@@ -2496,8 +2510,15 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
24962510
continue;
24972511
if (err < 0)
24982512
ret = err;
2499-
if (ret < 0)
2500-
return ret;
2513+
}
2514+
if (ret < 0) {
2515+
if (err == -ESTALE) {
2516+
/* session was killed, try renew caps */
2517+
ret = ceph_renew_caps(&ci->vfs_inode);
2518+
if (ret == 0)
2519+
continue;
2520+
}
2521+
return ret;
25012522
}
25022523

25032524
if (ci->i_inline_version != CEPH_INLINE_NONE &&
@@ -3226,6 +3247,8 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
32263247

32273248
if (target < 0) {
32283249
__ceph_remove_cap(cap, false);
3250+
if (!ci->i_auth_cap)
3251+
ci->i_ceph_flags |= CEPH_I_CAP_DROPPED;
32293252
goto out_unlock;
32303253
}
32313254

‎fs/ceph/file.c‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,59 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
191191
return ret;
192192
}
193193

194+
/*
195+
* try renew caps after session gets killed.
196+
*/
197+
int ceph_renew_caps(struct inode *inode)
198+
{
199+
struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
200+
struct ceph_inode_info *ci = ceph_inode(inode);
201+
struct ceph_mds_request *req;
202+
int err, flags, wanted;
203+
204+
spin_lock(&ci->i_ceph_lock);
205+
wanted = __ceph_caps_file_wanted(ci);
206+
if (__ceph_is_any_real_caps(ci) &&
207+
(!(wanted & CEPH_CAP_ANY_WR) == 0 || ci->i_auth_cap)) {
208+
int issued = __ceph_caps_issued(ci, NULL);
209+
spin_unlock(&ci->i_ceph_lock);
210+
dout("renew caps %p want %s issued %s updating mds_wanted\n",
211+
inode, ceph_cap_string(wanted), ceph_cap_string(issued));
212+
ceph_check_caps(ci, 0, NULL);
213+
return 0;
214+
}
215+
spin_unlock(&ci->i_ceph_lock);
216+
217+
flags = 0;
218+
if ((wanted & CEPH_CAP_FILE_RD) && (wanted & CEPH_CAP_FILE_WR))
219+
flags = O_RDWR;
220+
else if (wanted & CEPH_CAP_FILE_RD)
221+
flags = O_RDONLY;
222+
else if (wanted & CEPH_CAP_FILE_WR)
223+
flags = O_WRONLY;
224+
#ifdef O_LAZY
225+
if (wanted & CEPH_CAP_FILE_LAZYIO)
226+
flags |= O_LAZY;
227+
#endif
228+
229+
req = prepare_open_request(inode->i_sb, flags, 0);
230+
if (IS_ERR(req)) {
231+
err = PTR_ERR(req);
232+
goto out;
233+
}
234+
235+
req->r_inode = inode;
236+
ihold(inode);
237+
req->r_num_caps = 1;
238+
req->r_fmode = -1;
239+
240+
err = ceph_mdsc_do_request(mdsc, NULL, req);
241+
ceph_mdsc_put_request(req);
242+
out:
243+
dout("renew caps %p open result=%d\n", inode, err);
244+
return err < 0 ? err : 0;
245+
}
246+
194247
/*
195248
* If we already have the requisite capabilities, we can satisfy
196249
* the open request locally (no need to request new caps from the

‎fs/ceph/mds_client.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,8 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap,
11331133
struct ceph_mds_client *mdsc =
11341134
ceph_sb_to_client(inode->i_sb)->mdsc;
11351135

1136+
ci->i_ceph_flags |= CEPH_I_CAP_DROPPED;
1137+
11361138
while (true) {
11371139
struct rb_node *n = rb_first(&ci->i_cap_flush_tree);
11381140
if (!n)
@@ -1181,7 +1183,9 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap,
11811183
list_del(&cf->list);
11821184
ceph_free_cap_flush(cf);
11831185
}
1184-
while (drop--)
1186+
1187+
wake_up_all(&ci->i_cap_wq);
1188+
if (drop)
11851189
iput(inode);
11861190
return 0;
11871191
}

‎fs/ceph/super.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,
470470
#define CEPH_I_POOL_RD (1 << 5) /* can read from pool */
471471
#define CEPH_I_POOL_WR (1 << 6) /* can write to pool */
472472
#define CEPH_I_SEC_INITED (1 << 7) /* security initialized */
473+
#define CEPH_I_CAP_DROPPED (1 << 8) /* caps were forcibly dropped */
473474

474475
static inline void __ceph_dir_set_complete(struct ceph_inode_info *ci,
475476
long long release_count,
@@ -932,6 +933,7 @@ extern void ceph_pool_perm_destroy(struct ceph_mds_client* mdsc);
932933
/* file.c */
933934
extern const struct file_operations ceph_file_fops;
934935

936+
extern int ceph_renew_caps(struct inode *inode);
935937
extern int ceph_open(struct inode *inode, struct file *file);
936938
extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
937939
struct file *file, unsigned flags, umode_t mode,

0 commit comments

Comments
 (0)