Skip to content

Commit d468e72

Browse files
ukernelidryomov
authored andcommitted
ceph: add helper function that forcibly reconnects to ceph cluster.
It closes mds sessions, drop all caps and invalidates page caches, then use new entity address to reconnect to the cluster. After reconnect, all dirty data/metadata are dropped, file locks get lost sliently. Open files continue to work because client will try renewing caps on later read/write. Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 5e3ded1 commit d468e72

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎fs/ceph/mds_client.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,9 +1394,12 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap,
13941394
struct ceph_cap_flush *cf;
13951395
struct ceph_mds_client *mdsc = fsc->mdsc;
13961396

1397-
if (ci->i_wrbuffer_ref > 0 &&
1398-
READ_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN)
1399-
invalidate = true;
1397+
if (READ_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) {
1398+
if (inode->i_data.nrpages > 0)
1399+
invalidate = true;
1400+
if (ci->i_wrbuffer_ref > 0)
1401+
mapping_set_error(&inode->i_data, -EIO);
1402+
}
14001403

14011404
while (!list_empty(&ci->i_cap_flush_list)) {
14021405
cf = list_first_entry(&ci->i_cap_flush_list,
@@ -4369,7 +4372,12 @@ void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc)
43694372
session = __ceph_lookup_mds_session(mdsc, mds);
43704373
if (!session)
43714374
continue;
4375+
4376+
if (session->s_state == CEPH_MDS_SESSION_REJECTED)
4377+
__unregister_session(mdsc, session);
4378+
__wake_requests(mdsc, &session->s_waiting);
43724379
mutex_unlock(&mdsc->mutex);
4380+
43734381
mutex_lock(&session->s_mutex);
43744382
__close_session(mdsc, session);
43754383
if (session->s_state == CEPH_MDS_SESSION_CLOSING) {
@@ -4378,6 +4386,7 @@ void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc)
43784386
}
43794387
mutex_unlock(&session->s_mutex);
43804388
ceph_put_mds_session(session);
4389+
43814390
mutex_lock(&mdsc->mutex);
43824391
kick_requests(mdsc, mds);
43834392
}

‎fs/ceph/super.c‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ static void ceph_umount_begin(struct super_block *sb)
829829
fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
830830
ceph_osdc_abort_requests(&fsc->client->osdc, -EIO);
831831
ceph_mdsc_force_umount(fsc->mdsc);
832-
return;
833832
}
834833

835834
static int ceph_remount(struct super_block *sb, int *flags, char *data)
@@ -1152,6 +1151,31 @@ static struct file_system_type ceph_fs_type = {
11521151
};
11531152
MODULE_ALIAS_FS("ceph");
11541153

1154+
int ceph_force_reconnect(struct super_block *sb)
1155+
{
1156+
struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
1157+
int err = 0;
1158+
1159+
ceph_umount_begin(sb);
1160+
1161+
/* Make sure all page caches get invalidated.
1162+
* see remove_session_caps_cb() */
1163+
flush_workqueue(fsc->inode_wq);
1164+
1165+
/* In case that we were blacklisted. This also reset
1166+
* all mon/osd connections */
1167+
ceph_reset_client_addr(fsc->client);
1168+
1169+
ceph_osdc_clear_abort_err(&fsc->client->osdc);
1170+
fsc->mount_state = CEPH_MOUNT_MOUNTED;
1171+
1172+
if (sb->s_root) {
1173+
err = __ceph_do_getattr(d_inode(sb->s_root), NULL,
1174+
CEPH_STAT_CAP_INODE, true);
1175+
}
1176+
return err;
1177+
}
1178+
11551179
static int __init init_ceph(void)
11561180
{
11571181
int ret = init_caches();

‎fs/ceph/super.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,8 @@ static inline int default_congestion_kb(void)
846846
}
847847

848848

849-
849+
/* super.c */
850+
extern int ceph_force_reconnect(struct super_block *sb);
850851
/* snap.c */
851852
struct ceph_snap_realm *ceph_lookup_snap_realm(struct ceph_mds_client *mdsc,
852853
u64 ino);

0 commit comments

Comments
 (0)