Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 2 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3 | |
Sage Weil | 496e595 | 2010-09-22 19:57:10 -0700 | [diff] [blame] | 4 | #include <linux/fs.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 5 | #include <linux/wait.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 6 | #include <linux/slab.h> |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 7 | #include <linux/gfp.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 8 | #include <linux/sched.h> |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 9 | #include <linux/debugfs.h> |
| 10 | #include <linux/seq_file.h> |
Yan, Zheng | 3e0708b | 2015-05-22 16:38:02 +0800 | [diff] [blame] | 11 | #include <linux/ratelimit.h> |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 12 | #include <linux/bits.h> |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 13 | #include <linux/ktime.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 14 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 15 | #include "super.h" |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 16 | #include "mds_client.h" |
| 17 | |
Sage Weil | 1fe60e5 | 2012-07-30 16:23:22 -0700 | [diff] [blame] | 18 | #include <linux/ceph/ceph_features.h> |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 19 | #include <linux/ceph/messenger.h> |
| 20 | #include <linux/ceph/decode.h> |
| 21 | #include <linux/ceph/pagelist.h> |
| 22 | #include <linux/ceph/auth.h> |
| 23 | #include <linux/ceph/debugfs.h> |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 24 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 25 | #define RECONNECT_MAX_SIZE (INT_MAX - PAGE_SIZE) |
| 26 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 27 | /* |
| 28 | * A cluster of MDS (metadata server) daemons is responsible for |
| 29 | * managing the file system namespace (the directory hierarchy and |
| 30 | * inodes) and for coordinating shared access to storage. Metadata is |
| 31 | * partitioning hierarchically across a number of servers, and that |
| 32 | * partition varies over time as the cluster adjusts the distribution |
| 33 | * in order to balance load. |
| 34 | * |
| 35 | * The MDS client is primarily responsible to managing synchronous |
| 36 | * metadata requests for operations like open, unlink, and so forth. |
| 37 | * If there is a MDS failure, we find out about it when we (possibly |
| 38 | * request and) receive a new MDS map, and can resubmit affected |
| 39 | * requests. |
| 40 | * |
| 41 | * For the most part, though, we take advantage of a lossless |
| 42 | * communications channel to the MDS, and do not need to worry about |
| 43 | * timing out or resubmitting requests. |
| 44 | * |
| 45 | * We maintain a stateful "session" with each MDS we interact with. |
| 46 | * Within each session, we sent periodic heartbeat messages to ensure |
| 47 | * any capabilities or leases we have been issues remain valid. If |
| 48 | * the session times out and goes stale, our leases and capabilities |
| 49 | * are no longer valid. |
| 50 | */ |
| 51 | |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 52 | struct ceph_reconnect_state { |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 53 | struct ceph_mds_session *session; |
| 54 | int nr_caps, nr_realms; |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 55 | struct ceph_pagelist *pagelist; |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 56 | unsigned msg_version; |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 57 | bool allow_multi; |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 60 | static void __wake_requests(struct ceph_mds_client *mdsc, |
| 61 | struct list_head *head); |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 62 | static void ceph_cap_release_work(struct work_struct *work); |
Yan, Zheng | 37c4efc | 2019-01-31 16:55:51 +0800 | [diff] [blame] | 63 | static void ceph_cap_reclaim_work(struct work_struct *work); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 64 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 65 | static const struct ceph_connection_operations mds_con_ops; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 66 | |
| 67 | |
| 68 | /* |
| 69 | * mds reply parsing |
| 70 | */ |
| 71 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 72 | static int parse_reply_info_quota(void **p, void *end, |
| 73 | struct ceph_mds_reply_info_in *info) |
| 74 | { |
| 75 | u8 struct_v, struct_compat; |
| 76 | u32 struct_len; |
| 77 | |
| 78 | ceph_decode_8_safe(p, end, struct_v, bad); |
| 79 | ceph_decode_8_safe(p, end, struct_compat, bad); |
| 80 | /* struct_v is expected to be >= 1. we only |
| 81 | * understand encoding with struct_compat == 1. */ |
| 82 | if (!struct_v || struct_compat != 1) |
| 83 | goto bad; |
| 84 | ceph_decode_32_safe(p, end, struct_len, bad); |
| 85 | ceph_decode_need(p, end, struct_len, bad); |
| 86 | end = *p + struct_len; |
| 87 | ceph_decode_64_safe(p, end, info->max_bytes, bad); |
| 88 | ceph_decode_64_safe(p, end, info->max_files, bad); |
| 89 | *p = end; |
| 90 | return 0; |
| 91 | bad: |
| 92 | return -EIO; |
| 93 | } |
| 94 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 95 | /* |
| 96 | * parse individual inode info |
| 97 | */ |
| 98 | static int parse_reply_info_in(void **p, void *end, |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 99 | struct ceph_mds_reply_info_in *info, |
Ilya Dryomov | 12b4629 | 2013-12-24 21:19:23 +0200 | [diff] [blame] | 100 | u64 features) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 101 | { |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 102 | int err = 0; |
| 103 | u8 struct_v = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 104 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 105 | if (features == (u64)-1) { |
| 106 | u32 struct_len; |
| 107 | u8 struct_compat; |
| 108 | ceph_decode_8_safe(p, end, struct_v, bad); |
| 109 | ceph_decode_8_safe(p, end, struct_compat, bad); |
| 110 | /* struct_v is expected to be >= 1. we only understand |
| 111 | * encoding with struct_compat == 1. */ |
| 112 | if (!struct_v || struct_compat != 1) |
| 113 | goto bad; |
| 114 | ceph_decode_32_safe(p, end, struct_len, bad); |
| 115 | ceph_decode_need(p, end, struct_len, bad); |
| 116 | end = *p + struct_len; |
| 117 | } |
| 118 | |
| 119 | ceph_decode_need(p, end, sizeof(struct ceph_mds_reply_inode), bad); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 120 | info->in = *p; |
| 121 | *p += sizeof(struct ceph_mds_reply_inode) + |
| 122 | sizeof(*info->in->fragtree.splits) * |
| 123 | le32_to_cpu(info->in->fragtree.nsplits); |
| 124 | |
| 125 | ceph_decode_32_safe(p, end, info->symlink_len, bad); |
| 126 | ceph_decode_need(p, end, info->symlink_len, bad); |
| 127 | info->symlink = *p; |
| 128 | *p += info->symlink_len; |
| 129 | |
Ilya Dryomov | 23c625c | 2018-11-08 14:55:21 +0100 | [diff] [blame] | 130 | ceph_decode_copy_safe(p, end, &info->dir_layout, |
| 131 | sizeof(info->dir_layout), bad); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 132 | ceph_decode_32_safe(p, end, info->xattr_len, bad); |
| 133 | ceph_decode_need(p, end, info->xattr_len, bad); |
| 134 | info->xattr_data = *p; |
| 135 | *p += info->xattr_len; |
Yan, Zheng | fb01d1f | 2014-11-14 21:29:55 +0800 | [diff] [blame] | 136 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 137 | if (features == (u64)-1) { |
| 138 | /* inline data */ |
Yan, Zheng | fb01d1f | 2014-11-14 21:29:55 +0800 | [diff] [blame] | 139 | ceph_decode_64_safe(p, end, info->inline_version, bad); |
| 140 | ceph_decode_32_safe(p, end, info->inline_len, bad); |
| 141 | ceph_decode_need(p, end, info->inline_len, bad); |
| 142 | info->inline_data = *p; |
| 143 | *p += info->inline_len; |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 144 | /* quota */ |
| 145 | err = parse_reply_info_quota(p, end, info); |
| 146 | if (err < 0) |
| 147 | goto out_bad; |
| 148 | /* pool namespace */ |
Yan, Zheng | 5ea5c5e | 2016-02-14 18:06:41 +0800 | [diff] [blame] | 149 | ceph_decode_32_safe(p, end, info->pool_ns_len, bad); |
Yan, Zheng | 779fe0f | 2016-03-07 09:35:06 +0800 | [diff] [blame] | 150 | if (info->pool_ns_len > 0) { |
| 151 | ceph_decode_need(p, end, info->pool_ns_len, bad); |
| 152 | info->pool_ns_data = *p; |
| 153 | *p += info->pool_ns_len; |
| 154 | } |
Jeff Layton | 245ce99 | 2019-05-29 11:19:42 -0400 | [diff] [blame] | 155 | |
| 156 | /* btime */ |
| 157 | ceph_decode_need(p, end, sizeof(info->btime), bad); |
| 158 | ceph_decode_copy(p, &info->btime, sizeof(info->btime)); |
| 159 | |
| 160 | /* change attribute */ |
Jeff Layton | a35ead3 | 2019-06-06 07:29:23 -0400 | [diff] [blame] | 161 | ceph_decode_64_safe(p, end, info->change_attr, bad); |
Yan, Zheng | 5ea5c5e | 2016-02-14 18:06:41 +0800 | [diff] [blame] | 162 | |
Yan, Zheng | 0879687 | 2019-01-09 11:07:02 +0800 | [diff] [blame] | 163 | /* dir pin */ |
| 164 | if (struct_v >= 2) { |
| 165 | ceph_decode_32_safe(p, end, info->dir_pin, bad); |
| 166 | } else { |
| 167 | info->dir_pin = -ENODATA; |
| 168 | } |
| 169 | |
David Disseldorp | 193e7b3 | 2019-04-18 14:15:46 +0200 | [diff] [blame] | 170 | /* snapshot birth time, remains zero for v<=2 */ |
| 171 | if (struct_v >= 3) { |
| 172 | ceph_decode_need(p, end, sizeof(info->snap_btime), bad); |
| 173 | ceph_decode_copy(p, &info->snap_btime, |
| 174 | sizeof(info->snap_btime)); |
| 175 | } else { |
| 176 | memset(&info->snap_btime, 0, sizeof(info->snap_btime)); |
| 177 | } |
| 178 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 179 | *p = end; |
| 180 | } else { |
| 181 | if (features & CEPH_FEATURE_MDS_INLINE_DATA) { |
| 182 | ceph_decode_64_safe(p, end, info->inline_version, bad); |
| 183 | ceph_decode_32_safe(p, end, info->inline_len, bad); |
| 184 | ceph_decode_need(p, end, info->inline_len, bad); |
| 185 | info->inline_data = *p; |
| 186 | *p += info->inline_len; |
| 187 | } else |
| 188 | info->inline_version = CEPH_INLINE_NONE; |
| 189 | |
| 190 | if (features & CEPH_FEATURE_MDS_QUOTA) { |
| 191 | err = parse_reply_info_quota(p, end, info); |
| 192 | if (err < 0) |
| 193 | goto out_bad; |
| 194 | } else { |
| 195 | info->max_bytes = 0; |
| 196 | info->max_files = 0; |
| 197 | } |
| 198 | |
| 199 | info->pool_ns_len = 0; |
| 200 | info->pool_ns_data = NULL; |
| 201 | if (features & CEPH_FEATURE_FS_FILE_LAYOUT_V2) { |
| 202 | ceph_decode_32_safe(p, end, info->pool_ns_len, bad); |
| 203 | if (info->pool_ns_len > 0) { |
| 204 | ceph_decode_need(p, end, info->pool_ns_len, bad); |
| 205 | info->pool_ns_data = *p; |
| 206 | *p += info->pool_ns_len; |
| 207 | } |
| 208 | } |
Yan, Zheng | 0879687 | 2019-01-09 11:07:02 +0800 | [diff] [blame] | 209 | |
Jeff Layton | 245ce99 | 2019-05-29 11:19:42 -0400 | [diff] [blame] | 210 | if (features & CEPH_FEATURE_FS_BTIME) { |
| 211 | ceph_decode_need(p, end, sizeof(info->btime), bad); |
| 212 | ceph_decode_copy(p, &info->btime, sizeof(info->btime)); |
Jeff Layton | a35ead3 | 2019-06-06 07:29:23 -0400 | [diff] [blame] | 213 | ceph_decode_64_safe(p, end, info->change_attr, bad); |
Jeff Layton | 245ce99 | 2019-05-29 11:19:42 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Yan, Zheng | 0879687 | 2019-01-09 11:07:02 +0800 | [diff] [blame] | 216 | info->dir_pin = -ENODATA; |
David Disseldorp | 193e7b3 | 2019-04-18 14:15:46 +0200 | [diff] [blame] | 217 | /* info->snap_btime remains zero */ |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 218 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 219 | return 0; |
| 220 | bad: |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 221 | err = -EIO; |
| 222 | out_bad: |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 223 | return err; |
| 224 | } |
| 225 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 226 | static int parse_reply_info_dir(void **p, void *end, |
| 227 | struct ceph_mds_reply_dirfrag **dirfrag, |
| 228 | u64 features) |
| 229 | { |
| 230 | if (features == (u64)-1) { |
| 231 | u8 struct_v, struct_compat; |
| 232 | u32 struct_len; |
| 233 | ceph_decode_8_safe(p, end, struct_v, bad); |
| 234 | ceph_decode_8_safe(p, end, struct_compat, bad); |
| 235 | /* struct_v is expected to be >= 1. we only understand |
| 236 | * encoding whose struct_compat == 1. */ |
| 237 | if (!struct_v || struct_compat != 1) |
| 238 | goto bad; |
| 239 | ceph_decode_32_safe(p, end, struct_len, bad); |
| 240 | ceph_decode_need(p, end, struct_len, bad); |
| 241 | end = *p + struct_len; |
| 242 | } |
| 243 | |
| 244 | ceph_decode_need(p, end, sizeof(**dirfrag), bad); |
| 245 | *dirfrag = *p; |
| 246 | *p += sizeof(**dirfrag) + sizeof(u32) * le32_to_cpu((*dirfrag)->ndist); |
| 247 | if (unlikely(*p > end)) |
| 248 | goto bad; |
| 249 | if (features == (u64)-1) |
| 250 | *p = end; |
| 251 | return 0; |
| 252 | bad: |
| 253 | return -EIO; |
| 254 | } |
| 255 | |
| 256 | static int parse_reply_info_lease(void **p, void *end, |
| 257 | struct ceph_mds_reply_lease **lease, |
| 258 | u64 features) |
| 259 | { |
| 260 | if (features == (u64)-1) { |
| 261 | u8 struct_v, struct_compat; |
| 262 | u32 struct_len; |
| 263 | ceph_decode_8_safe(p, end, struct_v, bad); |
| 264 | ceph_decode_8_safe(p, end, struct_compat, bad); |
| 265 | /* struct_v is expected to be >= 1. we only understand |
| 266 | * encoding whose struct_compat == 1. */ |
| 267 | if (!struct_v || struct_compat != 1) |
| 268 | goto bad; |
| 269 | ceph_decode_32_safe(p, end, struct_len, bad); |
| 270 | ceph_decode_need(p, end, struct_len, bad); |
| 271 | end = *p + struct_len; |
| 272 | } |
| 273 | |
| 274 | ceph_decode_need(p, end, sizeof(**lease), bad); |
| 275 | *lease = *p; |
| 276 | *p += sizeof(**lease); |
| 277 | if (features == (u64)-1) |
| 278 | *p = end; |
| 279 | return 0; |
| 280 | bad: |
| 281 | return -EIO; |
| 282 | } |
| 283 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 284 | /* |
| 285 | * parse a normal reply, which may contain a (dir+)dentry and/or a |
| 286 | * target inode. |
| 287 | */ |
| 288 | static int parse_reply_info_trace(void **p, void *end, |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 289 | struct ceph_mds_reply_info_parsed *info, |
Ilya Dryomov | 12b4629 | 2013-12-24 21:19:23 +0200 | [diff] [blame] | 290 | u64 features) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 291 | { |
| 292 | int err; |
| 293 | |
| 294 | if (info->head->is_dentry) { |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 295 | err = parse_reply_info_in(p, end, &info->diri, features); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 296 | if (err < 0) |
| 297 | goto out_bad; |
| 298 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 299 | err = parse_reply_info_dir(p, end, &info->dirfrag, features); |
| 300 | if (err < 0) |
| 301 | goto out_bad; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 302 | |
| 303 | ceph_decode_32_safe(p, end, info->dname_len, bad); |
| 304 | ceph_decode_need(p, end, info->dname_len, bad); |
| 305 | info->dname = *p; |
| 306 | *p += info->dname_len; |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 307 | |
| 308 | err = parse_reply_info_lease(p, end, &info->dlease, features); |
| 309 | if (err < 0) |
| 310 | goto out_bad; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | if (info->head->is_target) { |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 314 | err = parse_reply_info_in(p, end, &info->targeti, features); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 315 | if (err < 0) |
| 316 | goto out_bad; |
| 317 | } |
| 318 | |
| 319 | if (unlikely(*p != end)) |
| 320 | goto bad; |
| 321 | return 0; |
| 322 | |
| 323 | bad: |
| 324 | err = -EIO; |
| 325 | out_bad: |
| 326 | pr_err("problem parsing mds trace %d\n", err); |
| 327 | return err; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * parse readdir results |
| 332 | */ |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 333 | static int parse_reply_info_readdir(void **p, void *end, |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 334 | struct ceph_mds_reply_info_parsed *info, |
Ilya Dryomov | 12b4629 | 2013-12-24 21:19:23 +0200 | [diff] [blame] | 335 | u64 features) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 336 | { |
| 337 | u32 num, i = 0; |
| 338 | int err; |
| 339 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 340 | err = parse_reply_info_dir(p, end, &info->dir_dir, features); |
| 341 | if (err < 0) |
| 342 | goto out_bad; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 343 | |
| 344 | ceph_decode_need(p, end, sizeof(num) + 2, bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 345 | num = ceph_decode_32(p); |
Yan, Zheng | 956d39d | 2016-04-27 17:48:30 +0800 | [diff] [blame] | 346 | { |
| 347 | u16 flags = ceph_decode_16(p); |
| 348 | info->dir_end = !!(flags & CEPH_READDIR_FRAG_END); |
| 349 | info->dir_complete = !!(flags & CEPH_READDIR_FRAG_COMPLETE); |
Yan, Zheng | f3c4ebe | 2016-04-29 11:27:30 +0800 | [diff] [blame] | 350 | info->hash_order = !!(flags & CEPH_READDIR_HASH_ORDER); |
Yan, Zheng | 7916254 | 2017-04-05 12:54:05 -0400 | [diff] [blame] | 351 | info->offset_hash = !!(flags & CEPH_READDIR_OFFSET_HASH); |
Yan, Zheng | 956d39d | 2016-04-27 17:48:30 +0800 | [diff] [blame] | 352 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 353 | if (num == 0) |
| 354 | goto done; |
| 355 | |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 356 | BUG_ON(!info->dir_entries); |
| 357 | if ((unsigned long)(info->dir_entries + num) > |
| 358 | (unsigned long)info->dir_entries + info->dir_buf_size) { |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 359 | pr_err("dir contents are larger than expected\n"); |
| 360 | WARN_ON(1); |
| 361 | goto bad; |
| 362 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 363 | |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 364 | info->dir_nr = num; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 365 | while (num) { |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 366 | struct ceph_mds_reply_dir_entry *rde = info->dir_entries + i; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 367 | /* dentry */ |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 368 | ceph_decode_32_safe(p, end, rde->name_len, bad); |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 369 | ceph_decode_need(p, end, rde->name_len, bad); |
| 370 | rde->name = *p; |
| 371 | *p += rde->name_len; |
| 372 | dout("parsed dir dname '%.*s'\n", rde->name_len, rde->name); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 373 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 374 | /* dentry lease */ |
| 375 | err = parse_reply_info_lease(p, end, &rde->lease, features); |
| 376 | if (err) |
| 377 | goto out_bad; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 378 | /* inode */ |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 379 | err = parse_reply_info_in(p, end, &rde->inode, features); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 380 | if (err < 0) |
| 381 | goto out_bad; |
Yan, Zheng | 8974eeb | 2016-04-28 15:17:40 +0800 | [diff] [blame] | 382 | /* ceph_readdir_prepopulate() will update it */ |
| 383 | rde->offset = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 384 | i++; |
| 385 | num--; |
| 386 | } |
| 387 | |
| 388 | done: |
Jeff Layton | 1d3f872 | 2019-09-26 16:05:11 -0400 | [diff] [blame] | 389 | /* Skip over any unrecognized fields */ |
| 390 | *p = end; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 391 | return 0; |
| 392 | |
| 393 | bad: |
| 394 | err = -EIO; |
| 395 | out_bad: |
| 396 | pr_err("problem parsing dir contents %d\n", err); |
| 397 | return err; |
| 398 | } |
| 399 | |
| 400 | /* |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 401 | * parse fcntl F_GETLK results |
| 402 | */ |
| 403 | static int parse_reply_info_filelock(void **p, void *end, |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 404 | struct ceph_mds_reply_info_parsed *info, |
Ilya Dryomov | 12b4629 | 2013-12-24 21:19:23 +0200 | [diff] [blame] | 405 | u64 features) |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 406 | { |
| 407 | if (*p + sizeof(*info->filelock_reply) > end) |
| 408 | goto bad; |
| 409 | |
| 410 | info->filelock_reply = *p; |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 411 | |
Jeff Layton | 1d3f872 | 2019-09-26 16:05:11 -0400 | [diff] [blame] | 412 | /* Skip over any unrecognized fields */ |
| 413 | *p = end; |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 414 | return 0; |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 415 | bad: |
| 416 | return -EIO; |
| 417 | } |
| 418 | |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 419 | |
| 420 | #if BITS_PER_LONG == 64 |
| 421 | |
| 422 | #define DELEGATED_INO_AVAILABLE xa_mk_value(1) |
| 423 | |
| 424 | static int ceph_parse_deleg_inos(void **p, void *end, |
| 425 | struct ceph_mds_session *s) |
| 426 | { |
| 427 | u32 sets; |
| 428 | |
| 429 | ceph_decode_32_safe(p, end, sets, bad); |
| 430 | dout("got %u sets of delegated inodes\n", sets); |
| 431 | while (sets--) { |
| 432 | u64 start, len, ino; |
| 433 | |
| 434 | ceph_decode_64_safe(p, end, start, bad); |
| 435 | ceph_decode_64_safe(p, end, len, bad); |
| 436 | while (len--) { |
| 437 | int err = xa_insert(&s->s_delegated_inos, ino = start++, |
| 438 | DELEGATED_INO_AVAILABLE, |
| 439 | GFP_KERNEL); |
| 440 | if (!err) { |
| 441 | dout("added delegated inode 0x%llx\n", |
| 442 | start - 1); |
| 443 | } else if (err == -EBUSY) { |
| 444 | pr_warn("ceph: MDS delegated inode 0x%llx more than once.\n", |
| 445 | start - 1); |
| 446 | } else { |
| 447 | return err; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | return 0; |
| 452 | bad: |
| 453 | return -EIO; |
| 454 | } |
| 455 | |
| 456 | u64 ceph_get_deleg_ino(struct ceph_mds_session *s) |
| 457 | { |
| 458 | unsigned long ino; |
| 459 | void *val; |
| 460 | |
| 461 | xa_for_each(&s->s_delegated_inos, ino, val) { |
| 462 | val = xa_erase(&s->s_delegated_inos, ino); |
| 463 | if (val == DELEGATED_INO_AVAILABLE) |
| 464 | return ino; |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | int ceph_restore_deleg_ino(struct ceph_mds_session *s, u64 ino) |
| 470 | { |
| 471 | return xa_insert(&s->s_delegated_inos, ino, DELEGATED_INO_AVAILABLE, |
| 472 | GFP_KERNEL); |
| 473 | } |
| 474 | #else /* BITS_PER_LONG == 64 */ |
| 475 | /* |
| 476 | * FIXME: xarrays can't handle 64-bit indexes on a 32-bit arch. For now, just |
| 477 | * ignore delegated_inos on 32 bit arch. Maybe eventually add xarrays for top |
| 478 | * and bottom words? |
| 479 | */ |
| 480 | static int ceph_parse_deleg_inos(void **p, void *end, |
| 481 | struct ceph_mds_session *s) |
| 482 | { |
| 483 | u32 sets; |
| 484 | |
| 485 | ceph_decode_32_safe(p, end, sets, bad); |
| 486 | if (sets) |
| 487 | ceph_decode_skip_n(p, end, sets * 2 * sizeof(__le64), bad); |
| 488 | return 0; |
| 489 | bad: |
| 490 | return -EIO; |
| 491 | } |
| 492 | |
| 493 | u64 ceph_get_deleg_ino(struct ceph_mds_session *s) |
| 494 | { |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | int ceph_restore_deleg_ino(struct ceph_mds_session *s, u64 ino) |
| 499 | { |
| 500 | return 0; |
| 501 | } |
| 502 | #endif /* BITS_PER_LONG == 64 */ |
| 503 | |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 504 | /* |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 505 | * parse create results |
| 506 | */ |
| 507 | static int parse_reply_info_create(void **p, void *end, |
| 508 | struct ceph_mds_reply_info_parsed *info, |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 509 | u64 features, struct ceph_mds_session *s) |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 510 | { |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 511 | int ret; |
| 512 | |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 513 | if (features == (u64)-1 || |
| 514 | (features & CEPH_FEATURE_REPLY_CREATE_INODE)) { |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 515 | if (*p == end) { |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 516 | /* Malformed reply? */ |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 517 | info->has_create_ino = false; |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 518 | } else if (test_bit(CEPHFS_FEATURE_DELEG_INO, &s->s_features)) { |
| 519 | u8 struct_v, struct_compat; |
| 520 | u32 len; |
| 521 | |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 522 | info->has_create_ino = true; |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 523 | ceph_decode_8_safe(p, end, struct_v, bad); |
| 524 | ceph_decode_8_safe(p, end, struct_compat, bad); |
| 525 | ceph_decode_32_safe(p, end, len, bad); |
Jeff Layton | 1d3f872 | 2019-09-26 16:05:11 -0400 | [diff] [blame] | 526 | ceph_decode_64_safe(p, end, info->ino, bad); |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 527 | ret = ceph_parse_deleg_inos(p, end, s); |
| 528 | if (ret) |
| 529 | return ret; |
| 530 | } else { |
| 531 | /* legacy */ |
| 532 | ceph_decode_64_safe(p, end, info->ino, bad); |
| 533 | info->has_create_ino = true; |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 534 | } |
Jeff Layton | 1d3f872 | 2019-09-26 16:05:11 -0400 | [diff] [blame] | 535 | } else { |
| 536 | if (*p != end) |
| 537 | goto bad; |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Jeff Layton | 1d3f872 | 2019-09-26 16:05:11 -0400 | [diff] [blame] | 540 | /* Skip over any unrecognized fields */ |
| 541 | *p = end; |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 542 | return 0; |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 543 | bad: |
| 544 | return -EIO; |
| 545 | } |
| 546 | |
| 547 | /* |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 548 | * parse extra results |
| 549 | */ |
| 550 | static int parse_reply_info_extra(void **p, void *end, |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 551 | struct ceph_mds_reply_info_parsed *info, |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 552 | u64 features, struct ceph_mds_session *s) |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 553 | { |
Jeff Layton | 6df8c9d | 2017-01-12 14:42:41 -0500 | [diff] [blame] | 554 | u32 op = le32_to_cpu(info->head->op); |
| 555 | |
| 556 | if (op == CEPH_MDS_OP_GETFILELOCK) |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 557 | return parse_reply_info_filelock(p, end, info, features); |
Jeff Layton | 6df8c9d | 2017-01-12 14:42:41 -0500 | [diff] [blame] | 558 | else if (op == CEPH_MDS_OP_READDIR || op == CEPH_MDS_OP_LSSNAP) |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 559 | return parse_reply_info_readdir(p, end, info, features); |
Jeff Layton | 6df8c9d | 2017-01-12 14:42:41 -0500 | [diff] [blame] | 560 | else if (op == CEPH_MDS_OP_CREATE) |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 561 | return parse_reply_info_create(p, end, info, features, s); |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 562 | else |
| 563 | return -EIO; |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 567 | * parse entire mds reply |
| 568 | */ |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 569 | static int parse_reply_info(struct ceph_mds_session *s, struct ceph_msg *msg, |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 570 | struct ceph_mds_reply_info_parsed *info, |
Ilya Dryomov | 12b4629 | 2013-12-24 21:19:23 +0200 | [diff] [blame] | 571 | u64 features) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 572 | { |
| 573 | void *p, *end; |
| 574 | u32 len; |
| 575 | int err; |
| 576 | |
| 577 | info->head = msg->front.iov_base; |
| 578 | p = msg->front.iov_base + sizeof(struct ceph_mds_reply_head); |
| 579 | end = p + msg->front.iov_len - sizeof(struct ceph_mds_reply_head); |
| 580 | |
| 581 | /* trace */ |
| 582 | ceph_decode_32_safe(&p, end, len, bad); |
| 583 | if (len > 0) { |
Xi Wang | 32852a8 | 2012-01-14 22:20:59 -0500 | [diff] [blame] | 584 | ceph_decode_need(&p, end, len, bad); |
Sage Weil | 14303d2 | 2010-12-14 17:37:52 -0800 | [diff] [blame] | 585 | err = parse_reply_info_trace(&p, p+len, info, features); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 586 | if (err < 0) |
| 587 | goto out_bad; |
| 588 | } |
| 589 | |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 590 | /* extra */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 591 | ceph_decode_32_safe(&p, end, len, bad); |
| 592 | if (len > 0) { |
Xi Wang | 32852a8 | 2012-01-14 22:20:59 -0500 | [diff] [blame] | 593 | ceph_decode_need(&p, end, len, bad); |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 594 | err = parse_reply_info_extra(&p, p+len, info, features, s); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 595 | if (err < 0) |
| 596 | goto out_bad; |
| 597 | } |
| 598 | |
| 599 | /* snap blob */ |
| 600 | ceph_decode_32_safe(&p, end, len, bad); |
| 601 | info->snapblob_len = len; |
| 602 | info->snapblob = p; |
| 603 | p += len; |
| 604 | |
| 605 | if (p != end) |
| 606 | goto bad; |
| 607 | return 0; |
| 608 | |
| 609 | bad: |
| 610 | err = -EIO; |
| 611 | out_bad: |
| 612 | pr_err("mds parse_reply err %d\n", err); |
| 613 | return err; |
| 614 | } |
| 615 | |
| 616 | static void destroy_reply_info(struct ceph_mds_reply_info_parsed *info) |
| 617 | { |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 618 | if (!info->dir_entries) |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 619 | return; |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 620 | free_pages((unsigned long)info->dir_entries, get_order(info->dir_buf_size)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
| 624 | /* |
| 625 | * sessions |
| 626 | */ |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 627 | const char *ceph_session_state_name(int s) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 628 | { |
| 629 | switch (s) { |
| 630 | case CEPH_MDS_SESSION_NEW: return "new"; |
| 631 | case CEPH_MDS_SESSION_OPENING: return "opening"; |
| 632 | case CEPH_MDS_SESSION_OPEN: return "open"; |
| 633 | case CEPH_MDS_SESSION_HUNG: return "hung"; |
| 634 | case CEPH_MDS_SESSION_CLOSING: return "closing"; |
Xiubo Li | 4d681c2 | 2019-12-05 22:35:51 -0500 | [diff] [blame] | 635 | case CEPH_MDS_SESSION_CLOSED: return "closed"; |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 636 | case CEPH_MDS_SESSION_RESTARTING: return "restarting"; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 637 | case CEPH_MDS_SESSION_RECONNECTING: return "reconnecting"; |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 638 | case CEPH_MDS_SESSION_REJECTED: return "rejected"; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 639 | default: return "???"; |
| 640 | } |
| 641 | } |
| 642 | |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 643 | struct ceph_mds_session *ceph_get_mds_session(struct ceph_mds_session *s) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 644 | { |
Elena Reshetova | 3997c01 | 2017-03-03 11:15:06 +0200 | [diff] [blame] | 645 | if (refcount_inc_not_zero(&s->s_ref)) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 646 | dout("mdsc get_session %p %d -> %d\n", s, |
Elena Reshetova | 3997c01 | 2017-03-03 11:15:06 +0200 | [diff] [blame] | 647 | refcount_read(&s->s_ref)-1, refcount_read(&s->s_ref)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 648 | return s; |
| 649 | } else { |
Chengguang Xu | 4c069a5 | 2018-01-30 16:29:17 +0800 | [diff] [blame] | 650 | dout("mdsc get_session %p 0 -- FAIL\n", s); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 651 | return NULL; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | void ceph_put_mds_session(struct ceph_mds_session *s) |
| 656 | { |
| 657 | dout("mdsc put_session %p %d -> %d\n", s, |
Elena Reshetova | 3997c01 | 2017-03-03 11:15:06 +0200 | [diff] [blame] | 658 | refcount_read(&s->s_ref), refcount_read(&s->s_ref)-1); |
| 659 | if (refcount_dec_and_test(&s->s_ref)) { |
Alex Elder | 6c4a191 | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 660 | if (s->s_auth.authorizer) |
Ilya Dryomov | 6c1ea26 | 2016-04-11 19:34:49 +0200 | [diff] [blame] | 661 | ceph_auth_destroy_authorizer(s->s_auth.authorizer); |
Jeff Layton | 8882819 | 2020-03-20 17:07:36 -0400 | [diff] [blame] | 662 | WARN_ON(mutex_is_locked(&s->s_mutex)); |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 663 | xa_destroy(&s->s_delegated_inos); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 664 | kfree(s); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 665 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /* |
| 669 | * called under mdsc->mutex |
| 670 | */ |
| 671 | struct ceph_mds_session *__ceph_lookup_mds_session(struct ceph_mds_client *mdsc, |
| 672 | int mds) |
| 673 | { |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 674 | if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 675 | return NULL; |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 676 | return ceph_get_mds_session(mdsc->sessions[mds]); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static bool __have_session(struct ceph_mds_client *mdsc, int mds) |
| 680 | { |
Chengguang Xu | 98cfda8 | 2018-03-13 10:43:45 +0800 | [diff] [blame] | 681 | if (mds >= mdsc->max_sessions || !mdsc->sessions[mds]) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 682 | return false; |
Chengguang Xu | 98cfda8 | 2018-03-13 10:43:45 +0800 | [diff] [blame] | 683 | else |
| 684 | return true; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 687 | static int __verify_registered_session(struct ceph_mds_client *mdsc, |
| 688 | struct ceph_mds_session *s) |
| 689 | { |
| 690 | if (s->s_mds >= mdsc->max_sessions || |
| 691 | mdsc->sessions[s->s_mds] != s) |
| 692 | return -ENOENT; |
| 693 | return 0; |
| 694 | } |
| 695 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 696 | /* |
| 697 | * create+register a new session for given mds. |
| 698 | * called under mdsc->mutex. |
| 699 | */ |
| 700 | static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc, |
| 701 | int mds) |
| 702 | { |
| 703 | struct ceph_mds_session *s; |
| 704 | |
Xiubo Li | b38c9eb | 2019-12-04 06:57:39 -0500 | [diff] [blame] | 705 | if (mds >= mdsc->mdsmap->possible_max_rank) |
Nathaniel Yazdani | c338c07 | 2013-08-04 21:04:30 -0700 | [diff] [blame] | 706 | return ERR_PTR(-EINVAL); |
| 707 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 708 | s = kzalloc(sizeof(*s), GFP_NOFS); |
Dan Carpenter | 4736b00 | 2010-03-20 15:30:16 +0300 | [diff] [blame] | 709 | if (!s) |
| 710 | return ERR_PTR(-ENOMEM); |
Chengguang Xu | 47474d0 | 2018-03-13 23:01:07 +0800 | [diff] [blame] | 711 | |
| 712 | if (mds >= mdsc->max_sessions) { |
| 713 | int newmax = 1 << get_count_order(mds + 1); |
| 714 | struct ceph_mds_session **sa; |
| 715 | |
| 716 | dout("%s: realloc to %d\n", __func__, newmax); |
| 717 | sa = kcalloc(newmax, sizeof(void *), GFP_NOFS); |
| 718 | if (!sa) |
| 719 | goto fail_realloc; |
| 720 | if (mdsc->sessions) { |
| 721 | memcpy(sa, mdsc->sessions, |
| 722 | mdsc->max_sessions * sizeof(void *)); |
| 723 | kfree(mdsc->sessions); |
| 724 | } |
| 725 | mdsc->sessions = sa; |
| 726 | mdsc->max_sessions = newmax; |
| 727 | } |
| 728 | |
| 729 | dout("%s: mds%d\n", __func__, mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 730 | s->s_mdsc = mdsc; |
| 731 | s->s_mds = mds; |
| 732 | s->s_state = CEPH_MDS_SESSION_NEW; |
| 733 | s->s_ttl = 0; |
| 734 | s->s_seq = 0; |
| 735 | mutex_init(&s->s_mutex); |
| 736 | |
Sage Weil | b7a9e5d | 2012-06-27 12:24:08 -0700 | [diff] [blame] | 737 | ceph_con_init(&s->s_con, s, &mds_con_ops, &mdsc->fsc->client->msgr); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 738 | |
Alex Elder | d8fb02a | 2012-01-12 17:48:10 -0800 | [diff] [blame] | 739 | spin_lock_init(&s->s_gen_ttl_lock); |
Yan, Zheng | 1e9c2eb | 2019-01-28 20:43:55 +0800 | [diff] [blame] | 740 | s->s_cap_gen = 1; |
Alex Elder | 1ce208a | 2012-01-12 17:48:11 -0800 | [diff] [blame] | 741 | s->s_cap_ttl = jiffies - 1; |
Alex Elder | d8fb02a | 2012-01-12 17:48:10 -0800 | [diff] [blame] | 742 | |
| 743 | spin_lock_init(&s->s_cap_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 744 | s->s_renew_requested = 0; |
| 745 | s->s_renew_seq = 0; |
| 746 | INIT_LIST_HEAD(&s->s_caps); |
| 747 | s->s_nr_caps = 0; |
Elena Reshetova | 3997c01 | 2017-03-03 11:15:06 +0200 | [diff] [blame] | 748 | refcount_set(&s->s_ref, 1); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 749 | INIT_LIST_HEAD(&s->s_waiting); |
| 750 | INIT_LIST_HEAD(&s->s_unsafe); |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 751 | xa_init(&s->s_delegated_inos); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 752 | s->s_num_cap_releases = 0; |
Yan, Zheng | 99a9c27 | 2013-09-22 11:08:14 +0800 | [diff] [blame] | 753 | s->s_cap_reconnect = 0; |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 754 | s->s_cap_iterator = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 755 | INIT_LIST_HEAD(&s->s_cap_releases); |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 756 | INIT_WORK(&s->s_cap_release_work, ceph_cap_release_work); |
| 757 | |
Jeff Layton | 1cf03a6 | 2020-04-01 17:07:52 -0400 | [diff] [blame] | 758 | INIT_LIST_HEAD(&s->s_cap_dirty); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 759 | INIT_LIST_HEAD(&s->s_cap_flushing); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 760 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 761 | mdsc->sessions[mds] = s; |
Yan, Zheng | 86d8f67 | 2015-01-09 17:00:42 +0800 | [diff] [blame] | 762 | atomic_inc(&mdsc->num_sessions); |
Elena Reshetova | 3997c01 | 2017-03-03 11:15:06 +0200 | [diff] [blame] | 763 | refcount_inc(&s->s_ref); /* one ref to sessions[], one to caller */ |
Sage Weil | 42ce56e | 2009-11-18 11:22:36 -0800 | [diff] [blame] | 764 | |
Sage Weil | b7a9e5d | 2012-06-27 12:24:08 -0700 | [diff] [blame] | 765 | ceph_con_open(&s->s_con, CEPH_ENTITY_TYPE_MDS, mds, |
| 766 | ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); |
Sage Weil | 42ce56e | 2009-11-18 11:22:36 -0800 | [diff] [blame] | 767 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 768 | return s; |
Sage Weil | 42ce56e | 2009-11-18 11:22:36 -0800 | [diff] [blame] | 769 | |
| 770 | fail_realloc: |
| 771 | kfree(s); |
| 772 | return ERR_PTR(-ENOMEM); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /* |
| 776 | * called under mdsc->mutex |
| 777 | */ |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 778 | static void __unregister_session(struct ceph_mds_client *mdsc, |
Sage Weil | 42ce56e | 2009-11-18 11:22:36 -0800 | [diff] [blame] | 779 | struct ceph_mds_session *s) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 780 | { |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 781 | dout("__unregister_session mds%d %p\n", s->s_mds, s); |
| 782 | BUG_ON(mdsc->sessions[s->s_mds] != s); |
Sage Weil | 42ce56e | 2009-11-18 11:22:36 -0800 | [diff] [blame] | 783 | mdsc->sessions[s->s_mds] = NULL; |
| 784 | ceph_con_close(&s->s_con); |
| 785 | ceph_put_mds_session(s); |
Yan, Zheng | 86d8f67 | 2015-01-09 17:00:42 +0800 | [diff] [blame] | 786 | atomic_dec(&mdsc->num_sessions); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /* |
| 790 | * drop session refs in request. |
| 791 | * |
| 792 | * should be last request ref, or hold mdsc->mutex |
| 793 | */ |
| 794 | static void put_request_session(struct ceph_mds_request *req) |
| 795 | { |
| 796 | if (req->r_session) { |
| 797 | ceph_put_mds_session(req->r_session); |
| 798 | req->r_session = NULL; |
| 799 | } |
| 800 | } |
| 801 | |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 802 | void ceph_mdsc_release_request(struct kref *kref) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 803 | { |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 804 | struct ceph_mds_request *req = container_of(kref, |
| 805 | struct ceph_mds_request, |
| 806 | r_kref); |
Xiubo Li | e64f44a | 2020-05-27 09:09:27 -0400 | [diff] [blame] | 807 | ceph_mdsc_release_dir_caps_no_check(req); |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 808 | destroy_reply_info(&req->r_reply_info); |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 809 | if (req->r_request) |
| 810 | ceph_msg_put(req->r_request); |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 811 | if (req->r_reply) |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 812 | ceph_msg_put(req->r_reply); |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 813 | if (req->r_inode) { |
Sage Weil | 41b02e1 | 2011-07-26 11:31:14 -0700 | [diff] [blame] | 814 | ceph_put_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN); |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 815 | /* avoid calling iput_final() in mds dispatch threads */ |
| 816 | ceph_async_iput(req->r_inode); |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 817 | } |
Jeff Layton | 9c1c2b3 | 2019-04-03 13:16:01 -0400 | [diff] [blame] | 818 | if (req->r_parent) { |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 819 | ceph_put_cap_refs(ceph_inode(req->r_parent), CEPH_CAP_PIN); |
Jeff Layton | 9c1c2b3 | 2019-04-03 13:16:01 -0400 | [diff] [blame] | 820 | ceph_async_iput(req->r_parent); |
| 821 | } |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 822 | ceph_async_iput(req->r_target_inode); |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 823 | if (req->r_dentry) |
| 824 | dput(req->r_dentry); |
Sage Weil | 844d87c | 2013-02-05 13:40:09 -0800 | [diff] [blame] | 825 | if (req->r_old_dentry) |
| 826 | dput(req->r_old_dentry); |
| 827 | if (req->r_old_dentry_dir) { |
Sage Weil | 41b02e1 | 2011-07-26 11:31:14 -0700 | [diff] [blame] | 828 | /* |
| 829 | * track (and drop pins for) r_old_dentry_dir |
| 830 | * separately, since r_old_dentry's d_parent may have |
| 831 | * changed between the dir mutex being dropped and |
| 832 | * this request being freed. |
| 833 | */ |
| 834 | ceph_put_cap_refs(ceph_inode(req->r_old_dentry_dir), |
| 835 | CEPH_CAP_PIN); |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 836 | ceph_async_iput(req->r_old_dentry_dir); |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 837 | } |
| 838 | kfree(req->r_path1); |
| 839 | kfree(req->r_path2); |
Yan, Zheng | 25e6bae | 2014-09-16 19:15:28 +0800 | [diff] [blame] | 840 | if (req->r_pagelist) |
| 841 | ceph_pagelist_release(req->r_pagelist); |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 842 | put_request_session(req); |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 843 | ceph_unreserve_caps(req->r_mdsc, &req->r_caps_reservation); |
Yan, Zheng | 428138c | 2019-06-14 10:55:05 +0800 | [diff] [blame] | 844 | WARN_ON_ONCE(!list_empty(&req->r_wait)); |
Jeff Layton | 058daab | 2020-02-17 18:38:37 -0500 | [diff] [blame] | 845 | kmem_cache_free(ceph_mds_request_cachep, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 848 | DEFINE_RB_FUNCS(request, struct ceph_mds_request, r_tid, r_node) |
| 849 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 850 | /* |
| 851 | * lookup session, bump ref if found. |
| 852 | * |
| 853 | * called under mdsc->mutex. |
| 854 | */ |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 855 | static struct ceph_mds_request * |
| 856 | lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 857 | { |
| 858 | struct ceph_mds_request *req; |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 859 | |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 860 | req = lookup_request(&mdsc->request_tree, tid); |
| 861 | if (req) |
| 862 | ceph_mdsc_get_request(req); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 863 | |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 864 | return req; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | /* |
| 868 | * Register an in-flight request, and assign a tid. Link to directory |
| 869 | * are modifying (if any). |
| 870 | * |
| 871 | * Called under mdsc->mutex. |
| 872 | */ |
| 873 | static void __register_request(struct ceph_mds_client *mdsc, |
| 874 | struct ceph_mds_request *req, |
| 875 | struct inode *dir) |
| 876 | { |
Zhi Zhang | e30ee58 | 2018-01-24 21:24:33 +0800 | [diff] [blame] | 877 | int ret = 0; |
| 878 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 879 | req->r_tid = ++mdsc->last_tid; |
Zhi Zhang | e30ee58 | 2018-01-24 21:24:33 +0800 | [diff] [blame] | 880 | if (req->r_num_caps) { |
| 881 | ret = ceph_reserve_caps(mdsc, &req->r_caps_reservation, |
| 882 | req->r_num_caps); |
| 883 | if (ret < 0) { |
| 884 | pr_err("__register_request %p " |
| 885 | "failed to reserve caps: %d\n", req, ret); |
| 886 | /* set req->r_err to fail early from __do_request */ |
| 887 | req->r_err = ret; |
| 888 | return; |
| 889 | } |
| 890 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 891 | dout("__register_request %p tid %lld\n", req, req->r_tid); |
| 892 | ceph_mdsc_get_request(req); |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 893 | insert_request(&mdsc->request_tree, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 894 | |
Sage Weil | cb4276c | 2010-11-08 07:28:52 -0800 | [diff] [blame] | 895 | req->r_uid = current_fsuid(); |
| 896 | req->r_gid = current_fsgid(); |
| 897 | |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 898 | if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK) |
| 899 | mdsc->oldest_tid = req->r_tid; |
| 900 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 901 | if (dir) { |
Jeff Layton | 3db0a2f | 2019-04-04 08:05:38 -0400 | [diff] [blame] | 902 | struct ceph_inode_info *ci = ceph_inode(dir); |
| 903 | |
Sage Weil | 3b66378 | 2011-05-18 16:12:12 -0700 | [diff] [blame] | 904 | ihold(dir); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 905 | req->r_unsafe_dir = dir; |
Jeff Layton | 3db0a2f | 2019-04-04 08:05:38 -0400 | [diff] [blame] | 906 | spin_lock(&ci->i_unsafe_lock); |
| 907 | list_add_tail(&req->r_unsafe_dir_item, &ci->i_unsafe_dirops); |
| 908 | spin_unlock(&ci->i_unsafe_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
| 912 | static void __unregister_request(struct ceph_mds_client *mdsc, |
| 913 | struct ceph_mds_request *req) |
| 914 | { |
| 915 | dout("__unregister_request %p tid %lld\n", req, req->r_tid); |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 916 | |
Jeff Layton | df963ea | 2017-02-14 10:09:40 -0500 | [diff] [blame] | 917 | /* Never leave an unregistered request on an unsafe list! */ |
| 918 | list_del_init(&req->r_unsafe_item); |
| 919 | |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 920 | if (req->r_tid == mdsc->oldest_tid) { |
| 921 | struct rb_node *p = rb_next(&req->r_node); |
| 922 | mdsc->oldest_tid = 0; |
| 923 | while (p) { |
| 924 | struct ceph_mds_request *next_req = |
| 925 | rb_entry(p, struct ceph_mds_request, r_node); |
| 926 | if (next_req->r_op != CEPH_MDS_OP_SETFILELOCK) { |
| 927 | mdsc->oldest_tid = next_req->r_tid; |
| 928 | break; |
| 929 | } |
| 930 | p = rb_next(p); |
| 931 | } |
| 932 | } |
| 933 | |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 934 | erase_request(&mdsc->request_tree, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 935 | |
Jeff Layton | 3db0a2f | 2019-04-04 08:05:38 -0400 | [diff] [blame] | 936 | if (req->r_unsafe_dir) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 937 | struct ceph_inode_info *ci = ceph_inode(req->r_unsafe_dir); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 938 | spin_lock(&ci->i_unsafe_lock); |
| 939 | list_del_init(&req->r_unsafe_dir_item); |
| 940 | spin_unlock(&ci->i_unsafe_lock); |
Yan, Zheng | 4c06ace | 2015-10-27 17:18:00 +0800 | [diff] [blame] | 941 | } |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 942 | if (req->r_target_inode && |
| 943 | test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) { |
Yan, Zheng | 68cd5b4 | 2015-10-27 18:36:06 +0800 | [diff] [blame] | 944 | struct ceph_inode_info *ci = ceph_inode(req->r_target_inode); |
| 945 | spin_lock(&ci->i_unsafe_lock); |
| 946 | list_del_init(&req->r_unsafe_target_item); |
| 947 | spin_unlock(&ci->i_unsafe_lock); |
| 948 | } |
Sage Weil | 3b66378 | 2011-05-18 16:12:12 -0700 | [diff] [blame] | 949 | |
Yan, Zheng | 4c06ace | 2015-10-27 17:18:00 +0800 | [diff] [blame] | 950 | if (req->r_unsafe_dir) { |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 951 | /* avoid calling iput_final() in mds dispatch threads */ |
| 952 | ceph_async_iput(req->r_unsafe_dir); |
Sage Weil | 3b66378 | 2011-05-18 16:12:12 -0700 | [diff] [blame] | 953 | req->r_unsafe_dir = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 954 | } |
Sage Weil | 94aa8ae | 2010-03-28 21:22:50 -0700 | [diff] [blame] | 955 | |
Yan, Zheng | fc55d2c | 2013-10-31 09:10:47 +0800 | [diff] [blame] | 956 | complete_all(&req->r_safe_completion); |
| 957 | |
Sage Weil | 94aa8ae | 2010-03-28 21:22:50 -0700 | [diff] [blame] | 958 | ceph_mdsc_put_request(req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /* |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 962 | * Walk back up the dentry tree until we hit a dentry representing a |
| 963 | * non-snapshot inode. We do this using the rcu_read_lock (which must be held |
| 964 | * when calling this) to ensure that the objects won't disappear while we're |
| 965 | * working with them. Once we hit a candidate dentry, we attempt to take a |
| 966 | * reference to it, and return that as the result. |
| 967 | */ |
Dan Carpenter | f107548 | 2017-02-23 13:39:59 +0300 | [diff] [blame] | 968 | static struct inode *get_nonsnap_parent(struct dentry *dentry) |
| 969 | { |
| 970 | struct inode *inode = NULL; |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 971 | |
| 972 | while (dentry && !IS_ROOT(dentry)) { |
| 973 | inode = d_inode_rcu(dentry); |
| 974 | if (!inode || ceph_snap(inode) == CEPH_NOSNAP) |
| 975 | break; |
| 976 | dentry = dentry->d_parent; |
| 977 | } |
| 978 | if (inode) |
| 979 | inode = igrab(inode); |
| 980 | return inode; |
| 981 | } |
| 982 | |
| 983 | /* |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 984 | * Choose mds to send request to next. If there is a hint set in the |
| 985 | * request (e.g., due to a prior forward hint from the mds), use that. |
| 986 | * Otherwise, consult frag tree and/or caps to identify the |
| 987 | * appropriate mds. If all else fails, choose randomly. |
| 988 | * |
| 989 | * Called under mdsc->mutex. |
| 990 | */ |
| 991 | static int __choose_mds(struct ceph_mds_client *mdsc, |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 992 | struct ceph_mds_request *req, |
| 993 | bool *random) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 994 | { |
| 995 | struct inode *inode; |
| 996 | struct ceph_inode_info *ci; |
| 997 | struct ceph_cap *cap; |
| 998 | int mode = req->r_direct_mode; |
| 999 | int mds = -1; |
| 1000 | u32 hash = req->r_direct_hash; |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 1001 | bool is_hash = test_bit(CEPH_MDS_R_DIRECT_IS_HASH, &req->r_req_flags); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1002 | |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 1003 | if (random) |
| 1004 | *random = false; |
| 1005 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1006 | /* |
| 1007 | * is there a specific mds we should try? ignore hint if we have |
| 1008 | * no session and the mds is not up (active or recovering). |
| 1009 | */ |
| 1010 | if (req->r_resend_mds >= 0 && |
| 1011 | (__have_session(mdsc, req->r_resend_mds) || |
| 1012 | ceph_mdsmap_get_state(mdsc->mdsmap, req->r_resend_mds) > 0)) { |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1013 | dout("%s using resend_mds mds%d\n", __func__, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1014 | req->r_resend_mds); |
| 1015 | return req->r_resend_mds; |
| 1016 | } |
| 1017 | |
| 1018 | if (mode == USE_RANDOM_MDS) |
| 1019 | goto random; |
| 1020 | |
| 1021 | inode = NULL; |
| 1022 | if (req->r_inode) { |
Yan, Zheng | 5d37ca1 | 2017-07-26 12:48:08 +0800 | [diff] [blame] | 1023 | if (ceph_snap(req->r_inode) != CEPH_SNAPDIR) { |
| 1024 | inode = req->r_inode; |
| 1025 | ihold(inode); |
| 1026 | } else { |
Yan, Zheng | 38f340c | 2017-09-22 11:41:06 +0800 | [diff] [blame] | 1027 | /* req->r_dentry is non-null for LSSNAP request */ |
| 1028 | rcu_read_lock(); |
| 1029 | inode = get_nonsnap_parent(req->r_dentry); |
| 1030 | rcu_read_unlock(); |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1031 | dout("%s using snapdir's parent %p\n", __func__, inode); |
Yan, Zheng | 5d37ca1 | 2017-07-26 12:48:08 +0800 | [diff] [blame] | 1032 | } |
Yan, Zheng | 38f340c | 2017-09-22 11:41:06 +0800 | [diff] [blame] | 1033 | } else if (req->r_dentry) { |
Sage Weil | d79698d | 2011-07-26 11:31:26 -0700 | [diff] [blame] | 1034 | /* ignore race with rename; old or new d_parent is okay */ |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1035 | struct dentry *parent; |
| 1036 | struct inode *dir; |
Sage Weil | eb6bb1c | 2010-08-16 09:21:27 -0700 | [diff] [blame] | 1037 | |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1038 | rcu_read_lock(); |
Yan, Zheng | 41883ba | 2019-05-23 10:22:55 +0800 | [diff] [blame] | 1039 | parent = READ_ONCE(req->r_dentry->d_parent); |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 1040 | dir = req->r_parent ? : d_inode_rcu(parent); |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1041 | |
| 1042 | if (!dir || dir->i_sb != mdsc->fsc->sb) { |
| 1043 | /* not this fs or parent went negative */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1044 | inode = d_inode(req->r_dentry); |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1045 | if (inode) |
| 1046 | ihold(inode); |
Sage Weil | eb6bb1c | 2010-08-16 09:21:27 -0700 | [diff] [blame] | 1047 | } else if (ceph_snap(dir) != CEPH_NOSNAP) { |
| 1048 | /* direct snapped/virtual snapdir requests |
| 1049 | * based on parent dir inode */ |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1050 | inode = get_nonsnap_parent(parent); |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1051 | dout("%s using nonsnap parent %p\n", __func__, inode); |
Yan, Zheng | ca18bed | 2013-11-22 14:21:44 +0800 | [diff] [blame] | 1052 | } else { |
Sage Weil | eb6bb1c | 2010-08-16 09:21:27 -0700 | [diff] [blame] | 1053 | /* dentry target */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1054 | inode = d_inode(req->r_dentry); |
Yan, Zheng | ca18bed | 2013-11-22 14:21:44 +0800 | [diff] [blame] | 1055 | if (!inode || mode == USE_AUTH_MDS) { |
| 1056 | /* dir + name */ |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1057 | inode = igrab(dir); |
Yan, Zheng | ca18bed | 2013-11-22 14:21:44 +0800 | [diff] [blame] | 1058 | hash = ceph_dentry_hash(dir, req->r_dentry); |
| 1059 | is_hash = true; |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1060 | } else { |
| 1061 | ihold(inode); |
Yan, Zheng | ca18bed | 2013-11-22 14:21:44 +0800 | [diff] [blame] | 1062 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1063 | } |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1064 | rcu_read_unlock(); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1065 | } |
Sage Weil | eb6bb1c | 2010-08-16 09:21:27 -0700 | [diff] [blame] | 1066 | |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1067 | dout("%s %p is_hash=%d (0x%x) mode %d\n", __func__, inode, (int)is_hash, |
| 1068 | hash, mode); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1069 | if (!inode) |
| 1070 | goto random; |
| 1071 | ci = ceph_inode(inode); |
| 1072 | |
| 1073 | if (is_hash && S_ISDIR(inode->i_mode)) { |
| 1074 | struct ceph_inode_frag frag; |
| 1075 | int found; |
| 1076 | |
| 1077 | ceph_choose_frag(ci, hash, &frag, &found); |
| 1078 | if (found) { |
| 1079 | if (mode == USE_ANY_MDS && frag.ndist > 0) { |
| 1080 | u8 r; |
| 1081 | |
| 1082 | /* choose a random replica */ |
| 1083 | get_random_bytes(&r, 1); |
| 1084 | r %= frag.ndist; |
| 1085 | mds = frag.dist[r]; |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1086 | dout("%s %p %llx.%llx frag %u mds%d (%d/%d)\n", |
| 1087 | __func__, inode, ceph_vinop(inode), |
| 1088 | frag.frag, mds, (int)r, frag.ndist); |
Sage Weil | d66bbd4 | 2011-01-21 21:16:46 -0800 | [diff] [blame] | 1089 | if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= |
Xiubo Li | 5d47648 | 2019-11-26 07:24:22 -0500 | [diff] [blame] | 1090 | CEPH_MDS_STATE_ACTIVE && |
| 1091 | !ceph_mdsmap_is_laggy(mdsc->mdsmap, mds)) |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1092 | goto out; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | /* since this file/dir wasn't known to be |
| 1096 | * replicated, then we want to look for the |
| 1097 | * authoritative mds. */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1098 | if (frag.mds >= 0) { |
| 1099 | /* choose auth mds */ |
| 1100 | mds = frag.mds; |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1101 | dout("%s %p %llx.%llx frag %u mds%d (auth)\n", |
| 1102 | __func__, inode, ceph_vinop(inode), |
| 1103 | frag.frag, mds); |
Sage Weil | d66bbd4 | 2011-01-21 21:16:46 -0800 | [diff] [blame] | 1104 | if (ceph_mdsmap_get_state(mdsc->mdsmap, mds) >= |
Xiubo Li | 5d47648 | 2019-11-26 07:24:22 -0500 | [diff] [blame] | 1105 | CEPH_MDS_STATE_ACTIVE) { |
| 1106 | if (mode == USE_ANY_MDS && |
| 1107 | !ceph_mdsmap_is_laggy(mdsc->mdsmap, |
| 1108 | mds)) |
| 1109 | goto out; |
| 1110 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1111 | } |
Xiubo Li | 5d47648 | 2019-11-26 07:24:22 -0500 | [diff] [blame] | 1112 | mode = USE_AUTH_MDS; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1116 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1117 | cap = NULL; |
| 1118 | if (mode == USE_AUTH_MDS) |
| 1119 | cap = ci->i_auth_cap; |
| 1120 | if (!cap && !RB_EMPTY_ROOT(&ci->i_caps)) |
| 1121 | cap = rb_entry(rb_first(&ci->i_caps), struct ceph_cap, ci_node); |
| 1122 | if (!cap) { |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1123 | spin_unlock(&ci->i_ceph_lock); |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 1124 | ceph_async_iput(inode); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1125 | goto random; |
| 1126 | } |
| 1127 | mds = cap->session->s_mds; |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1128 | dout("%s %p %llx.%llx mds%d (%scap %p)\n", __func__, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1129 | inode, ceph_vinop(inode), mds, |
| 1130 | cap == ci->i_auth_cap ? "auth " : "", cap); |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1131 | spin_unlock(&ci->i_ceph_lock); |
Jeff Layton | 30c7123 | 2016-12-15 08:37:56 -0500 | [diff] [blame] | 1132 | out: |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 1133 | /* avoid calling iput_final() while holding mdsc->mutex or |
| 1134 | * in mds dispatch threads */ |
| 1135 | ceph_async_iput(inode); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1136 | return mds; |
| 1137 | |
| 1138 | random: |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 1139 | if (random) |
| 1140 | *random = true; |
| 1141 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1142 | mds = ceph_mdsmap_get_random_mds(mdsc->mdsmap); |
Xiubo Li | 3c80209 | 2020-01-01 22:09:37 -0500 | [diff] [blame] | 1143 | dout("%s chose random mds%d\n", __func__, mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1144 | return mds; |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | /* |
| 1149 | * session messages |
| 1150 | */ |
| 1151 | static struct ceph_msg *create_session_msg(u32 op, u64 seq) |
| 1152 | { |
| 1153 | struct ceph_msg *msg; |
| 1154 | struct ceph_mds_session_head *h; |
| 1155 | |
Sage Weil | b61c276 | 2011-08-09 15:03:46 -0700 | [diff] [blame] | 1156 | msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h), GFP_NOFS, |
| 1157 | false); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1158 | if (!msg) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1159 | pr_err("create_session_msg ENOMEM creating msg\n"); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1160 | return NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1161 | } |
| 1162 | h = msg->front.iov_base; |
| 1163 | h->op = cpu_to_le32(op); |
| 1164 | h->seq = cpu_to_le64(seq); |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1165 | |
| 1166 | return msg; |
| 1167 | } |
| 1168 | |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1169 | static const unsigned char feature_bits[] = CEPHFS_FEATURES_CLIENT_SUPPORTED; |
| 1170 | #define FEATURE_BYTES(c) (DIV_ROUND_UP((size_t)feature_bits[c - 1] + 1, 64) * 8) |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1171 | static void encode_supported_features(void **p, void *end) |
| 1172 | { |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1173 | static const size_t count = ARRAY_SIZE(feature_bits); |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1174 | |
| 1175 | if (count > 0) { |
| 1176 | size_t i; |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1177 | size_t size = FEATURE_BYTES(count); |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1178 | |
| 1179 | BUG_ON(*p + 4 + size > end); |
| 1180 | ceph_encode_32(p, size); |
| 1181 | memset(*p, 0, size); |
| 1182 | for (i = 0; i < count; i++) |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1183 | ((unsigned char*)(*p))[i / 8] |= BIT(feature_bits[i] % 8); |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1184 | *p += size; |
| 1185 | } else { |
| 1186 | BUG_ON(*p + 4 > end); |
| 1187 | ceph_encode_32(p, 0); |
| 1188 | } |
| 1189 | } |
| 1190 | |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1191 | /* |
| 1192 | * session message, specialization for CEPH_SESSION_REQUEST_OPEN |
| 1193 | * to include additional client metadata fields. |
| 1194 | */ |
| 1195 | static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq) |
| 1196 | { |
| 1197 | struct ceph_msg *msg; |
| 1198 | struct ceph_mds_session_head *h; |
| 1199 | int i = -1; |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1200 | int extra_bytes = 0; |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1201 | int metadata_key_count = 0; |
| 1202 | struct ceph_options *opt = mdsc->fsc->client->options; |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 1203 | struct ceph_mount_options *fsopt = mdsc->fsc->mount_options; |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1204 | size_t size, count; |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1205 | void *p, *end; |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1206 | |
Yan, Zheng | a6a5ce4 | 2015-01-16 10:54:43 +0800 | [diff] [blame] | 1207 | const char* metadata[][2] = { |
Yan, Zheng | 717e6f2 | 2017-09-11 12:10:08 +0800 | [diff] [blame] | 1208 | {"hostname", mdsc->nodename}, |
| 1209 | {"kernel_version", init_utsname()->release}, |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 1210 | {"entity_id", opt->name ? : ""}, |
| 1211 | {"root", fsopt->server_path ? : "/"}, |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1212 | {NULL, NULL} |
| 1213 | }; |
| 1214 | |
| 1215 | /* Calculate serialized length of metadata */ |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1216 | extra_bytes = 4; /* map length */ |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 1217 | for (i = 0; metadata[i][0]; ++i) { |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1218 | extra_bytes += 8 + strlen(metadata[i][0]) + |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1219 | strlen(metadata[i][1]); |
| 1220 | metadata_key_count++; |
| 1221 | } |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1222 | |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1223 | /* supported feature */ |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1224 | size = 0; |
| 1225 | count = ARRAY_SIZE(feature_bits); |
| 1226 | if (count > 0) |
| 1227 | size = FEATURE_BYTES(count); |
| 1228 | extra_bytes += 4 + size; |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1229 | |
| 1230 | /* Allocate the message */ |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1231 | msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + extra_bytes, |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1232 | GFP_NOFS, false); |
| 1233 | if (!msg) { |
| 1234 | pr_err("create_session_msg ENOMEM creating msg\n"); |
| 1235 | return NULL; |
| 1236 | } |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1237 | p = msg->front.iov_base; |
| 1238 | end = p + msg->front.iov_len; |
| 1239 | |
| 1240 | h = p; |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1241 | h->op = cpu_to_le32(CEPH_SESSION_REQUEST_OPEN); |
| 1242 | h->seq = cpu_to_le64(seq); |
| 1243 | |
| 1244 | /* |
| 1245 | * Serialize client metadata into waiting buffer space, using |
| 1246 | * the format that userspace expects for map<string, string> |
John Spray | 7cfa031 | 2014-10-30 17:15:26 +0000 | [diff] [blame] | 1247 | * |
Xiubo Li | 9ba1e22 | 2020-01-08 05:17:31 -0500 | [diff] [blame] | 1248 | * ClientSession messages with metadata are v3 |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1249 | */ |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1250 | msg->hdr.version = cpu_to_le16(3); |
John Spray | 7cfa031 | 2014-10-30 17:15:26 +0000 | [diff] [blame] | 1251 | msg->hdr.compat_version = cpu_to_le16(1); |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1252 | |
| 1253 | /* The write pointer, following the session_head structure */ |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1254 | p += sizeof(*h); |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1255 | |
| 1256 | /* Number of entries in the map */ |
| 1257 | ceph_encode_32(&p, metadata_key_count); |
| 1258 | |
| 1259 | /* Two length-prefixed strings for each entry in the map */ |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 1260 | for (i = 0; metadata[i][0]; ++i) { |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1261 | size_t const key_len = strlen(metadata[i][0]); |
| 1262 | size_t const val_len = strlen(metadata[i][1]); |
| 1263 | |
| 1264 | ceph_encode_32(&p, key_len); |
| 1265 | memcpy(p, metadata[i][0], key_len); |
| 1266 | p += key_len; |
| 1267 | ceph_encode_32(&p, val_len); |
| 1268 | memcpy(p, metadata[i][1], val_len); |
| 1269 | p += val_len; |
| 1270 | } |
| 1271 | |
Yan, Zheng | 342ce18 | 2018-05-11 18:47:29 +0800 | [diff] [blame] | 1272 | encode_supported_features(&p, end); |
| 1273 | msg->front.iov_len = p - msg->front.iov_base; |
| 1274 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 1275 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1276 | return msg; |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | * send session open request. |
| 1281 | * |
| 1282 | * called under mdsc->mutex |
| 1283 | */ |
| 1284 | static int __open_session(struct ceph_mds_client *mdsc, |
| 1285 | struct ceph_mds_session *session) |
| 1286 | { |
| 1287 | struct ceph_msg *msg; |
| 1288 | int mstate; |
| 1289 | int mds = session->s_mds; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1290 | |
| 1291 | /* wait for mds to go active? */ |
| 1292 | mstate = ceph_mdsmap_get_state(mdsc->mdsmap, mds); |
| 1293 | dout("open_session to mds%d (%s)\n", mds, |
| 1294 | ceph_mds_state_name(mstate)); |
| 1295 | session->s_state = CEPH_MDS_SESSION_OPENING; |
| 1296 | session->s_renew_requested = jiffies; |
| 1297 | |
| 1298 | /* send connect message */ |
John Spray | dbd0c8b | 2014-09-09 19:26:01 +0100 | [diff] [blame] | 1299 | msg = create_session_open_msg(mdsc, session->s_seq); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1300 | if (!msg) |
| 1301 | return -ENOMEM; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1302 | ceph_con_send(&session->s_con, msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1303 | return 0; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1307 | * open sessions for any export targets for the given mds |
| 1308 | * |
| 1309 | * called under mdsc->mutex |
| 1310 | */ |
Yan, Zheng | 5d72d13 | 2013-11-24 14:33:01 +0800 | [diff] [blame] | 1311 | static struct ceph_mds_session * |
| 1312 | __open_export_target_session(struct ceph_mds_client *mdsc, int target) |
| 1313 | { |
| 1314 | struct ceph_mds_session *session; |
| 1315 | |
| 1316 | session = __ceph_lookup_mds_session(mdsc, target); |
| 1317 | if (!session) { |
| 1318 | session = register_session(mdsc, target); |
| 1319 | if (IS_ERR(session)) |
| 1320 | return session; |
| 1321 | } |
| 1322 | if (session->s_state == CEPH_MDS_SESSION_NEW || |
| 1323 | session->s_state == CEPH_MDS_SESSION_CLOSING) |
| 1324 | __open_session(mdsc, session); |
| 1325 | |
| 1326 | return session; |
| 1327 | } |
| 1328 | |
| 1329 | struct ceph_mds_session * |
| 1330 | ceph_mdsc_open_export_target_session(struct ceph_mds_client *mdsc, int target) |
| 1331 | { |
| 1332 | struct ceph_mds_session *session; |
| 1333 | |
| 1334 | dout("open_export_target_session to mds%d\n", target); |
| 1335 | |
| 1336 | mutex_lock(&mdsc->mutex); |
| 1337 | session = __open_export_target_session(mdsc, target); |
| 1338 | mutex_unlock(&mdsc->mutex); |
| 1339 | |
| 1340 | return session; |
| 1341 | } |
| 1342 | |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1343 | static void __open_export_target_sessions(struct ceph_mds_client *mdsc, |
| 1344 | struct ceph_mds_session *session) |
| 1345 | { |
| 1346 | struct ceph_mds_info *mi; |
| 1347 | struct ceph_mds_session *ts; |
| 1348 | int i, mds = session->s_mds; |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1349 | |
Xiubo Li | b38c9eb | 2019-12-04 06:57:39 -0500 | [diff] [blame] | 1350 | if (mds >= mdsc->mdsmap->possible_max_rank) |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1351 | return; |
Yan, Zheng | 5d72d13 | 2013-11-24 14:33:01 +0800 | [diff] [blame] | 1352 | |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1353 | mi = &mdsc->mdsmap->m_info[mds]; |
| 1354 | dout("open_export_target_sessions for mds%d (%d targets)\n", |
| 1355 | session->s_mds, mi->num_export_targets); |
| 1356 | |
| 1357 | for (i = 0; i < mi->num_export_targets; i++) { |
Yan, Zheng | 5d72d13 | 2013-11-24 14:33:01 +0800 | [diff] [blame] | 1358 | ts = __open_export_target_session(mdsc, mi->export_targets[i]); |
| 1359 | if (!IS_ERR(ts)) |
| 1360 | ceph_put_mds_session(ts); |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | |
Sage Weil | 154f42c | 2010-06-21 13:45:04 -0700 | [diff] [blame] | 1364 | void ceph_mdsc_open_export_target_sessions(struct ceph_mds_client *mdsc, |
| 1365 | struct ceph_mds_session *session) |
| 1366 | { |
| 1367 | mutex_lock(&mdsc->mutex); |
| 1368 | __open_export_target_sessions(mdsc, session); |
| 1369 | mutex_unlock(&mdsc->mutex); |
| 1370 | } |
| 1371 | |
Sage Weil | ed0552a | 2010-06-21 13:38:25 -0700 | [diff] [blame] | 1372 | /* |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1373 | * session caps |
| 1374 | */ |
| 1375 | |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1376 | static void detach_cap_releases(struct ceph_mds_session *session, |
| 1377 | struct list_head *target) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1378 | { |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1379 | lockdep_assert_held(&session->s_cap_lock); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1380 | |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1381 | list_splice_init(&session->s_cap_releases, target); |
| 1382 | session->s_num_cap_releases = 0; |
| 1383 | dout("dispose_cap_releases mds%d\n", session->s_mds); |
| 1384 | } |
| 1385 | |
| 1386 | static void dispose_cap_releases(struct ceph_mds_client *mdsc, |
| 1387 | struct list_head *dispose) |
| 1388 | { |
| 1389 | while (!list_empty(dispose)) { |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1390 | struct ceph_cap *cap; |
| 1391 | /* zero out the in-progress message */ |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1392 | cap = list_first_entry(dispose, struct ceph_cap, session_caps); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1393 | list_del(&cap->session_caps); |
| 1394 | ceph_put_cap(mdsc, cap); |
| 1395 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Yan, Zheng | 1c841a9 | 2015-03-24 20:15:36 +0800 | [diff] [blame] | 1398 | static void cleanup_session_requests(struct ceph_mds_client *mdsc, |
| 1399 | struct ceph_mds_session *session) |
| 1400 | { |
| 1401 | struct ceph_mds_request *req; |
| 1402 | struct rb_node *p; |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1403 | struct ceph_inode_info *ci; |
Yan, Zheng | 1c841a9 | 2015-03-24 20:15:36 +0800 | [diff] [blame] | 1404 | |
| 1405 | dout("cleanup_session_requests mds%d\n", session->s_mds); |
| 1406 | mutex_lock(&mdsc->mutex); |
| 1407 | while (!list_empty(&session->s_unsafe)) { |
| 1408 | req = list_first_entry(&session->s_unsafe, |
| 1409 | struct ceph_mds_request, r_unsafe_item); |
Yan, Zheng | 3e0708b | 2015-05-22 16:38:02 +0800 | [diff] [blame] | 1410 | pr_warn_ratelimited(" dropping unsafe request %llu\n", |
| 1411 | req->r_tid); |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1412 | if (req->r_target_inode) { |
| 1413 | /* dropping unsafe change of inode's attributes */ |
| 1414 | ci = ceph_inode(req->r_target_inode); |
| 1415 | errseq_set(&ci->i_meta_err, -EIO); |
| 1416 | } |
| 1417 | if (req->r_unsafe_dir) { |
| 1418 | /* dropping unsafe directory operation */ |
| 1419 | ci = ceph_inode(req->r_unsafe_dir); |
| 1420 | errseq_set(&ci->i_meta_err, -EIO); |
| 1421 | } |
Yan, Zheng | 1c841a9 | 2015-03-24 20:15:36 +0800 | [diff] [blame] | 1422 | __unregister_request(mdsc, req); |
| 1423 | } |
| 1424 | /* zero r_attempts, so kick_requests() will re-send requests */ |
| 1425 | p = rb_first(&mdsc->request_tree); |
| 1426 | while (p) { |
| 1427 | req = rb_entry(p, struct ceph_mds_request, r_node); |
| 1428 | p = rb_next(p); |
| 1429 | if (req->r_session && |
| 1430 | req->r_session->s_mds == session->s_mds) |
| 1431 | req->r_attempts = 0; |
| 1432 | } |
| 1433 | mutex_unlock(&mdsc->mutex); |
| 1434 | } |
| 1435 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1436 | /* |
Sage Weil | f818a73 | 2010-05-11 20:56:31 -0700 | [diff] [blame] | 1437 | * Helper to safely iterate over all caps associated with a session, with |
| 1438 | * special care taken to handle a racing __ceph_remove_cap(). |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1439 | * |
Sage Weil | f818a73 | 2010-05-11 20:56:31 -0700 | [diff] [blame] | 1440 | * Caller must hold session s_mutex. |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1441 | */ |
Jeff Layton | f5d77269 | 2019-04-24 12:09:04 -0400 | [diff] [blame] | 1442 | int ceph_iterate_session_caps(struct ceph_mds_session *session, |
| 1443 | int (*cb)(struct inode *, struct ceph_cap *, |
| 1444 | void *), void *arg) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1445 | { |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1446 | struct list_head *p; |
| 1447 | struct ceph_cap *cap; |
| 1448 | struct inode *inode, *last_inode = NULL; |
| 1449 | struct ceph_cap *old_cap = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1450 | int ret; |
| 1451 | |
| 1452 | dout("iterate_session_caps %p mds%d\n", session, session->s_mds); |
| 1453 | spin_lock(&session->s_cap_lock); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1454 | p = session->s_caps.next; |
| 1455 | while (p != &session->s_caps) { |
| 1456 | cap = list_entry(p, struct ceph_cap, session_caps); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1457 | inode = igrab(&cap->ci->vfs_inode); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1458 | if (!inode) { |
| 1459 | p = p->next; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1460 | continue; |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1461 | } |
| 1462 | session->s_cap_iterator = cap; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1463 | spin_unlock(&session->s_cap_lock); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1464 | |
| 1465 | if (last_inode) { |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 1466 | /* avoid calling iput_final() while holding |
| 1467 | * s_mutex or in mds dispatch threads */ |
| 1468 | ceph_async_iput(last_inode); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1469 | last_inode = NULL; |
| 1470 | } |
| 1471 | if (old_cap) { |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 1472 | ceph_put_cap(session->s_mdsc, old_cap); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1473 | old_cap = NULL; |
| 1474 | } |
| 1475 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1476 | ret = cb(inode, cap, arg); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1477 | last_inode = inode; |
| 1478 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1479 | spin_lock(&session->s_cap_lock); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1480 | p = p->next; |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 1481 | if (!cap->ci) { |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1482 | dout("iterate_session_caps finishing cap %p removal\n", |
| 1483 | cap); |
| 1484 | BUG_ON(cap->session != session); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1485 | cap->session = NULL; |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1486 | list_del_init(&cap->session_caps); |
| 1487 | session->s_nr_caps--; |
Xiubo Li | 4f1d756 | 2020-06-30 03:52:16 -0400 | [diff] [blame^] | 1488 | atomic64_dec(&session->s_mdsc->metric.total_caps); |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 1489 | if (cap->queue_release) |
| 1490 | __ceph_queue_cap_release(session, cap); |
| 1491 | else |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1492 | old_cap = cap; /* put_cap it w/o locks held */ |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1493 | } |
Sage Weil | 5dacf09 | 2009-12-21 20:40:34 -0800 | [diff] [blame] | 1494 | if (ret < 0) |
| 1495 | goto out; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1496 | } |
Sage Weil | 5dacf09 | 2009-12-21 20:40:34 -0800 | [diff] [blame] | 1497 | ret = 0; |
| 1498 | out: |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1499 | session->s_cap_iterator = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1500 | spin_unlock(&session->s_cap_lock); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1501 | |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 1502 | ceph_async_iput(last_inode); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1503 | if (old_cap) |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 1504 | ceph_put_cap(session->s_mdsc, old_cap); |
Sage Weil | 7c1332b | 2010-02-16 11:39:45 -0800 | [diff] [blame] | 1505 | |
Sage Weil | 5dacf09 | 2009-12-21 20:40:34 -0800 | [diff] [blame] | 1506 | return ret; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap, |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1510 | void *arg) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1511 | { |
Yan, Zheng | 6c93df5 | 2016-04-15 13:56:12 +0800 | [diff] [blame] | 1512 | struct ceph_fs_client *fsc = (struct ceph_fs_client *)arg; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1513 | struct ceph_inode_info *ci = ceph_inode(inode); |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 1514 | LIST_HEAD(to_remove); |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1515 | bool dirty_dropped = false; |
Yan, Zheng | 6c93df5 | 2016-04-15 13:56:12 +0800 | [diff] [blame] | 1516 | bool invalidate = false; |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1517 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1518 | dout("removing cap %p, ci is %p, inode is %p\n", |
| 1519 | cap, ci, &ci->vfs_inode); |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1520 | spin_lock(&ci->i_ceph_lock); |
Yan, Zheng | a096b09 | 2013-09-22 10:15:58 +0800 | [diff] [blame] | 1521 | __ceph_remove_cap(cap, false); |
Yan, Zheng | 571ade3 | 2015-03-24 11:36:08 +0800 | [diff] [blame] | 1522 | if (!ci->i_auth_cap) { |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 1523 | struct ceph_cap_flush *cf; |
Yan, Zheng | 6c93df5 | 2016-04-15 13:56:12 +0800 | [diff] [blame] | 1524 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1525 | |
Yan, Zheng | d468e72 | 2019-07-25 20:16:44 +0800 | [diff] [blame] | 1526 | if (READ_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { |
| 1527 | if (inode->i_data.nrpages > 0) |
| 1528 | invalidate = true; |
| 1529 | if (ci->i_wrbuffer_ref > 0) |
| 1530 | mapping_set_error(&inode->i_data, -EIO); |
| 1531 | } |
Yan, Zheng | 6c93df5 | 2016-04-15 13:56:12 +0800 | [diff] [blame] | 1532 | |
Yan, Zheng | e4500b5 | 2016-07-06 11:12:56 +0800 | [diff] [blame] | 1533 | while (!list_empty(&ci->i_cap_flush_list)) { |
| 1534 | cf = list_first_entry(&ci->i_cap_flush_list, |
| 1535 | struct ceph_cap_flush, i_list); |
Wei Yongjun | 8cdcc07 | 2016-08-13 09:10:28 +0000 | [diff] [blame] | 1536 | list_move(&cf->i_list, &to_remove); |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 1537 | } |
| 1538 | |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1539 | spin_lock(&mdsc->cap_dirty_lock); |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1540 | |
Yan, Zheng | e4500b5 | 2016-07-06 11:12:56 +0800 | [diff] [blame] | 1541 | list_for_each_entry(cf, &to_remove, i_list) |
| 1542 | list_del(&cf->g_list); |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1543 | |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1544 | if (!list_empty(&ci->i_dirty_item)) { |
Yan, Zheng | 3e0708b | 2015-05-22 16:38:02 +0800 | [diff] [blame] | 1545 | pr_warn_ratelimited( |
| 1546 | " dropping dirty %s state for %p %lld\n", |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1547 | ceph_cap_string(ci->i_dirty_caps), |
| 1548 | inode, ceph_ino(inode)); |
| 1549 | ci->i_dirty_caps = 0; |
| 1550 | list_del_init(&ci->i_dirty_item); |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1551 | dirty_dropped = true; |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1552 | } |
| 1553 | if (!list_empty(&ci->i_flushing_item)) { |
Yan, Zheng | 3e0708b | 2015-05-22 16:38:02 +0800 | [diff] [blame] | 1554 | pr_warn_ratelimited( |
| 1555 | " dropping dirty+flushing %s state for %p %lld\n", |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1556 | ceph_cap_string(ci->i_flushing_caps), |
| 1557 | inode, ceph_ino(inode)); |
| 1558 | ci->i_flushing_caps = 0; |
| 1559 | list_del_init(&ci->i_flushing_item); |
| 1560 | mdsc->num_cap_flushing--; |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1561 | dirty_dropped = true; |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1562 | } |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1563 | spin_unlock(&mdsc->cap_dirty_lock); |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 1564 | |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1565 | if (dirty_dropped) { |
| 1566 | errseq_set(&ci->i_meta_err, -EIO); |
| 1567 | |
| 1568 | if (ci->i_wrbuffer_ref_head == 0 && |
| 1569 | ci->i_wr_ref == 0 && |
| 1570 | ci->i_dirty_caps == 0 && |
| 1571 | ci->i_flushing_caps == 0) { |
| 1572 | ceph_put_snap_context(ci->i_head_snapc); |
| 1573 | ci->i_head_snapc = NULL; |
| 1574 | } |
| 1575 | } |
| 1576 | |
Yan, Zheng | b3f8d68 | 2017-09-11 10:58:55 +0800 | [diff] [blame] | 1577 | if (atomic_read(&ci->i_filelock_ref) > 0) { |
| 1578 | /* make further file lock syscall return -EIO */ |
| 1579 | ci->i_ceph_flags |= CEPH_I_ERROR_FILELOCK; |
| 1580 | pr_warn_ratelimited(" dropping file locks for %p %lld\n", |
| 1581 | inode, ceph_ino(inode)); |
| 1582 | } |
| 1583 | |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 1584 | if (!ci->i_dirty_caps && ci->i_prealloc_cap_flush) { |
Yan, Zheng | e4500b5 | 2016-07-06 11:12:56 +0800 | [diff] [blame] | 1585 | list_add(&ci->i_prealloc_cap_flush->i_list, &to_remove); |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 1586 | ci->i_prealloc_cap_flush = NULL; |
| 1587 | } |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1588 | } |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1589 | spin_unlock(&ci->i_ceph_lock); |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 1590 | while (!list_empty(&to_remove)) { |
| 1591 | struct ceph_cap_flush *cf; |
| 1592 | cf = list_first_entry(&to_remove, |
Yan, Zheng | e4500b5 | 2016-07-06 11:12:56 +0800 | [diff] [blame] | 1593 | struct ceph_cap_flush, i_list); |
| 1594 | list_del(&cf->i_list); |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 1595 | ceph_free_cap_flush(cf); |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 1596 | } |
Yan, Zheng | 7731032 | 2016-04-08 15:27:16 +0800 | [diff] [blame] | 1597 | |
| 1598 | wake_up_all(&ci->i_cap_wq); |
Yan, Zheng | 6c93df5 | 2016-04-15 13:56:12 +0800 | [diff] [blame] | 1599 | if (invalidate) |
| 1600 | ceph_queue_invalidate(inode); |
Yan, Zheng | f4b9786 | 2019-07-25 20:16:42 +0800 | [diff] [blame] | 1601 | if (dirty_dropped) |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1602 | iput(inode); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1603 | return 0; |
| 1604 | } |
| 1605 | |
| 1606 | /* |
| 1607 | * caller must hold session s_mutex |
| 1608 | */ |
| 1609 | static void remove_session_caps(struct ceph_mds_session *session) |
| 1610 | { |
Yan, Zheng | 6c93df5 | 2016-04-15 13:56:12 +0800 | [diff] [blame] | 1611 | struct ceph_fs_client *fsc = session->s_mdsc->fsc; |
| 1612 | struct super_block *sb = fsc->sb; |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1613 | LIST_HEAD(dispose); |
| 1614 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1615 | dout("remove_session_caps on %p\n", session); |
Jeff Layton | f5d77269 | 2019-04-24 12:09:04 -0400 | [diff] [blame] | 1616 | ceph_iterate_session_caps(session, remove_session_caps_cb, fsc); |
Yan, Zheng | 6f60f88 | 2013-07-24 12:22:11 +0800 | [diff] [blame] | 1617 | |
Yan, Zheng | c8799fc | 2016-07-07 15:22:38 +0800 | [diff] [blame] | 1618 | wake_up_all(&fsc->mdsc->cap_flushing_wq); |
| 1619 | |
Yan, Zheng | 6f60f88 | 2013-07-24 12:22:11 +0800 | [diff] [blame] | 1620 | spin_lock(&session->s_cap_lock); |
| 1621 | if (session->s_nr_caps > 0) { |
Yan, Zheng | 6f60f88 | 2013-07-24 12:22:11 +0800 | [diff] [blame] | 1622 | struct inode *inode; |
| 1623 | struct ceph_cap *cap, *prev = NULL; |
| 1624 | struct ceph_vino vino; |
| 1625 | /* |
| 1626 | * iterate_session_caps() skips inodes that are being |
| 1627 | * deleted, we need to wait until deletions are complete. |
| 1628 | * __wait_on_freeing_inode() is designed for the job, |
| 1629 | * but it is not exported, so use lookup inode function |
| 1630 | * to access it. |
| 1631 | */ |
| 1632 | while (!list_empty(&session->s_caps)) { |
| 1633 | cap = list_entry(session->s_caps.next, |
| 1634 | struct ceph_cap, session_caps); |
| 1635 | if (cap == prev) |
| 1636 | break; |
| 1637 | prev = cap; |
| 1638 | vino = cap->ci->i_vino; |
| 1639 | spin_unlock(&session->s_cap_lock); |
| 1640 | |
Yan, Zheng | ed284c4 | 2013-09-02 15:19:53 +0800 | [diff] [blame] | 1641 | inode = ceph_find_inode(sb, vino); |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 1642 | /* avoid calling iput_final() while holding s_mutex */ |
| 1643 | ceph_async_iput(inode); |
Yan, Zheng | 6f60f88 | 2013-07-24 12:22:11 +0800 | [diff] [blame] | 1644 | |
| 1645 | spin_lock(&session->s_cap_lock); |
| 1646 | } |
| 1647 | } |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1648 | |
| 1649 | // drop cap expires and unlock s_cap_lock |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1650 | detach_cap_releases(session, &dispose); |
Yan, Zheng | 6f60f88 | 2013-07-24 12:22:11 +0800 | [diff] [blame] | 1651 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1652 | BUG_ON(session->s_nr_caps > 0); |
Sage Weil | 6c99f25 | 2010-05-10 16:12:25 -0700 | [diff] [blame] | 1653 | BUG_ON(!list_empty(&session->s_cap_flushing)); |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 1654 | spin_unlock(&session->s_cap_lock); |
| 1655 | dispose_cap_releases(session->s_mdsc, &dispose); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1658 | enum { |
| 1659 | RECONNECT, |
| 1660 | RENEWCAPS, |
| 1661 | FORCE_RO, |
| 1662 | }; |
| 1663 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1664 | /* |
| 1665 | * wake up any threads waiting on this session's caps. if the cap is |
| 1666 | * old (didn't get renewed on the client reconnect), remove it now. |
| 1667 | * |
| 1668 | * caller must hold s_mutex. |
| 1669 | */ |
| 1670 | static int wake_up_session_cb(struct inode *inode, struct ceph_cap *cap, |
| 1671 | void *arg) |
| 1672 | { |
Sage Weil | 0dc2570 | 2009-11-20 13:43:45 -0800 | [diff] [blame] | 1673 | struct ceph_inode_info *ci = ceph_inode(inode); |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1674 | unsigned long ev = (unsigned long)arg; |
Sage Weil | 0dc2570 | 2009-11-20 13:43:45 -0800 | [diff] [blame] | 1675 | |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1676 | if (ev == RECONNECT) { |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1677 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 0dc2570 | 2009-11-20 13:43:45 -0800 | [diff] [blame] | 1678 | ci->i_wanted_max_size = 0; |
| 1679 | ci->i_requested_max_size = 0; |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1680 | spin_unlock(&ci->i_ceph_lock); |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1681 | } else if (ev == RENEWCAPS) { |
| 1682 | if (cap->cap_gen < cap->session->s_cap_gen) { |
| 1683 | /* mds did not re-issue stale cap */ |
| 1684 | spin_lock(&ci->i_ceph_lock); |
| 1685 | cap->issued = cap->implemented = CEPH_CAP_PIN; |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1686 | spin_unlock(&ci->i_ceph_lock); |
| 1687 | } |
| 1688 | } else if (ev == FORCE_RO) { |
Sage Weil | 0dc2570 | 2009-11-20 13:43:45 -0800 | [diff] [blame] | 1689 | } |
Yan, Zheng | e536030 | 2016-05-19 19:15:19 +0800 | [diff] [blame] | 1690 | wake_up_all(&ci->i_cap_wq); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1691 | return 0; |
| 1692 | } |
| 1693 | |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1694 | static void wake_up_session_caps(struct ceph_mds_session *session, int ev) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1695 | { |
| 1696 | dout("wake_up_session_caps %p mds%d\n", session, session->s_mds); |
Jeff Layton | f5d77269 | 2019-04-24 12:09:04 -0400 | [diff] [blame] | 1697 | ceph_iterate_session_caps(session, wake_up_session_cb, |
| 1698 | (void *)(unsigned long)ev); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | /* |
| 1702 | * Send periodic message to MDS renewing all currently held caps. The |
| 1703 | * ack will reset the expiration for all caps from this session. |
| 1704 | * |
| 1705 | * caller holds s_mutex |
| 1706 | */ |
| 1707 | static int send_renew_caps(struct ceph_mds_client *mdsc, |
| 1708 | struct ceph_mds_session *session) |
| 1709 | { |
| 1710 | struct ceph_msg *msg; |
| 1711 | int state; |
| 1712 | |
| 1713 | if (time_after_eq(jiffies, session->s_cap_ttl) && |
| 1714 | time_after_eq(session->s_cap_ttl, session->s_renew_requested)) |
| 1715 | pr_info("mds%d caps stale\n", session->s_mds); |
Sage Weil | e4cb4cb | 2010-03-18 13:43:09 -0700 | [diff] [blame] | 1716 | session->s_renew_requested = jiffies; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1717 | |
| 1718 | /* do not try to renew caps until a recovering mds has reconnected |
| 1719 | * with its clients. */ |
| 1720 | state = ceph_mdsmap_get_state(mdsc->mdsmap, session->s_mds); |
| 1721 | if (state < CEPH_MDS_STATE_RECONNECT) { |
| 1722 | dout("send_renew_caps ignoring mds%d (%s)\n", |
| 1723 | session->s_mds, ceph_mds_state_name(state)); |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
| 1727 | dout("send_renew_caps to mds%d (%s)\n", session->s_mds, |
| 1728 | ceph_mds_state_name(state)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1729 | msg = create_session_msg(CEPH_SESSION_REQUEST_RENEWCAPS, |
| 1730 | ++session->s_renew_seq); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1731 | if (!msg) |
| 1732 | return -ENOMEM; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1733 | ceph_con_send(&session->s_con, msg); |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
Yan, Zheng | 186e4f7 | 2013-11-22 14:48:37 +0800 | [diff] [blame] | 1737 | static int send_flushmsg_ack(struct ceph_mds_client *mdsc, |
| 1738 | struct ceph_mds_session *session, u64 seq) |
| 1739 | { |
| 1740 | struct ceph_msg *msg; |
| 1741 | |
| 1742 | dout("send_flushmsg_ack to mds%d (%s)s seq %lld\n", |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 1743 | session->s_mds, ceph_session_state_name(session->s_state), seq); |
Yan, Zheng | 186e4f7 | 2013-11-22 14:48:37 +0800 | [diff] [blame] | 1744 | msg = create_session_msg(CEPH_SESSION_FLUSHMSG_ACK, seq); |
| 1745 | if (!msg) |
| 1746 | return -ENOMEM; |
| 1747 | ceph_con_send(&session->s_con, msg); |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1752 | /* |
| 1753 | * Note new cap ttl, and any transition from stale -> not stale (fresh?). |
Sage Weil | 0dc2570 | 2009-11-20 13:43:45 -0800 | [diff] [blame] | 1754 | * |
| 1755 | * Called under session->s_mutex |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1756 | */ |
| 1757 | static void renewed_caps(struct ceph_mds_client *mdsc, |
| 1758 | struct ceph_mds_session *session, int is_renew) |
| 1759 | { |
| 1760 | int was_stale; |
| 1761 | int wake = 0; |
| 1762 | |
| 1763 | spin_lock(&session->s_cap_lock); |
Alex Elder | 1ce208a | 2012-01-12 17:48:11 -0800 | [diff] [blame] | 1764 | was_stale = is_renew && time_after_eq(jiffies, session->s_cap_ttl); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1765 | |
| 1766 | session->s_cap_ttl = session->s_renew_requested + |
| 1767 | mdsc->mdsmap->m_session_timeout*HZ; |
| 1768 | |
| 1769 | if (was_stale) { |
| 1770 | if (time_before(jiffies, session->s_cap_ttl)) { |
| 1771 | pr_info("mds%d caps renewed\n", session->s_mds); |
| 1772 | wake = 1; |
| 1773 | } else { |
| 1774 | pr_info("mds%d caps still stale\n", session->s_mds); |
| 1775 | } |
| 1776 | } |
| 1777 | dout("renewed_caps mds%d ttl now %lu, was %s, now %s\n", |
| 1778 | session->s_mds, session->s_cap_ttl, was_stale ? "stale" : "fresh", |
| 1779 | time_before(jiffies, session->s_cap_ttl) ? "stale" : "fresh"); |
| 1780 | spin_unlock(&session->s_cap_lock); |
| 1781 | |
| 1782 | if (wake) |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 1783 | wake_up_session_caps(session, RENEWCAPS); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | /* |
| 1787 | * send a session close request |
| 1788 | */ |
Xiubo Li | 3e699bd | 2020-06-30 03:52:15 -0400 | [diff] [blame] | 1789 | static int request_close_session(struct ceph_mds_session *session) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1790 | { |
| 1791 | struct ceph_msg *msg; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1792 | |
| 1793 | dout("request_close_session mds%d state %s seq %lld\n", |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 1794 | session->s_mds, ceph_session_state_name(session->s_state), |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1795 | session->s_seq); |
| 1796 | msg = create_session_msg(CEPH_SESSION_REQUEST_CLOSE, session->s_seq); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 1797 | if (!msg) |
| 1798 | return -ENOMEM; |
| 1799 | ceph_con_send(&session->s_con, msg); |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 1800 | return 1; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | /* |
| 1804 | * Called with s_mutex held. |
| 1805 | */ |
| 1806 | static int __close_session(struct ceph_mds_client *mdsc, |
| 1807 | struct ceph_mds_session *session) |
| 1808 | { |
| 1809 | if (session->s_state >= CEPH_MDS_SESSION_CLOSING) |
| 1810 | return 0; |
| 1811 | session->s_state = CEPH_MDS_SESSION_CLOSING; |
Xiubo Li | 3e699bd | 2020-06-30 03:52:15 -0400 | [diff] [blame] | 1812 | return request_close_session(session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
Yan, Zheng | 040d786 | 2017-11-30 11:59:22 +0800 | [diff] [blame] | 1815 | static bool drop_negative_children(struct dentry *dentry) |
| 1816 | { |
| 1817 | struct dentry *child; |
| 1818 | bool all_negative = true; |
| 1819 | |
| 1820 | if (!d_is_dir(dentry)) |
| 1821 | goto out; |
| 1822 | |
| 1823 | spin_lock(&dentry->d_lock); |
| 1824 | list_for_each_entry(child, &dentry->d_subdirs, d_child) { |
| 1825 | if (d_really_is_positive(child)) { |
| 1826 | all_negative = false; |
| 1827 | break; |
| 1828 | } |
| 1829 | } |
| 1830 | spin_unlock(&dentry->d_lock); |
| 1831 | |
| 1832 | if (all_negative) |
| 1833 | shrink_dcache_parent(dentry); |
| 1834 | out: |
| 1835 | return all_negative; |
| 1836 | } |
| 1837 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1838 | /* |
| 1839 | * Trim old(er) caps. |
| 1840 | * |
| 1841 | * Because we can't cache an inode without one or more caps, we do |
| 1842 | * this indirectly: if a cap is unused, we prune its aliases, at which |
| 1843 | * point the inode will hopefully get dropped to. |
| 1844 | * |
| 1845 | * Yes, this is a bit sloppy. Our only real goal here is to respond to |
| 1846 | * memory pressure from the MDS, though, so it needn't be perfect. |
| 1847 | */ |
| 1848 | static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg) |
| 1849 | { |
Jeff Layton | 533a281 | 2019-07-19 15:22:28 -0400 | [diff] [blame] | 1850 | int *remaining = arg; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1851 | struct ceph_inode_info *ci = ceph_inode(inode); |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1852 | int used, wanted, oissued, mine; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1853 | |
Jeff Layton | 533a281 | 2019-07-19 15:22:28 -0400 | [diff] [blame] | 1854 | if (*remaining <= 0) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1855 | return -1; |
| 1856 | |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1857 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1858 | mine = cap->issued | cap->implemented; |
| 1859 | used = __ceph_caps_used(ci); |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1860 | wanted = __ceph_caps_file_wanted(ci); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1861 | oissued = __ceph_caps_issued_other(ci, cap); |
| 1862 | |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1863 | dout("trim_caps_cb %p cap %p mine %s oissued %s used %s wanted %s\n", |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1864 | inode, cap, ceph_cap_string(mine), ceph_cap_string(oissued), |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1865 | ceph_cap_string(used), ceph_cap_string(wanted)); |
| 1866 | if (cap == ci->i_auth_cap) { |
Yan, Zheng | 622f3e2 | 2015-05-07 10:59:47 +0800 | [diff] [blame] | 1867 | if (ci->i_dirty_caps || ci->i_flushing_caps || |
| 1868 | !list_empty(&ci->i_cap_snaps)) |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1869 | goto out; |
| 1870 | if ((used | wanted) & CEPH_CAP_ANY_WR) |
| 1871 | goto out; |
Yan, Zheng | 89aa593 | 2017-09-08 15:23:18 +0800 | [diff] [blame] | 1872 | /* Note: it's possible that i_filelock_ref becomes non-zero |
| 1873 | * after dropping auth caps. It doesn't hurt because reply |
| 1874 | * of lock mds request will re-add auth caps. */ |
| 1875 | if (atomic_read(&ci->i_filelock_ref) > 0) |
| 1876 | goto out; |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1877 | } |
Yan, Zheng | 5e804ac | 2015-10-26 16:08:43 +0800 | [diff] [blame] | 1878 | /* The inode has cached pages, but it's no longer used. |
| 1879 | * we can safely drop it */ |
Yan, Zheng | 525d15e | 2019-05-11 17:27:59 +0800 | [diff] [blame] | 1880 | if (S_ISREG(inode->i_mode) && |
| 1881 | wanted == 0 && used == CEPH_CAP_FILE_CACHE && |
Yan, Zheng | 5e804ac | 2015-10-26 16:08:43 +0800 | [diff] [blame] | 1882 | !(oissued & CEPH_CAP_FILE_CACHE)) { |
| 1883 | used = 0; |
| 1884 | oissued = 0; |
| 1885 | } |
Yan, Zheng | 979abfd | 2013-11-22 13:56:24 +0800 | [diff] [blame] | 1886 | if ((used | wanted) & ~oissued & mine) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1887 | goto out; /* we need these caps */ |
| 1888 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1889 | if (oissued) { |
| 1890 | /* we aren't the only cap.. just remove us */ |
Yan, Zheng | a096b09 | 2013-09-22 10:15:58 +0800 | [diff] [blame] | 1891 | __ceph_remove_cap(cap, true); |
Jeff Layton | 533a281 | 2019-07-19 15:22:28 -0400 | [diff] [blame] | 1892 | (*remaining)--; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1893 | } else { |
Yan, Zheng | 040d786 | 2017-11-30 11:59:22 +0800 | [diff] [blame] | 1894 | struct dentry *dentry; |
Yan, Zheng | 5e804ac | 2015-10-26 16:08:43 +0800 | [diff] [blame] | 1895 | /* try dropping referring dentries */ |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1896 | spin_unlock(&ci->i_ceph_lock); |
Yan, Zheng | 040d786 | 2017-11-30 11:59:22 +0800 | [diff] [blame] | 1897 | dentry = d_find_any_alias(inode); |
| 1898 | if (dentry && drop_negative_children(dentry)) { |
| 1899 | int count; |
| 1900 | dput(dentry); |
| 1901 | d_prune_aliases(inode); |
| 1902 | count = atomic_read(&inode->i_count); |
| 1903 | if (count == 1) |
Jeff Layton | 533a281 | 2019-07-19 15:22:28 -0400 | [diff] [blame] | 1904 | (*remaining)--; |
Yan, Zheng | 040d786 | 2017-11-30 11:59:22 +0800 | [diff] [blame] | 1905 | dout("trim_caps_cb %p cap %p pruned, count now %d\n", |
| 1906 | inode, cap, count); |
| 1907 | } else { |
| 1908 | dput(dentry); |
| 1909 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1910 | return 0; |
| 1911 | } |
| 1912 | |
| 1913 | out: |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 1914 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | /* |
| 1919 | * Trim session cap count down to some max number. |
| 1920 | */ |
Zhi Zhang | e30ee58 | 2018-01-24 21:24:33 +0800 | [diff] [blame] | 1921 | int ceph_trim_caps(struct ceph_mds_client *mdsc, |
| 1922 | struct ceph_mds_session *session, |
| 1923 | int max_caps) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1924 | { |
| 1925 | int trim_caps = session->s_nr_caps - max_caps; |
| 1926 | |
| 1927 | dout("trim_caps mds%d start: %d / %d, trim %d\n", |
| 1928 | session->s_mds, session->s_nr_caps, max_caps, trim_caps); |
| 1929 | if (trim_caps > 0) { |
Jeff Layton | 533a281 | 2019-07-19 15:22:28 -0400 | [diff] [blame] | 1930 | int remaining = trim_caps; |
| 1931 | |
| 1932 | ceph_iterate_session_caps(session, trim_caps_cb, &remaining); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1933 | dout("trim_caps mds%d done: %d / %d, trimmed %d\n", |
| 1934 | session->s_mds, session->s_nr_caps, max_caps, |
Jeff Layton | 533a281 | 2019-07-19 15:22:28 -0400 | [diff] [blame] | 1935 | trim_caps - remaining); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1936 | } |
Yan, Zheng | a56371d | 2014-04-01 20:34:56 +0800 | [diff] [blame] | 1937 | |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 1938 | ceph_flush_cap_releases(mdsc, session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1939 | return 0; |
| 1940 | } |
| 1941 | |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1942 | static int check_caps_flush(struct ceph_mds_client *mdsc, |
| 1943 | u64 want_flush_tid) |
| 1944 | { |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1945 | int ret = 1; |
| 1946 | |
| 1947 | spin_lock(&mdsc->cap_dirty_lock); |
Yan, Zheng | e4500b5 | 2016-07-06 11:12:56 +0800 | [diff] [blame] | 1948 | if (!list_empty(&mdsc->cap_flush_list)) { |
| 1949 | struct ceph_cap_flush *cf = |
| 1950 | list_first_entry(&mdsc->cap_flush_list, |
| 1951 | struct ceph_cap_flush, g_list); |
| 1952 | if (cf->tid <= want_flush_tid) { |
| 1953 | dout("check_caps_flush still flushing tid " |
| 1954 | "%llu <= %llu\n", cf->tid, want_flush_tid); |
| 1955 | ret = 0; |
| 1956 | } |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1957 | } |
| 1958 | spin_unlock(&mdsc->cap_dirty_lock); |
| 1959 | return ret; |
Yan, Zheng | d3383a8 | 2015-01-08 21:30:12 +0800 | [diff] [blame] | 1960 | } |
| 1961 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1962 | /* |
| 1963 | * flush all dirty inode data to disk. |
| 1964 | * |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1965 | * returns true if we've flushed through want_flush_tid |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1966 | */ |
Yan, Zheng | affbc19 | 2015-05-05 21:22:13 +0800 | [diff] [blame] | 1967 | static void wait_caps_flush(struct ceph_mds_client *mdsc, |
Yan, Zheng | 0e29438 | 2016-07-04 18:06:41 +0800 | [diff] [blame] | 1968 | u64 want_flush_tid) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1969 | { |
Yan, Zheng | 0e29438 | 2016-07-04 18:06:41 +0800 | [diff] [blame] | 1970 | dout("check_caps_flush want %llu\n", want_flush_tid); |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 1971 | |
| 1972 | wait_event(mdsc->cap_flushing_wq, |
| 1973 | check_caps_flush(mdsc, want_flush_tid)); |
| 1974 | |
| 1975 | dout("check_caps_flush ok, flushed thru %llu\n", want_flush_tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | /* |
| 1979 | * called under s_mutex |
| 1980 | */ |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 1981 | static void ceph_send_cap_releases(struct ceph_mds_client *mdsc, |
| 1982 | struct ceph_mds_session *session) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1983 | { |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1984 | struct ceph_msg *msg = NULL; |
| 1985 | struct ceph_mds_cap_release *head; |
| 1986 | struct ceph_mds_cap_item *item; |
Jeff Layton | 92475f0 | 2017-04-13 11:07:04 -0400 | [diff] [blame] | 1987 | struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc; |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1988 | struct ceph_cap *cap; |
| 1989 | LIST_HEAD(tmp_list); |
| 1990 | int num_cap_releases; |
Jeff Layton | 92475f0 | 2017-04-13 11:07:04 -0400 | [diff] [blame] | 1991 | __le32 barrier, *cap_barrier; |
| 1992 | |
| 1993 | down_read(&osdc->lock); |
| 1994 | barrier = cpu_to_le32(osdc->epoch_barrier); |
| 1995 | up_read(&osdc->lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 1996 | |
Sage Weil | 0f8605f | 2010-05-05 15:51:35 -0700 | [diff] [blame] | 1997 | spin_lock(&session->s_cap_lock); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 1998 | again: |
| 1999 | list_splice_init(&session->s_cap_releases, &tmp_list); |
| 2000 | num_cap_releases = session->s_num_cap_releases; |
| 2001 | session->s_num_cap_releases = 0; |
| 2002 | spin_unlock(&session->s_cap_lock); |
| 2003 | |
| 2004 | while (!list_empty(&tmp_list)) { |
| 2005 | if (!msg) { |
| 2006 | msg = ceph_msg_new(CEPH_MSG_CLIENT_CAPRELEASE, |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 2007 | PAGE_SIZE, GFP_NOFS, false); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 2008 | if (!msg) |
| 2009 | goto out_err; |
| 2010 | head = msg->front.iov_base; |
| 2011 | head->num = cpu_to_le32(0); |
| 2012 | msg->front.iov_len = sizeof(*head); |
Jeff Layton | 92475f0 | 2017-04-13 11:07:04 -0400 | [diff] [blame] | 2013 | |
| 2014 | msg->hdr.version = cpu_to_le16(2); |
| 2015 | msg->hdr.compat_version = cpu_to_le16(1); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 2016 | } |
Jeff Layton | 92475f0 | 2017-04-13 11:07:04 -0400 | [diff] [blame] | 2017 | |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 2018 | cap = list_first_entry(&tmp_list, struct ceph_cap, |
| 2019 | session_caps); |
| 2020 | list_del(&cap->session_caps); |
| 2021 | num_cap_releases--; |
| 2022 | |
| 2023 | head = msg->front.iov_base; |
Jeff Layton | 4198aba | 2019-05-02 08:06:50 -0400 | [diff] [blame] | 2024 | put_unaligned_le32(get_unaligned_le32(&head->num) + 1, |
| 2025 | &head->num); |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 2026 | item = msg->front.iov_base + msg->front.iov_len; |
| 2027 | item->ino = cpu_to_le64(cap->cap_ino); |
| 2028 | item->cap_id = cpu_to_le64(cap->cap_id); |
| 2029 | item->migrate_seq = cpu_to_le32(cap->mseq); |
| 2030 | item->seq = cpu_to_le32(cap->issue_seq); |
| 2031 | msg->front.iov_len += sizeof(*item); |
| 2032 | |
| 2033 | ceph_put_cap(mdsc, cap); |
| 2034 | |
| 2035 | if (le32_to_cpu(head->num) == CEPH_CAPS_PER_RELEASE) { |
Jeff Layton | 92475f0 | 2017-04-13 11:07:04 -0400 | [diff] [blame] | 2036 | // Append cap_barrier field |
| 2037 | cap_barrier = msg->front.iov_base + msg->front.iov_len; |
| 2038 | *cap_barrier = barrier; |
| 2039 | msg->front.iov_len += sizeof(*cap_barrier); |
| 2040 | |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 2041 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 2042 | dout("send_cap_releases mds%d %p\n", session->s_mds, msg); |
| 2043 | ceph_con_send(&session->s_con, msg); |
| 2044 | msg = NULL; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | BUG_ON(num_cap_releases != 0); |
| 2049 | |
| 2050 | spin_lock(&session->s_cap_lock); |
| 2051 | if (!list_empty(&session->s_cap_releases)) |
| 2052 | goto again; |
| 2053 | spin_unlock(&session->s_cap_lock); |
| 2054 | |
| 2055 | if (msg) { |
Jeff Layton | 92475f0 | 2017-04-13 11:07:04 -0400 | [diff] [blame] | 2056 | // Append cap_barrier field |
| 2057 | cap_barrier = msg->front.iov_base + msg->front.iov_len; |
| 2058 | *cap_barrier = barrier; |
| 2059 | msg->front.iov_len += sizeof(*cap_barrier); |
| 2060 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2061 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 2062 | dout("send_cap_releases mds%d %p\n", session->s_mds, msg); |
| 2063 | ceph_con_send(&session->s_con, msg); |
| 2064 | } |
Yan, Zheng | 745a8e3 | 2015-05-14 17:22:42 +0800 | [diff] [blame] | 2065 | return; |
| 2066 | out_err: |
| 2067 | pr_err("send_cap_releases mds%d, failed to allocate message\n", |
| 2068 | session->s_mds); |
| 2069 | spin_lock(&session->s_cap_lock); |
| 2070 | list_splice(&tmp_list, &session->s_cap_releases); |
| 2071 | session->s_num_cap_releases += num_cap_releases; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2072 | spin_unlock(&session->s_cap_lock); |
| 2073 | } |
| 2074 | |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 2075 | static void ceph_cap_release_work(struct work_struct *work) |
| 2076 | { |
| 2077 | struct ceph_mds_session *session = |
| 2078 | container_of(work, struct ceph_mds_session, s_cap_release_work); |
| 2079 | |
| 2080 | mutex_lock(&session->s_mutex); |
| 2081 | if (session->s_state == CEPH_MDS_SESSION_OPEN || |
| 2082 | session->s_state == CEPH_MDS_SESSION_HUNG) |
| 2083 | ceph_send_cap_releases(session->s_mdsc, session); |
| 2084 | mutex_unlock(&session->s_mutex); |
| 2085 | ceph_put_mds_session(session); |
| 2086 | } |
| 2087 | |
| 2088 | void ceph_flush_cap_releases(struct ceph_mds_client *mdsc, |
| 2089 | struct ceph_mds_session *session) |
| 2090 | { |
| 2091 | if (mdsc->stopping) |
| 2092 | return; |
| 2093 | |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 2094 | ceph_get_mds_session(session); |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 2095 | if (queue_work(mdsc->fsc->cap_wq, |
| 2096 | &session->s_cap_release_work)) { |
| 2097 | dout("cap release work queued\n"); |
| 2098 | } else { |
| 2099 | ceph_put_mds_session(session); |
| 2100 | dout("failed to queue cap release work\n"); |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | /* |
| 2105 | * caller holds session->s_cap_lock |
| 2106 | */ |
| 2107 | void __ceph_queue_cap_release(struct ceph_mds_session *session, |
| 2108 | struct ceph_cap *cap) |
| 2109 | { |
| 2110 | list_add_tail(&cap->session_caps, &session->s_cap_releases); |
| 2111 | session->s_num_cap_releases++; |
| 2112 | |
| 2113 | if (!(session->s_num_cap_releases % CEPH_CAPS_PER_RELEASE)) |
| 2114 | ceph_flush_cap_releases(session->s_mdsc, session); |
| 2115 | } |
| 2116 | |
Yan, Zheng | 37c4efc | 2019-01-31 16:55:51 +0800 | [diff] [blame] | 2117 | static void ceph_cap_reclaim_work(struct work_struct *work) |
| 2118 | { |
| 2119 | struct ceph_mds_client *mdsc = |
| 2120 | container_of(work, struct ceph_mds_client, cap_reclaim_work); |
| 2121 | int ret = ceph_trim_dentries(mdsc); |
| 2122 | if (ret == -EAGAIN) |
| 2123 | ceph_queue_cap_reclaim_work(mdsc); |
| 2124 | } |
| 2125 | |
| 2126 | void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc) |
| 2127 | { |
| 2128 | if (mdsc->stopping) |
| 2129 | return; |
| 2130 | |
| 2131 | if (queue_work(mdsc->fsc->cap_wq, &mdsc->cap_reclaim_work)) { |
| 2132 | dout("caps reclaim work queued\n"); |
| 2133 | } else { |
| 2134 | dout("failed to queue caps release work\n"); |
| 2135 | } |
| 2136 | } |
| 2137 | |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 2138 | void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr) |
| 2139 | { |
| 2140 | int val; |
| 2141 | if (!nr) |
| 2142 | return; |
| 2143 | val = atomic_add_return(nr, &mdsc->cap_reclaim_pending); |
Xiubo Li | bba1560 | 2019-11-26 07:32:22 -0500 | [diff] [blame] | 2144 | if ((val % CEPH_CAPS_PER_RELEASE) < nr) { |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 2145 | atomic_set(&mdsc->cap_reclaim_pending, 0); |
| 2146 | ceph_queue_cap_reclaim_work(mdsc); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2150 | /* |
| 2151 | * requests |
| 2152 | */ |
| 2153 | |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 2154 | int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req, |
| 2155 | struct inode *dir) |
| 2156 | { |
| 2157 | struct ceph_inode_info *ci = ceph_inode(dir); |
| 2158 | struct ceph_mds_reply_info_parsed *rinfo = &req->r_reply_info; |
| 2159 | struct ceph_mount_options *opt = req->r_mdsc->fsc->mount_options; |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 2160 | size_t size = sizeof(struct ceph_mds_reply_dir_entry); |
Jeff Layton | ad8c28a | 2019-09-09 15:58:55 -0400 | [diff] [blame] | 2161 | unsigned int num_entries; |
| 2162 | int order; |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 2163 | |
| 2164 | spin_lock(&ci->i_ceph_lock); |
| 2165 | num_entries = ci->i_files + ci->i_subdirs; |
| 2166 | spin_unlock(&ci->i_ceph_lock); |
Jeff Layton | ad8c28a | 2019-09-09 15:58:55 -0400 | [diff] [blame] | 2167 | num_entries = max(num_entries, 1U); |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 2168 | num_entries = min(num_entries, opt->max_readdir); |
| 2169 | |
| 2170 | order = get_order(size * num_entries); |
| 2171 | while (order >= 0) { |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 2172 | rinfo->dir_entries = (void*)__get_free_pages(GFP_KERNEL | |
| 2173 | __GFP_NOWARN, |
| 2174 | order); |
| 2175 | if (rinfo->dir_entries) |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 2176 | break; |
| 2177 | order--; |
| 2178 | } |
Yan, Zheng | 2a5beea | 2016-04-28 09:37:39 +0800 | [diff] [blame] | 2179 | if (!rinfo->dir_entries) |
Yan, Zheng | 5400839 | 2014-03-29 13:41:15 +0800 | [diff] [blame] | 2180 | return -ENOMEM; |
| 2181 | |
| 2182 | num_entries = (PAGE_SIZE << order) / size; |
| 2183 | num_entries = min(num_entries, opt->max_readdir); |
| 2184 | |
| 2185 | rinfo->dir_buf_size = PAGE_SIZE << order; |
| 2186 | req->r_num_caps = num_entries + 1; |
| 2187 | req->r_args.readdir.max_entries = cpu_to_le32(num_entries); |
| 2188 | req->r_args.readdir.max_bytes = cpu_to_le32(opt->max_readdir_bytes); |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2192 | /* |
| 2193 | * Create an mds request. |
| 2194 | */ |
| 2195 | struct ceph_mds_request * |
| 2196 | ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) |
| 2197 | { |
Jeff Layton | 058daab | 2020-02-17 18:38:37 -0500 | [diff] [blame] | 2198 | struct ceph_mds_request *req; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2199 | |
Jeff Layton | 058daab | 2020-02-17 18:38:37 -0500 | [diff] [blame] | 2200 | req = kmem_cache_zalloc(ceph_mds_request_cachep, GFP_NOFS); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2201 | if (!req) |
| 2202 | return ERR_PTR(-ENOMEM); |
| 2203 | |
Sage Weil | b455639 | 2010-05-13 12:01:13 -0700 | [diff] [blame] | 2204 | mutex_init(&req->r_fill_mutex); |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 2205 | req->r_mdsc = mdsc; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2206 | req->r_started = jiffies; |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 2207 | req->r_start_latency = ktime_get(); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2208 | req->r_resend_mds = -1; |
| 2209 | INIT_LIST_HEAD(&req->r_unsafe_dir_item); |
Yan, Zheng | 68cd5b4 | 2015-10-27 18:36:06 +0800 | [diff] [blame] | 2210 | INIT_LIST_HEAD(&req->r_unsafe_target_item); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2211 | req->r_fmode = -1; |
Sage Weil | 153c8e6 | 2009-12-07 12:31:09 -0800 | [diff] [blame] | 2212 | kref_init(&req->r_kref); |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 2213 | RB_CLEAR_NODE(&req->r_node); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2214 | INIT_LIST_HEAD(&req->r_wait); |
| 2215 | init_completion(&req->r_completion); |
| 2216 | init_completion(&req->r_safe_completion); |
| 2217 | INIT_LIST_HEAD(&req->r_unsafe_item); |
| 2218 | |
Deepa Dinamani | 668c9a6 | 2019-12-02 21:19:42 -0800 | [diff] [blame] | 2219 | ktime_get_coarse_real_ts64(&req->r_stamp); |
Sage Weil | b8e6906 | 2014-05-21 17:41:08 -0700 | [diff] [blame] | 2220 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2221 | req->r_op = op; |
| 2222 | req->r_direct_mode = mode; |
| 2223 | return req; |
| 2224 | } |
| 2225 | |
| 2226 | /* |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2227 | * return oldest (lowest) request, tid in request tree, 0 if none. |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2228 | * |
| 2229 | * called under mdsc->mutex. |
| 2230 | */ |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2231 | static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc) |
| 2232 | { |
| 2233 | if (RB_EMPTY_ROOT(&mdsc->request_tree)) |
| 2234 | return NULL; |
| 2235 | return rb_entry(rb_first(&mdsc->request_tree), |
| 2236 | struct ceph_mds_request, r_node); |
| 2237 | } |
| 2238 | |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 2239 | static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2240 | { |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 2241 | return mdsc->oldest_tid; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | /* |
| 2245 | * Build a dentry's path. Allocate on heap; caller must kfree. Based |
| 2246 | * on build_path_from_dentry in fs/cifs/dir.c. |
| 2247 | * |
| 2248 | * If @stop_on_nosnap, generate path relative to the first non-snapped |
| 2249 | * inode. |
| 2250 | * |
| 2251 | * Encode hidden .snap dirs as a double /, i.e. |
| 2252 | * foo/.snap/bar -> foo//bar |
| 2253 | */ |
Jeff Layton | 69a10fb | 2019-04-26 13:33:39 -0400 | [diff] [blame] | 2254 | char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *pbase, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2255 | int stop_on_nosnap) |
| 2256 | { |
| 2257 | struct dentry *temp; |
| 2258 | char *path; |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2259 | int pos; |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2260 | unsigned seq; |
Jeff Layton | 69a10fb | 2019-04-26 13:33:39 -0400 | [diff] [blame] | 2261 | u64 base; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2262 | |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 2263 | if (!dentry) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2264 | return ERR_PTR(-EINVAL); |
| 2265 | |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2266 | path = __getname(); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 2267 | if (!path) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2268 | return ERR_PTR(-ENOMEM); |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2269 | retry: |
| 2270 | pos = PATH_MAX - 1; |
| 2271 | path[pos] = '\0'; |
| 2272 | |
| 2273 | seq = read_seqbegin(&rename_lock); |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2274 | rcu_read_lock(); |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2275 | temp = dentry; |
| 2276 | for (;;) { |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2277 | struct inode *inode; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2278 | |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2279 | spin_lock(&temp->d_lock); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2280 | inode = d_inode(temp); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2281 | if (inode && ceph_snap(inode) == CEPH_SNAPDIR) { |
Sage Weil | 104648a | 2010-03-18 10:14:30 -0700 | [diff] [blame] | 2282 | dout("build_path path+%d: %p SNAPDIR\n", |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2283 | pos, temp); |
Jeff Layton | d6b8bd6 | 2019-05-09 07:58:38 -0400 | [diff] [blame] | 2284 | } else if (stop_on_nosnap && inode && dentry != temp && |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2285 | ceph_snap(inode) == CEPH_NOSNAP) { |
Yehuda Sadeh | 9d5a09e | 2011-12-13 09:57:44 -0800 | [diff] [blame] | 2286 | spin_unlock(&temp->d_lock); |
Jeff Layton | d6b8bd6 | 2019-05-09 07:58:38 -0400 | [diff] [blame] | 2287 | pos++; /* get rid of any prepended '/' */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2288 | break; |
| 2289 | } else { |
| 2290 | pos -= temp->d_name.len; |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2291 | if (pos < 0) { |
| 2292 | spin_unlock(&temp->d_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2293 | break; |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2294 | } |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2295 | memcpy(path + pos, temp->d_name.name, temp->d_name.len); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2296 | } |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2297 | spin_unlock(&temp->d_lock); |
Yan, Zheng | 41883ba | 2019-05-23 10:22:55 +0800 | [diff] [blame] | 2298 | temp = READ_ONCE(temp->d_parent); |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2299 | |
| 2300 | /* Are we at the root? */ |
| 2301 | if (IS_ROOT(temp)) |
| 2302 | break; |
| 2303 | |
| 2304 | /* Are we out of buffer? */ |
| 2305 | if (--pos < 0) |
| 2306 | break; |
| 2307 | |
| 2308 | path[pos] = '/'; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2309 | } |
Jeff Layton | 69a10fb | 2019-04-26 13:33:39 -0400 | [diff] [blame] | 2310 | base = ceph_ino(d_inode(temp)); |
Al Viro | 1b71fe2 | 2011-07-16 23:43:58 -0400 | [diff] [blame] | 2311 | rcu_read_unlock(); |
Jeff Layton | f5946bc | 2019-10-16 08:20:17 -0400 | [diff] [blame] | 2312 | |
| 2313 | if (read_seqretry(&rename_lock, seq)) |
| 2314 | goto retry; |
| 2315 | |
| 2316 | if (pos < 0) { |
| 2317 | /* |
| 2318 | * A rename didn't occur, but somehow we didn't end up where |
| 2319 | * we thought we would. Throw a warning and try again. |
| 2320 | */ |
| 2321 | pr_warn("build_path did not end path lookup where " |
| 2322 | "expected, pos is %d\n", pos); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2323 | goto retry; |
| 2324 | } |
| 2325 | |
Jeff Layton | 69a10fb | 2019-04-26 13:33:39 -0400 | [diff] [blame] | 2326 | *pbase = base; |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2327 | *plen = PATH_MAX - 1 - pos; |
Sage Weil | 104648a | 2010-03-18 10:14:30 -0700 | [diff] [blame] | 2328 | dout("build_path on %p %d built %llx '%.*s'\n", |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2329 | dentry, d_count(dentry), base, *plen, path + pos); |
| 2330 | return path + pos; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Jeff Layton | fd36a71 | 2016-12-15 08:37:58 -0500 | [diff] [blame] | 2333 | static int build_dentry_path(struct dentry *dentry, struct inode *dir, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2334 | const char **ppath, int *ppathlen, u64 *pino, |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2335 | bool *pfreepath, bool parent_locked) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2336 | { |
| 2337 | char *path; |
| 2338 | |
Jeff Layton | c6b0b65 | 2016-12-15 08:37:57 -0500 | [diff] [blame] | 2339 | rcu_read_lock(); |
Jeff Layton | fd36a71 | 2016-12-15 08:37:58 -0500 | [diff] [blame] | 2340 | if (!dir) |
| 2341 | dir = d_inode_rcu(dentry->d_parent); |
Jeff Layton | 964fff7 | 2019-04-29 11:51:02 -0400 | [diff] [blame] | 2342 | if (dir && parent_locked && ceph_snap(dir) == CEPH_NOSNAP) { |
Jeff Layton | c6b0b65 | 2016-12-15 08:37:57 -0500 | [diff] [blame] | 2343 | *pino = ceph_ino(dir); |
| 2344 | rcu_read_unlock(); |
Jeff Layton | 964fff7 | 2019-04-29 11:51:02 -0400 | [diff] [blame] | 2345 | *ppath = dentry->d_name.name; |
| 2346 | *ppathlen = dentry->d_name.len; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2347 | return 0; |
| 2348 | } |
Jeff Layton | c6b0b65 | 2016-12-15 08:37:57 -0500 | [diff] [blame] | 2349 | rcu_read_unlock(); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2350 | path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1); |
| 2351 | if (IS_ERR(path)) |
| 2352 | return PTR_ERR(path); |
| 2353 | *ppath = path; |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2354 | *pfreepath = true; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2355 | return 0; |
| 2356 | } |
| 2357 | |
| 2358 | static int build_inode_path(struct inode *inode, |
| 2359 | const char **ppath, int *ppathlen, u64 *pino, |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2360 | bool *pfreepath) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2361 | { |
| 2362 | struct dentry *dentry; |
| 2363 | char *path; |
| 2364 | |
| 2365 | if (ceph_snap(inode) == CEPH_NOSNAP) { |
| 2366 | *pino = ceph_ino(inode); |
| 2367 | *ppathlen = 0; |
| 2368 | return 0; |
| 2369 | } |
| 2370 | dentry = d_find_alias(inode); |
| 2371 | path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1); |
| 2372 | dput(dentry); |
| 2373 | if (IS_ERR(path)) |
| 2374 | return PTR_ERR(path); |
| 2375 | *ppath = path; |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2376 | *pfreepath = true; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2377 | return 0; |
| 2378 | } |
| 2379 | |
| 2380 | /* |
| 2381 | * request arguments may be specified via an inode *, a dentry *, or |
| 2382 | * an explicit ino+path. |
| 2383 | */ |
| 2384 | static int set_request_path_attr(struct inode *rinode, struct dentry *rdentry, |
Jeff Layton | fd36a71 | 2016-12-15 08:37:58 -0500 | [diff] [blame] | 2385 | struct inode *rdiri, const char *rpath, |
| 2386 | u64 rino, const char **ppath, int *pathlen, |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2387 | u64 *ino, bool *freepath, bool parent_locked) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2388 | { |
| 2389 | int r = 0; |
| 2390 | |
| 2391 | if (rinode) { |
| 2392 | r = build_inode_path(rinode, ppath, pathlen, ino, freepath); |
| 2393 | dout(" inode %p %llx.%llx\n", rinode, ceph_ino(rinode), |
| 2394 | ceph_snap(rinode)); |
| 2395 | } else if (rdentry) { |
Jeff Layton | fd36a71 | 2016-12-15 08:37:58 -0500 | [diff] [blame] | 2396 | r = build_dentry_path(rdentry, rdiri, ppath, pathlen, ino, |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2397 | freepath, parent_locked); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2398 | dout(" dentry %p %llx/%.*s\n", rdentry, *ino, *pathlen, |
| 2399 | *ppath); |
Sage Weil | 795858d | 2011-08-15 13:02:37 -0700 | [diff] [blame] | 2400 | } else if (rpath || rino) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2401 | *ino = rino; |
| 2402 | *ppath = rpath; |
David Zafman | b000056 | 2012-10-25 10:23:46 -0700 | [diff] [blame] | 2403 | *pathlen = rpath ? strlen(rpath) : 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2404 | dout(" path %.*s\n", *pathlen, rpath); |
| 2405 | } |
| 2406 | |
| 2407 | return r; |
| 2408 | } |
| 2409 | |
| 2410 | /* |
| 2411 | * called under mdsc->mutex |
| 2412 | */ |
| 2413 | static struct ceph_msg *create_request_message(struct ceph_mds_client *mdsc, |
| 2414 | struct ceph_mds_request *req, |
Yan, Zheng | 6e6f092 | 2015-02-27 08:54:08 +0800 | [diff] [blame] | 2415 | int mds, bool drop_cap_releases) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2416 | { |
| 2417 | struct ceph_msg *msg; |
| 2418 | struct ceph_mds_request_head *head; |
| 2419 | const char *path1 = NULL; |
| 2420 | const char *path2 = NULL; |
| 2421 | u64 ino1 = 0, ino2 = 0; |
| 2422 | int pathlen1 = 0, pathlen2 = 0; |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2423 | bool freepath1 = false, freepath2 = false; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2424 | int len; |
| 2425 | u16 releases; |
| 2426 | void *p, *end; |
| 2427 | int ret; |
| 2428 | |
| 2429 | ret = set_request_path_attr(req->r_inode, req->r_dentry, |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 2430 | req->r_parent, req->r_path1, req->r_ino1.ino, |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2431 | &path1, &pathlen1, &ino1, &freepath1, |
| 2432 | test_bit(CEPH_MDS_R_PARENT_LOCKED, |
| 2433 | &req->r_req_flags)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2434 | if (ret < 0) { |
| 2435 | msg = ERR_PTR(ret); |
| 2436 | goto out; |
| 2437 | } |
| 2438 | |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2439 | /* If r_old_dentry is set, then assume that its parent is locked */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2440 | ret = set_request_path_attr(NULL, req->r_old_dentry, |
Jeff Layton | fd36a71 | 2016-12-15 08:37:58 -0500 | [diff] [blame] | 2441 | req->r_old_dentry_dir, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2442 | req->r_path2, req->r_ino2.ino, |
Jeff Layton | 1bcb344 | 2019-04-15 12:00:42 -0400 | [diff] [blame] | 2443 | &path2, &pathlen2, &ino2, &freepath2, true); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2444 | if (ret < 0) { |
| 2445 | msg = ERR_PTR(ret); |
| 2446 | goto out_free1; |
| 2447 | } |
| 2448 | |
| 2449 | len = sizeof(*head) + |
Sage Weil | b8e6906 | 2014-05-21 17:41:08 -0700 | [diff] [blame] | 2450 | pathlen1 + pathlen2 + 2*(1 + sizeof(u32) + sizeof(u64)) + |
Arnd Bergmann | 777d738 | 2015-09-30 15:04:42 +0200 | [diff] [blame] | 2451 | sizeof(struct ceph_timespec); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2452 | |
| 2453 | /* calculate (max) length for cap releases */ |
| 2454 | len += sizeof(struct ceph_mds_request_release) * |
| 2455 | (!!req->r_inode_drop + !!req->r_dentry_drop + |
| 2456 | !!req->r_old_inode_drop + !!req->r_old_dentry_drop); |
| 2457 | if (req->r_dentry_drop) |
Jeff Layton | c1dfc27 | 2019-04-17 14:23:17 -0400 | [diff] [blame] | 2458 | len += pathlen1; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2459 | if (req->r_old_dentry_drop) |
Jeff Layton | c1dfc27 | 2019-04-17 14:23:17 -0400 | [diff] [blame] | 2460 | len += pathlen2; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2461 | |
Ilya Dryomov | 0d9c1ab | 2018-10-15 17:38:23 +0200 | [diff] [blame] | 2462 | msg = ceph_msg_new2(CEPH_MSG_CLIENT_REQUEST, len, 1, GFP_NOFS, false); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 2463 | if (!msg) { |
| 2464 | msg = ERR_PTR(-ENOMEM); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2465 | goto out_free2; |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 2466 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2467 | |
John Spray | 7cfa031 | 2014-10-30 17:15:26 +0000 | [diff] [blame] | 2468 | msg->hdr.version = cpu_to_le16(2); |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 2469 | msg->hdr.tid = cpu_to_le64(req->r_tid); |
| 2470 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2471 | head = msg->front.iov_base; |
| 2472 | p = msg->front.iov_base + sizeof(*head); |
| 2473 | end = msg->front.iov_base + msg->front.iov_len; |
| 2474 | |
| 2475 | head->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch); |
| 2476 | head->op = cpu_to_le32(req->r_op); |
Eric W. Biederman | ff3d004 | 2013-01-31 04:01:53 -0800 | [diff] [blame] | 2477 | head->caller_uid = cpu_to_le32(from_kuid(&init_user_ns, req->r_uid)); |
| 2478 | head->caller_gid = cpu_to_le32(from_kgid(&init_user_ns, req->r_gid)); |
Jeff Layton | 6deb800 | 2020-01-13 13:04:08 -0500 | [diff] [blame] | 2479 | head->ino = cpu_to_le64(req->r_deleg_ino); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2480 | head->args = req->r_args; |
| 2481 | |
| 2482 | ceph_encode_filepath(&p, end, ino1, path1); |
| 2483 | ceph_encode_filepath(&p, end, ino2, path2); |
| 2484 | |
Sage Weil | e979cf5 | 2010-07-15 14:58:39 -0700 | [diff] [blame] | 2485 | /* make note of release offset, in case we need to replay */ |
| 2486 | req->r_request_release_offset = p - msg->front.iov_base; |
| 2487 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2488 | /* cap releases */ |
| 2489 | releases = 0; |
| 2490 | if (req->r_inode_drop) |
| 2491 | releases += ceph_encode_inode_release(&p, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2492 | req->r_inode ? req->r_inode : d_inode(req->r_dentry), |
Yan, Zheng | 719a251 | 2020-03-05 20:21:00 +0800 | [diff] [blame] | 2493 | mds, req->r_inode_drop, req->r_inode_unless, |
| 2494 | req->r_op == CEPH_MDS_OP_READDIR); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2495 | if (req->r_dentry_drop) |
| 2496 | releases += ceph_encode_dentry_release(&p, req->r_dentry, |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 2497 | req->r_parent, mds, req->r_dentry_drop, |
Jeff Layton | ca6c8ae | 2016-12-15 08:37:59 -0500 | [diff] [blame] | 2498 | req->r_dentry_unless); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2499 | if (req->r_old_dentry_drop) |
| 2500 | releases += ceph_encode_dentry_release(&p, req->r_old_dentry, |
Jeff Layton | ca6c8ae | 2016-12-15 08:37:59 -0500 | [diff] [blame] | 2501 | req->r_old_dentry_dir, mds, |
| 2502 | req->r_old_dentry_drop, |
| 2503 | req->r_old_dentry_unless); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2504 | if (req->r_old_inode_drop) |
| 2505 | releases += ceph_encode_inode_release(&p, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 2506 | d_inode(req->r_old_dentry), |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2507 | mds, req->r_old_inode_drop, req->r_old_inode_unless, 0); |
Yan, Zheng | 6e6f092 | 2015-02-27 08:54:08 +0800 | [diff] [blame] | 2508 | |
| 2509 | if (drop_cap_releases) { |
| 2510 | releases = 0; |
| 2511 | p = msg->front.iov_base + req->r_request_release_offset; |
| 2512 | } |
| 2513 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2514 | head->num_releases = cpu_to_le16(releases); |
| 2515 | |
Sage Weil | b8e6906 | 2014-05-21 17:41:08 -0700 | [diff] [blame] | 2516 | /* time stamp */ |
Yan, Zheng | 1f041a8 | 2015-01-13 15:20:52 +0800 | [diff] [blame] | 2517 | { |
| 2518 | struct ceph_timespec ts; |
Arnd Bergmann | 0ed1e90 | 2018-07-13 22:18:38 +0200 | [diff] [blame] | 2519 | ceph_encode_timespec64(&ts, &req->r_stamp); |
Yan, Zheng | 1f041a8 | 2015-01-13 15:20:52 +0800 | [diff] [blame] | 2520 | ceph_encode_copy(&p, &ts, sizeof(ts)); |
| 2521 | } |
Sage Weil | b8e6906 | 2014-05-21 17:41:08 -0700 | [diff] [blame] | 2522 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2523 | BUG_ON(p > end); |
| 2524 | msg->front.iov_len = p - msg->front.iov_base; |
| 2525 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
| 2526 | |
Yan, Zheng | 25e6bae | 2014-09-16 19:15:28 +0800 | [diff] [blame] | 2527 | if (req->r_pagelist) { |
| 2528 | struct ceph_pagelist *pagelist = req->r_pagelist; |
Yan, Zheng | 25e6bae | 2014-09-16 19:15:28 +0800 | [diff] [blame] | 2529 | ceph_msg_data_add_pagelist(msg, pagelist); |
| 2530 | msg->hdr.data_len = cpu_to_le32(pagelist->length); |
| 2531 | } else { |
| 2532 | msg->hdr.data_len = 0; |
Alex Elder | ebf18f4 | 2013-03-04 22:29:57 -0600 | [diff] [blame] | 2533 | } |
Alex Elder | 02afca6 | 2013-02-14 12:16:43 -0600 | [diff] [blame] | 2534 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2535 | msg->hdr.data_off = cpu_to_le16(0); |
| 2536 | |
| 2537 | out_free2: |
| 2538 | if (freepath2) |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2539 | ceph_mdsc_free_path((char *)path2, pathlen2); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2540 | out_free1: |
| 2541 | if (freepath1) |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 2542 | ceph_mdsc_free_path((char *)path1, pathlen1); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2543 | out: |
| 2544 | return msg; |
| 2545 | } |
| 2546 | |
| 2547 | /* |
| 2548 | * called under mdsc->mutex if error, under no mutex if |
| 2549 | * success. |
| 2550 | */ |
| 2551 | static void complete_request(struct ceph_mds_client *mdsc, |
| 2552 | struct ceph_mds_request *req) |
| 2553 | { |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 2554 | req->r_end_latency = ktime_get(); |
| 2555 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2556 | if (req->r_callback) |
| 2557 | req->r_callback(mdsc, req); |
Jeff Layton | 111c708 | 2019-04-02 09:43:18 -0400 | [diff] [blame] | 2558 | complete_all(&req->r_completion); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | /* |
| 2562 | * called under mdsc->mutex |
| 2563 | */ |
| 2564 | static int __prepare_send_request(struct ceph_mds_client *mdsc, |
| 2565 | struct ceph_mds_request *req, |
Yan, Zheng | 6e6f092 | 2015-02-27 08:54:08 +0800 | [diff] [blame] | 2566 | int mds, bool drop_cap_releases) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2567 | { |
| 2568 | struct ceph_mds_request_head *rhead; |
| 2569 | struct ceph_msg *msg; |
| 2570 | int flags = 0; |
| 2571 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2572 | req->r_attempts++; |
Greg Farnum | e55b71f | 2010-06-22 15:58:01 -0700 | [diff] [blame] | 2573 | if (req->r_inode) { |
| 2574 | struct ceph_cap *cap = |
| 2575 | ceph_get_cap_for_mds(ceph_inode(req->r_inode), mds); |
| 2576 | |
| 2577 | if (cap) |
| 2578 | req->r_sent_on_mseq = cap->mseq; |
| 2579 | else |
| 2580 | req->r_sent_on_mseq = -1; |
| 2581 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2582 | dout("prepare_send_request %p tid %lld %s (attempt %d)\n", req, |
| 2583 | req->r_tid, ceph_mds_op_name(req->r_op), req->r_attempts); |
| 2584 | |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 2585 | if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) { |
Yan, Zheng | c5c9a0b | 2014-07-01 16:54:34 +0800 | [diff] [blame] | 2586 | void *p; |
Sage Weil | 01a92f1 | 2010-07-15 13:24:32 -0700 | [diff] [blame] | 2587 | /* |
| 2588 | * Replay. Do not regenerate message (and rebuild |
| 2589 | * paths, etc.); just use the original message. |
| 2590 | * Rebuilding paths will break for renames because |
| 2591 | * d_move mangles the src name. |
| 2592 | */ |
| 2593 | msg = req->r_request; |
| 2594 | rhead = msg->front.iov_base; |
| 2595 | |
| 2596 | flags = le32_to_cpu(rhead->flags); |
| 2597 | flags |= CEPH_MDS_FLAG_REPLAY; |
| 2598 | rhead->flags = cpu_to_le32(flags); |
| 2599 | |
| 2600 | if (req->r_target_inode) |
| 2601 | rhead->ino = cpu_to_le64(ceph_ino(req->r_target_inode)); |
| 2602 | |
| 2603 | rhead->num_retry = req->r_attempts - 1; |
Sage Weil | e979cf5 | 2010-07-15 14:58:39 -0700 | [diff] [blame] | 2604 | |
| 2605 | /* remove cap/dentry releases from message */ |
| 2606 | rhead->num_releases = 0; |
Yan, Zheng | c5c9a0b | 2014-07-01 16:54:34 +0800 | [diff] [blame] | 2607 | |
| 2608 | /* time stamp */ |
| 2609 | p = msg->front.iov_base + req->r_request_release_offset; |
Yan, Zheng | 1f041a8 | 2015-01-13 15:20:52 +0800 | [diff] [blame] | 2610 | { |
| 2611 | struct ceph_timespec ts; |
Arnd Bergmann | 0ed1e90 | 2018-07-13 22:18:38 +0200 | [diff] [blame] | 2612 | ceph_encode_timespec64(&ts, &req->r_stamp); |
Yan, Zheng | 1f041a8 | 2015-01-13 15:20:52 +0800 | [diff] [blame] | 2613 | ceph_encode_copy(&p, &ts, sizeof(ts)); |
| 2614 | } |
Yan, Zheng | c5c9a0b | 2014-07-01 16:54:34 +0800 | [diff] [blame] | 2615 | |
| 2616 | msg->front.iov_len = p - msg->front.iov_base; |
| 2617 | msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); |
Sage Weil | 01a92f1 | 2010-07-15 13:24:32 -0700 | [diff] [blame] | 2618 | return 0; |
| 2619 | } |
| 2620 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2621 | if (req->r_request) { |
| 2622 | ceph_msg_put(req->r_request); |
| 2623 | req->r_request = NULL; |
| 2624 | } |
Yan, Zheng | 6e6f092 | 2015-02-27 08:54:08 +0800 | [diff] [blame] | 2625 | msg = create_request_message(mdsc, req, mds, drop_cap_releases); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2626 | if (IS_ERR(msg)) { |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2627 | req->r_err = PTR_ERR(msg); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 2628 | return PTR_ERR(msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2629 | } |
| 2630 | req->r_request = msg; |
| 2631 | |
| 2632 | rhead = msg->front.iov_base; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2633 | rhead->oldest_client_tid = cpu_to_le64(__get_oldest_tid(mdsc)); |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 2634 | if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2635 | flags |= CEPH_MDS_FLAG_REPLAY; |
Jeff Layton | 3bb48b4 | 2019-12-02 13:47:57 -0500 | [diff] [blame] | 2636 | if (test_bit(CEPH_MDS_R_ASYNC, &req->r_req_flags)) |
| 2637 | flags |= CEPH_MDS_FLAG_ASYNC; |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 2638 | if (req->r_parent) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2639 | flags |= CEPH_MDS_FLAG_WANT_DENTRY; |
| 2640 | rhead->flags = cpu_to_le32(flags); |
| 2641 | rhead->num_fwd = req->r_num_fwd; |
| 2642 | rhead->num_retry = req->r_attempts - 1; |
| 2643 | |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 2644 | dout(" r_parent = %p\n", req->r_parent); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2645 | return 0; |
| 2646 | } |
| 2647 | |
| 2648 | /* |
Xiubo Li | 9cf5456 | 2019-12-05 20:50:21 -0500 | [diff] [blame] | 2649 | * called under mdsc->mutex |
| 2650 | */ |
| 2651 | static int __send_request(struct ceph_mds_client *mdsc, |
| 2652 | struct ceph_mds_session *session, |
| 2653 | struct ceph_mds_request *req, |
| 2654 | bool drop_cap_releases) |
| 2655 | { |
| 2656 | int err; |
| 2657 | |
| 2658 | err = __prepare_send_request(mdsc, req, session->s_mds, |
| 2659 | drop_cap_releases); |
| 2660 | if (!err) { |
| 2661 | ceph_msg_get(req->r_request); |
| 2662 | ceph_con_send(&session->s_con, req->r_request); |
| 2663 | } |
| 2664 | |
| 2665 | return err; |
| 2666 | } |
| 2667 | |
| 2668 | /* |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2669 | * send request, or put it on the appropriate wait list. |
| 2670 | */ |
Chengguang Xu | d554849 | 2018-07-28 16:30:48 +0800 | [diff] [blame] | 2671 | static void __do_request(struct ceph_mds_client *mdsc, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2672 | struct ceph_mds_request *req) |
| 2673 | { |
| 2674 | struct ceph_mds_session *session = NULL; |
| 2675 | int mds = -1; |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 2676 | int err = 0; |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 2677 | bool random; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2678 | |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 2679 | if (req->r_err || test_bit(CEPH_MDS_R_GOT_RESULT, &req->r_req_flags)) { |
| 2680 | if (test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) |
Yan, Zheng | eb1b8af | 2013-09-26 14:25:36 +0800 | [diff] [blame] | 2681 | __unregister_request(mdsc, req); |
Chengguang Xu | d554849 | 2018-07-28 16:30:48 +0800 | [diff] [blame] | 2682 | return; |
Yan, Zheng | eb1b8af | 2013-09-26 14:25:36 +0800 | [diff] [blame] | 2683 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2684 | |
| 2685 | if (req->r_timeout && |
| 2686 | time_after_eq(jiffies, req->r_started + req->r_timeout)) { |
| 2687 | dout("do_request timed out\n"); |
Xiubo Li | 8ccf7fc | 2020-02-23 22:23:11 -0500 | [diff] [blame] | 2688 | err = -ETIMEDOUT; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2689 | goto finish; |
| 2690 | } |
Seraphime Kirkovski | 52953d5 | 2016-12-26 10:26:34 +0100 | [diff] [blame] | 2691 | if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 2692 | dout("do_request forced umount\n"); |
| 2693 | err = -EIO; |
| 2694 | goto finish; |
| 2695 | } |
Seraphime Kirkovski | 52953d5 | 2016-12-26 10:26:34 +0100 | [diff] [blame] | 2696 | if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_MOUNTING) { |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 2697 | if (mdsc->mdsmap_err) { |
| 2698 | err = mdsc->mdsmap_err; |
| 2699 | dout("do_request mdsmap err %d\n", err); |
| 2700 | goto finish; |
| 2701 | } |
Yan, Zheng | cc8e834 | 2017-01-04 16:21:58 +0800 | [diff] [blame] | 2702 | if (mdsc->mdsmap->m_epoch == 0) { |
| 2703 | dout("do_request no mdsmap, waiting for map\n"); |
| 2704 | list_add(&req->r_wait, &mdsc->waiting_for_map); |
Chengguang Xu | d554849 | 2018-07-28 16:30:48 +0800 | [diff] [blame] | 2705 | return; |
Yan, Zheng | cc8e834 | 2017-01-04 16:21:58 +0800 | [diff] [blame] | 2706 | } |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 2707 | if (!(mdsc->fsc->mount_options->flags & |
| 2708 | CEPH_MOUNT_OPT_MOUNTWAIT) && |
| 2709 | !ceph_mdsmap_is_cluster_available(mdsc->mdsmap)) { |
Xiubo Li | 9782005 | 2019-12-10 20:29:40 -0500 | [diff] [blame] | 2710 | err = -EHOSTUNREACH; |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 2711 | goto finish; |
| 2712 | } |
| 2713 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2714 | |
Sage Weil | dc69e2e | 2010-11-02 13:49:00 -0700 | [diff] [blame] | 2715 | put_request_session(req); |
| 2716 | |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 2717 | mds = __choose_mds(mdsc, req, &random); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2718 | if (mds < 0 || |
| 2719 | ceph_mdsmap_get_state(mdsc->mdsmap, mds) < CEPH_MDS_STATE_ACTIVE) { |
Jeff Layton | 3bb48b4 | 2019-12-02 13:47:57 -0500 | [diff] [blame] | 2720 | if (test_bit(CEPH_MDS_R_ASYNC, &req->r_req_flags)) { |
| 2721 | err = -EJUKEBOX; |
| 2722 | goto finish; |
| 2723 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2724 | dout("do_request no mds or not active, waiting for map\n"); |
| 2725 | list_add(&req->r_wait, &mdsc->waiting_for_map); |
Chengguang Xu | d554849 | 2018-07-28 16:30:48 +0800 | [diff] [blame] | 2726 | return; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | /* get, open session */ |
| 2730 | session = __ceph_lookup_mds_session(mdsc, mds); |
Sage Weil | 9c423956 | 2010-03-20 20:43:28 -0700 | [diff] [blame] | 2731 | if (!session) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2732 | session = register_session(mdsc, mds); |
Sage Weil | 9c423956 | 2010-03-20 20:43:28 -0700 | [diff] [blame] | 2733 | if (IS_ERR(session)) { |
| 2734 | err = PTR_ERR(session); |
| 2735 | goto finish; |
| 2736 | } |
| 2737 | } |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 2738 | req->r_session = ceph_get_mds_session(session); |
Sage Weil | dc69e2e | 2010-11-02 13:49:00 -0700 | [diff] [blame] | 2739 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2740 | dout("do_request mds%d session %p state %s\n", mds, session, |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 2741 | ceph_session_state_name(session->s_state)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2742 | if (session->s_state != CEPH_MDS_SESSION_OPEN && |
| 2743 | session->s_state != CEPH_MDS_SESSION_HUNG) { |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 2744 | if (session->s_state == CEPH_MDS_SESSION_REJECTED) { |
| 2745 | err = -EACCES; |
| 2746 | goto out_session; |
| 2747 | } |
Jeff Layton | 3bb48b4 | 2019-12-02 13:47:57 -0500 | [diff] [blame] | 2748 | /* |
| 2749 | * We cannot queue async requests since the caps and delegated |
| 2750 | * inodes are bound to the session. Just return -EJUKEBOX and |
| 2751 | * let the caller retry a sync request in that case. |
| 2752 | */ |
| 2753 | if (test_bit(CEPH_MDS_R_ASYNC, &req->r_req_flags)) { |
| 2754 | err = -EJUKEBOX; |
| 2755 | goto out_session; |
| 2756 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2757 | if (session->s_state == CEPH_MDS_SESSION_NEW || |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 2758 | session->s_state == CEPH_MDS_SESSION_CLOSING) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2759 | __open_session(mdsc, session); |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 2760 | /* retry the same mds later */ |
| 2761 | if (random) |
| 2762 | req->r_resend_mds = mds; |
| 2763 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2764 | list_add(&req->r_wait, &session->s_waiting); |
| 2765 | goto out_session; |
| 2766 | } |
| 2767 | |
| 2768 | /* send request */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2769 | req->r_resend_mds = -1; /* forget any previous mds hint */ |
| 2770 | |
| 2771 | if (req->r_request_started == 0) /* note request start time */ |
| 2772 | req->r_request_started = jiffies; |
| 2773 | |
Xiubo Li | 9cf5456 | 2019-12-05 20:50:21 -0500 | [diff] [blame] | 2774 | err = __send_request(mdsc, session, req, false); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2775 | |
| 2776 | out_session: |
| 2777 | ceph_put_mds_session(session); |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 2778 | finish: |
| 2779 | if (err) { |
| 2780 | dout("__do_request early error %d\n", err); |
| 2781 | req->r_err = err; |
| 2782 | complete_request(mdsc, req); |
| 2783 | __unregister_request(mdsc, req); |
| 2784 | } |
Chengguang Xu | d554849 | 2018-07-28 16:30:48 +0800 | [diff] [blame] | 2785 | return; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | /* |
| 2789 | * called under mdsc->mutex |
| 2790 | */ |
| 2791 | static void __wake_requests(struct ceph_mds_client *mdsc, |
| 2792 | struct list_head *head) |
| 2793 | { |
Yan, Zheng | ed75ec2 | 2012-11-19 10:49:06 +0800 | [diff] [blame] | 2794 | struct ceph_mds_request *req; |
| 2795 | LIST_HEAD(tmp_list); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2796 | |
Yan, Zheng | ed75ec2 | 2012-11-19 10:49:06 +0800 | [diff] [blame] | 2797 | list_splice_init(head, &tmp_list); |
| 2798 | |
| 2799 | while (!list_empty(&tmp_list)) { |
| 2800 | req = list_entry(tmp_list.next, |
| 2801 | struct ceph_mds_request, r_wait); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2802 | list_del_init(&req->r_wait); |
Sage Weil | 7971bd9 | 2013-05-01 21:15:58 -0700 | [diff] [blame] | 2803 | dout(" wake request %p tid %llu\n", req, req->r_tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2804 | __do_request(mdsc, req); |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | /* |
| 2809 | * Wake up threads with requests pending for @mds, so that they can |
Sage Weil | 29790f2 | 2010-03-18 14:45:05 -0700 | [diff] [blame] | 2810 | * resubmit their requests to a possibly different mds. |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2811 | */ |
Sage Weil | 29790f2 | 2010-03-18 14:45:05 -0700 | [diff] [blame] | 2812 | static void kick_requests(struct ceph_mds_client *mdsc, int mds) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2813 | { |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2814 | struct ceph_mds_request *req; |
Yan, Zheng | 282c105 | 2014-07-30 10:12:47 +0800 | [diff] [blame] | 2815 | struct rb_node *p = rb_first(&mdsc->request_tree); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2816 | |
| 2817 | dout("kick_requests mds%d\n", mds); |
Yan, Zheng | 282c105 | 2014-07-30 10:12:47 +0800 | [diff] [blame] | 2818 | while (p) { |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2819 | req = rb_entry(p, struct ceph_mds_request, r_node); |
Yan, Zheng | 282c105 | 2014-07-30 10:12:47 +0800 | [diff] [blame] | 2820 | p = rb_next(p); |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 2821 | if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2822 | continue; |
Yan, Zheng | 3de22be | 2015-02-04 14:26:22 +0800 | [diff] [blame] | 2823 | if (req->r_attempts > 0) |
| 2824 | continue; /* only new requests */ |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2825 | if (req->r_session && |
| 2826 | req->r_session->s_mds == mds) { |
| 2827 | dout(" kicking tid %llu\n", req->r_tid); |
Yan, Zheng | 03974e8 | 2014-09-11 14:28:56 +0800 | [diff] [blame] | 2828 | list_del_init(&req->r_wait); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 2829 | __do_request(mdsc, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | } |
| 2833 | |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2834 | int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2835 | struct ceph_mds_request *req) |
| 2836 | { |
Jeff Layton | 891f3f5 | 2020-01-14 15:06:40 -0500 | [diff] [blame] | 2837 | int err = 0; |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2838 | |
| 2839 | /* take CAP_PIN refs for r_inode, r_parent, r_old_dentry */ |
| 2840 | if (req->r_inode) |
| 2841 | ceph_get_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN); |
Jeff Layton | 9c1c2b3 | 2019-04-03 13:16:01 -0400 | [diff] [blame] | 2842 | if (req->r_parent) { |
Yan, Zheng | 719a251 | 2020-03-05 20:21:00 +0800 | [diff] [blame] | 2843 | struct ceph_inode_info *ci = ceph_inode(req->r_parent); |
| 2844 | int fmode = (req->r_op & CEPH_MDS_OP_WRITE) ? |
| 2845 | CEPH_FILE_MODE_WR : CEPH_FILE_MODE_RD; |
| 2846 | spin_lock(&ci->i_ceph_lock); |
| 2847 | ceph_take_cap_refs(ci, CEPH_CAP_PIN, false); |
| 2848 | __ceph_touch_fmode(ci, mdsc, fmode); |
| 2849 | spin_unlock(&ci->i_ceph_lock); |
Jeff Layton | 9c1c2b3 | 2019-04-03 13:16:01 -0400 | [diff] [blame] | 2850 | ihold(req->r_parent); |
| 2851 | } |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2852 | if (req->r_old_dentry_dir) |
| 2853 | ceph_get_cap_refs(ceph_inode(req->r_old_dentry_dir), |
| 2854 | CEPH_CAP_PIN); |
| 2855 | |
Jeff Layton | 891f3f5 | 2020-01-14 15:06:40 -0500 | [diff] [blame] | 2856 | if (req->r_inode) { |
| 2857 | err = ceph_wait_on_async_create(req->r_inode); |
| 2858 | if (err) { |
| 2859 | dout("%s: wait for async create returned: %d\n", |
| 2860 | __func__, err); |
| 2861 | return err; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | if (!err && req->r_old_inode) { |
| 2866 | err = ceph_wait_on_async_create(req->r_old_inode); |
| 2867 | if (err) { |
| 2868 | dout("%s: wait for async create returned: %d\n", |
| 2869 | __func__, err); |
| 2870 | return err; |
| 2871 | } |
| 2872 | } |
| 2873 | |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2874 | dout("submit_request on %p for inode %p\n", req, dir); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2875 | mutex_lock(&mdsc->mutex); |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2876 | __register_request(mdsc, req, dir); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2877 | __do_request(mdsc, req); |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2878 | err = req->r_err; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2879 | mutex_unlock(&mdsc->mutex); |
Jeff Layton | 86bda53 | 2019-04-02 09:24:36 -0400 | [diff] [blame] | 2880 | return err; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Jeff Layton | 8340f22 | 2019-04-02 12:34:38 -0400 | [diff] [blame] | 2883 | static int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc, |
| 2884 | struct ceph_mds_request *req) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2885 | { |
| 2886 | int err; |
| 2887 | |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2888 | /* wait */ |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2889 | dout("do_request waiting\n"); |
Ilya Dryomov | 5be7303 | 2015-05-19 12:05:38 +0300 | [diff] [blame] | 2890 | if (!req->r_timeout && req->r_wait_for_completion) { |
Yan, Zheng | 9280be2 | 2014-10-14 10:33:35 +0800 | [diff] [blame] | 2891 | err = req->r_wait_for_completion(mdsc, req); |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2892 | } else { |
Ilya Dryomov | 5be7303 | 2015-05-19 12:05:38 +0300 | [diff] [blame] | 2893 | long timeleft = wait_for_completion_killable_timeout( |
| 2894 | &req->r_completion, |
| 2895 | ceph_timeout_jiffies(req->r_timeout)); |
| 2896 | if (timeleft > 0) |
| 2897 | err = 0; |
| 2898 | else if (!timeleft) |
Xiubo Li | 8ccf7fc | 2020-02-23 22:23:11 -0500 | [diff] [blame] | 2899 | err = -ETIMEDOUT; /* timed out */ |
Ilya Dryomov | 5be7303 | 2015-05-19 12:05:38 +0300 | [diff] [blame] | 2900 | else |
| 2901 | err = timeleft; /* killed */ |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2902 | } |
| 2903 | dout("do_request waited, got %d\n", err); |
| 2904 | mutex_lock(&mdsc->mutex); |
| 2905 | |
| 2906 | /* only abort if we didn't race with a real reply */ |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 2907 | if (test_bit(CEPH_MDS_R_GOT_RESULT, &req->r_req_flags)) { |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2908 | err = le32_to_cpu(req->r_reply_info.head->result); |
| 2909 | } else if (err < 0) { |
| 2910 | dout("aborted request %lld with %d\n", req->r_tid, err); |
Sage Weil | b455639 | 2010-05-13 12:01:13 -0700 | [diff] [blame] | 2911 | |
| 2912 | /* |
| 2913 | * ensure we aren't running concurrently with |
| 2914 | * ceph_fill_trace or ceph_readdir_prepopulate, which |
| 2915 | * rely on locks (dir mutex) held by our caller. |
| 2916 | */ |
| 2917 | mutex_lock(&req->r_fill_mutex); |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2918 | req->r_err = err; |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 2919 | set_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags); |
Sage Weil | b455639 | 2010-05-13 12:01:13 -0700 | [diff] [blame] | 2920 | mutex_unlock(&req->r_fill_mutex); |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2921 | |
Jeff Layton | 3dd69aa | 2017-01-31 10:28:26 -0500 | [diff] [blame] | 2922 | if (req->r_parent && |
Sage Weil | 167c9e3 | 2010-05-14 10:02:57 -0700 | [diff] [blame] | 2923 | (req->r_op & CEPH_MDS_OP_WRITE)) |
| 2924 | ceph_invalidate_dir_request(req); |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2925 | } else { |
| 2926 | err = req->r_err; |
| 2927 | } |
| 2928 | |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 2929 | mutex_unlock(&mdsc->mutex); |
Jeff Layton | 8340f22 | 2019-04-02 12:34:38 -0400 | [diff] [blame] | 2930 | return err; |
| 2931 | } |
| 2932 | |
| 2933 | /* |
| 2934 | * Synchrously perform an mds request. Take care of all of the |
| 2935 | * session setup, forwarding, retry details. |
| 2936 | */ |
| 2937 | int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, |
| 2938 | struct inode *dir, |
| 2939 | struct ceph_mds_request *req) |
| 2940 | { |
| 2941 | int err; |
| 2942 | |
| 2943 | dout("do_request on %p\n", req); |
| 2944 | |
| 2945 | /* issue */ |
| 2946 | err = ceph_mdsc_submit_request(mdsc, dir, req); |
| 2947 | if (!err) |
| 2948 | err = ceph_mdsc_wait_request(mdsc, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2949 | dout("do_request %p done, result %d\n", req, err); |
| 2950 | return err; |
| 2951 | } |
| 2952 | |
| 2953 | /* |
Yan, Zheng | 2f276c5 | 2013-03-13 19:44:32 +0800 | [diff] [blame] | 2954 | * Invalidate dir's completeness, dentry lease state on an aborted MDS |
Sage Weil | 167c9e3 | 2010-05-14 10:02:57 -0700 | [diff] [blame] | 2955 | * namespace request. |
| 2956 | */ |
| 2957 | void ceph_invalidate_dir_request(struct ceph_mds_request *req) |
| 2958 | { |
Yan, Zheng | 8d8f371 | 2017-11-24 11:51:32 +0800 | [diff] [blame] | 2959 | struct inode *dir = req->r_parent; |
| 2960 | struct inode *old_dir = req->r_old_dentry_dir; |
Sage Weil | 167c9e3 | 2010-05-14 10:02:57 -0700 | [diff] [blame] | 2961 | |
Yan, Zheng | 8d8f371 | 2017-11-24 11:51:32 +0800 | [diff] [blame] | 2962 | dout("invalidate_dir_request %p %p (complete, lease(s))\n", dir, old_dir); |
Sage Weil | 167c9e3 | 2010-05-14 10:02:57 -0700 | [diff] [blame] | 2963 | |
Yan, Zheng | 8d8f371 | 2017-11-24 11:51:32 +0800 | [diff] [blame] | 2964 | ceph_dir_clear_complete(dir); |
| 2965 | if (old_dir) |
| 2966 | ceph_dir_clear_complete(old_dir); |
Sage Weil | 167c9e3 | 2010-05-14 10:02:57 -0700 | [diff] [blame] | 2967 | if (req->r_dentry) |
| 2968 | ceph_invalidate_dentry_lease(req->r_dentry); |
| 2969 | if (req->r_old_dentry) |
| 2970 | ceph_invalidate_dentry_lease(req->r_old_dentry); |
| 2971 | } |
| 2972 | |
| 2973 | /* |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2974 | * Handle mds reply. |
| 2975 | * |
| 2976 | * We take the session mutex and parse and process the reply immediately. |
| 2977 | * This preserves the logical ordering of replies, capabilities, etc., sent |
| 2978 | * by the MDS as they are applied to our local cache. |
| 2979 | */ |
| 2980 | static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) |
| 2981 | { |
| 2982 | struct ceph_mds_client *mdsc = session->s_mdsc; |
| 2983 | struct ceph_mds_request *req; |
| 2984 | struct ceph_mds_reply_head *head = msg->front.iov_base; |
| 2985 | struct ceph_mds_reply_info_parsed *rinfo; /* parsed reply info */ |
Yan, Zheng | 982d601 | 2014-12-23 15:30:54 +0800 | [diff] [blame] | 2986 | struct ceph_snap_realm *realm; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2987 | u64 tid; |
| 2988 | int err, result; |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 2989 | int mds = session->s_mds; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2990 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2991 | if (msg->front.iov_len < sizeof(*head)) { |
| 2992 | pr_err("mdsc_handle_reply got corrupt (short) reply\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 2993 | ceph_msg_dump(msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2994 | return; |
| 2995 | } |
| 2996 | |
| 2997 | /* get request, session */ |
Sage Weil | 6df058c | 2009-12-22 11:24:33 -0800 | [diff] [blame] | 2998 | tid = le64_to_cpu(msg->hdr.tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 2999 | mutex_lock(&mdsc->mutex); |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 3000 | req = lookup_get_request(mdsc, tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3001 | if (!req) { |
| 3002 | dout("handle_reply on unknown tid %llu\n", tid); |
| 3003 | mutex_unlock(&mdsc->mutex); |
| 3004 | return; |
| 3005 | } |
| 3006 | dout("handle_reply %p\n", req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3007 | |
| 3008 | /* correct session? */ |
Sage Weil | d96d604 | 2010-03-20 20:50:58 -0700 | [diff] [blame] | 3009 | if (req->r_session != session) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3010 | pr_err("mdsc_handle_reply got %llu on session mds%d" |
| 3011 | " not mds%d\n", tid, session->s_mds, |
| 3012 | req->r_session ? req->r_session->s_mds : -1); |
| 3013 | mutex_unlock(&mdsc->mutex); |
| 3014 | goto out; |
| 3015 | } |
| 3016 | |
| 3017 | /* dup? */ |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3018 | if ((test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags) && !head->safe) || |
| 3019 | (test_bit(CEPH_MDS_R_GOT_SAFE, &req->r_req_flags) && head->safe)) { |
Fabian Frederick | f3ae1b9 | 2014-06-06 14:35:37 -0700 | [diff] [blame] | 3020 | pr_warn("got a dup %s reply on %llu from mds%d\n", |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3021 | head->safe ? "safe" : "unsafe", tid, mds); |
| 3022 | mutex_unlock(&mdsc->mutex); |
| 3023 | goto out; |
| 3024 | } |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3025 | if (test_bit(CEPH_MDS_R_GOT_SAFE, &req->r_req_flags)) { |
Fabian Frederick | f3ae1b9 | 2014-06-06 14:35:37 -0700 | [diff] [blame] | 3026 | pr_warn("got unsafe after safe on %llu from mds%d\n", |
Sage Weil | 85792d0d | 2010-05-13 09:06:02 -0700 | [diff] [blame] | 3027 | tid, mds); |
| 3028 | mutex_unlock(&mdsc->mutex); |
| 3029 | goto out; |
| 3030 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3031 | |
| 3032 | result = le32_to_cpu(head->result); |
| 3033 | |
| 3034 | /* |
Greg Farnum | e55b71f | 2010-06-22 15:58:01 -0700 | [diff] [blame] | 3035 | * Handle an ESTALE |
| 3036 | * if we're not talking to the authority, send to them |
| 3037 | * if the authority has changed while we weren't looking, |
| 3038 | * send to new authority |
| 3039 | * Otherwise we just have to return an ESTALE |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3040 | */ |
| 3041 | if (result == -ESTALE) { |
Chengguang Xu | 4c069a5 | 2018-01-30 16:29:17 +0800 | [diff] [blame] | 3042 | dout("got ESTALE on request %llu\n", req->r_tid); |
Yan, Zheng | 51da8e8 | 2014-07-14 10:48:29 +0800 | [diff] [blame] | 3043 | req->r_resend_mds = -1; |
Yan, Zheng | ca18bed | 2013-11-22 14:21:44 +0800 | [diff] [blame] | 3044 | if (req->r_direct_mode != USE_AUTH_MDS) { |
Chengguang Xu | 4c069a5 | 2018-01-30 16:29:17 +0800 | [diff] [blame] | 3045 | dout("not using auth, setting for that now\n"); |
Greg Farnum | e55b71f | 2010-06-22 15:58:01 -0700 | [diff] [blame] | 3046 | req->r_direct_mode = USE_AUTH_MDS; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3047 | __do_request(mdsc, req); |
| 3048 | mutex_unlock(&mdsc->mutex); |
| 3049 | goto out; |
Greg Farnum | e55b71f | 2010-06-22 15:58:01 -0700 | [diff] [blame] | 3050 | } else { |
Xiubo Li | c4853e9 | 2019-12-09 07:47:15 -0500 | [diff] [blame] | 3051 | int mds = __choose_mds(mdsc, req, NULL); |
Yan, Zheng | ca18bed | 2013-11-22 14:21:44 +0800 | [diff] [blame] | 3052 | if (mds >= 0 && mds != req->r_session->s_mds) { |
Chengguang Xu | 4c069a5 | 2018-01-30 16:29:17 +0800 | [diff] [blame] | 3053 | dout("but auth changed, so resending\n"); |
Greg Farnum | e55b71f | 2010-06-22 15:58:01 -0700 | [diff] [blame] | 3054 | __do_request(mdsc, req); |
| 3055 | mutex_unlock(&mdsc->mutex); |
| 3056 | goto out; |
| 3057 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3058 | } |
Chengguang Xu | 4c069a5 | 2018-01-30 16:29:17 +0800 | [diff] [blame] | 3059 | dout("have to return ESTALE on request %llu\n", req->r_tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
Greg Farnum | e55b71f | 2010-06-22 15:58:01 -0700 | [diff] [blame] | 3062 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3063 | if (head->safe) { |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3064 | set_bit(CEPH_MDS_R_GOT_SAFE, &req->r_req_flags); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3065 | __unregister_request(mdsc, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3066 | |
Xiubo Li | 07edc05 | 2019-12-04 01:27:18 -0500 | [diff] [blame] | 3067 | /* last request during umount? */ |
| 3068 | if (mdsc->stopping && !__get_oldest_req(mdsc)) |
| 3069 | complete_all(&mdsc->safe_umount_waiters); |
| 3070 | |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3071 | if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3072 | /* |
| 3073 | * We already handled the unsafe response, now do the |
| 3074 | * cleanup. No need to examine the response; the MDS |
| 3075 | * doesn't include any result info in the safe |
| 3076 | * response. And even if it did, there is nothing |
| 3077 | * useful we could do with a revised return value. |
| 3078 | */ |
| 3079 | dout("got safe reply %llu, mds%d\n", tid, mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3080 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3081 | mutex_unlock(&mdsc->mutex); |
| 3082 | goto out; |
| 3083 | } |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 3084 | } else { |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3085 | set_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3086 | list_add_tail(&req->r_unsafe_item, &req->r_session->s_unsafe); |
| 3087 | } |
| 3088 | |
| 3089 | dout("handle_reply tid %lld result %d\n", tid, result); |
| 3090 | rinfo = &req->r_reply_info; |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 3091 | if (test_bit(CEPHFS_FEATURE_REPLY_ENCODING, &session->s_features)) |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 3092 | err = parse_reply_info(session, msg, rinfo, (u64)-1); |
Yan, Zheng | b37fe1f | 2019-01-09 10:10:17 +0800 | [diff] [blame] | 3093 | else |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 3094 | err = parse_reply_info(session, msg, rinfo, session->s_con.peer_features); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3095 | mutex_unlock(&mdsc->mutex); |
| 3096 | |
| 3097 | mutex_lock(&session->s_mutex); |
| 3098 | if (err < 0) { |
Herb Shiu | 25933ab | 2010-12-01 14:14:38 -0800 | [diff] [blame] | 3099 | pr_err("mdsc_handle_reply got corrupt reply mds%d(tid:%lld)\n", mds, tid); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 3100 | ceph_msg_dump(msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3101 | goto out_err; |
| 3102 | } |
| 3103 | |
| 3104 | /* snap trace */ |
Yan, Zheng | 982d601 | 2014-12-23 15:30:54 +0800 | [diff] [blame] | 3105 | realm = NULL; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3106 | if (rinfo->snapblob_len) { |
| 3107 | down_write(&mdsc->snap_rwsem); |
| 3108 | ceph_update_snap_trace(mdsc, rinfo->snapblob, |
Yan, Zheng | 982d601 | 2014-12-23 15:30:54 +0800 | [diff] [blame] | 3109 | rinfo->snapblob + rinfo->snapblob_len, |
| 3110 | le32_to_cpu(head->op) == CEPH_MDS_OP_RMSNAP, |
| 3111 | &realm); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3112 | downgrade_write(&mdsc->snap_rwsem); |
| 3113 | } else { |
| 3114 | down_read(&mdsc->snap_rwsem); |
| 3115 | } |
| 3116 | |
| 3117 | /* insert trace into our cache */ |
Sage Weil | b455639 | 2010-05-13 12:01:13 -0700 | [diff] [blame] | 3118 | mutex_lock(&req->r_fill_mutex); |
Yan, Zheng | 315f240 | 2016-03-07 10:34:50 +0800 | [diff] [blame] | 3119 | current->journal_info = req; |
Jeff Layton | f5a03b0 | 2017-01-31 11:06:13 -0500 | [diff] [blame] | 3120 | err = ceph_fill_trace(mdsc->fsc->sb, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3121 | if (err == 0) { |
Sam Lang | 6e8575f | 2012-12-28 09:56:46 -0800 | [diff] [blame] | 3122 | if (result == 0 && (req->r_op == CEPH_MDS_OP_READDIR || |
Yan, Zheng | 81c6aea | 2013-09-18 09:44:13 +0800 | [diff] [blame] | 3123 | req->r_op == CEPH_MDS_OP_LSSNAP)) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3124 | ceph_readdir_prepopulate(req, req->r_session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3125 | } |
Yan, Zheng | 315f240 | 2016-03-07 10:34:50 +0800 | [diff] [blame] | 3126 | current->journal_info = NULL; |
Sage Weil | b455639 | 2010-05-13 12:01:13 -0700 | [diff] [blame] | 3127 | mutex_unlock(&req->r_fill_mutex); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3128 | |
| 3129 | up_read(&mdsc->snap_rwsem); |
Yan, Zheng | 982d601 | 2014-12-23 15:30:54 +0800 | [diff] [blame] | 3130 | if (realm) |
| 3131 | ceph_put_snap_realm(mdsc, realm); |
Yan, Zheng | 68cd5b4 | 2015-10-27 18:36:06 +0800 | [diff] [blame] | 3132 | |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 3133 | if (err == 0) { |
| 3134 | if (req->r_target_inode && |
| 3135 | test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) { |
| 3136 | struct ceph_inode_info *ci = |
| 3137 | ceph_inode(req->r_target_inode); |
| 3138 | spin_lock(&ci->i_unsafe_lock); |
| 3139 | list_add_tail(&req->r_unsafe_target_item, |
| 3140 | &ci->i_unsafe_iops); |
| 3141 | spin_unlock(&ci->i_unsafe_lock); |
| 3142 | } |
| 3143 | |
| 3144 | ceph_unreserve_caps(mdsc, &req->r_caps_reservation); |
Yan, Zheng | 68cd5b4 | 2015-10-27 18:36:06 +0800 | [diff] [blame] | 3145 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3146 | out_err: |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 3147 | mutex_lock(&mdsc->mutex); |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3148 | if (!test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) { |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 3149 | if (err) { |
| 3150 | req->r_err = err; |
| 3151 | } else { |
Jianpeng Ma | 5fdb138 | 2015-08-18 10:30:38 +0800 | [diff] [blame] | 3152 | req->r_reply = ceph_msg_get(msg); |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3153 | set_bit(CEPH_MDS_R_GOT_RESULT, &req->r_req_flags); |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 3154 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3155 | } else { |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 3156 | dout("reply arrived after request %lld was aborted\n", tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3157 | } |
Sage Weil | e1518c7 | 2010-05-13 11:19:06 -0700 | [diff] [blame] | 3158 | mutex_unlock(&mdsc->mutex); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3159 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3160 | mutex_unlock(&session->s_mutex); |
| 3161 | |
| 3162 | /* kick calling process */ |
| 3163 | complete_request(mdsc, req); |
Xiubo Li | 70c9482 | 2020-03-19 23:45:02 -0400 | [diff] [blame] | 3164 | |
| 3165 | ceph_update_metadata_latency(&mdsc->metric, req->r_start_latency, |
| 3166 | req->r_end_latency, err); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3167 | out: |
| 3168 | ceph_mdsc_put_request(req); |
| 3169 | return; |
| 3170 | } |
| 3171 | |
| 3172 | |
| 3173 | |
| 3174 | /* |
| 3175 | * handle mds notification that our request has been forwarded. |
| 3176 | */ |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 3177 | static void handle_forward(struct ceph_mds_client *mdsc, |
| 3178 | struct ceph_mds_session *session, |
| 3179 | struct ceph_msg *msg) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3180 | { |
| 3181 | struct ceph_mds_request *req; |
Sage Weil | a1ea787 | 2010-02-23 14:02:44 -0800 | [diff] [blame] | 3182 | u64 tid = le64_to_cpu(msg->hdr.tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3183 | u32 next_mds; |
| 3184 | u32 fwd_seq; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3185 | int err = -EINVAL; |
| 3186 | void *p = msg->front.iov_base; |
| 3187 | void *end = p + msg->front.iov_len; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3188 | |
Sage Weil | a1ea787 | 2010-02-23 14:02:44 -0800 | [diff] [blame] | 3189 | ceph_decode_need(&p, end, 2*sizeof(u32), bad); |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 3190 | next_mds = ceph_decode_32(&p); |
| 3191 | fwd_seq = ceph_decode_32(&p); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3192 | |
| 3193 | mutex_lock(&mdsc->mutex); |
Ilya Dryomov | fcd00b6 | 2016-04-28 16:07:22 +0200 | [diff] [blame] | 3194 | req = lookup_get_request(mdsc, tid); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3195 | if (!req) { |
Sage Weil | 2a8e5e3 | 2010-05-28 16:43:16 -0700 | [diff] [blame] | 3196 | dout("forward tid %llu to mds%d - req dne\n", tid, next_mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3197 | goto out; /* dup reply? */ |
| 3198 | } |
| 3199 | |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3200 | if (test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) { |
Sage Weil | 2a8e5e3 | 2010-05-28 16:43:16 -0700 | [diff] [blame] | 3201 | dout("forward tid %llu aborted, unregistering\n", tid); |
| 3202 | __unregister_request(mdsc, req); |
| 3203 | } else if (fwd_seq <= req->r_num_fwd) { |
| 3204 | dout("forward tid %llu to mds%d - old seq %d <= %d\n", |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3205 | tid, next_mds, req->r_num_fwd, fwd_seq); |
| 3206 | } else { |
| 3207 | /* resend. forward race not possible; mds would drop */ |
Sage Weil | 2a8e5e3 | 2010-05-28 16:43:16 -0700 | [diff] [blame] | 3208 | dout("forward tid %llu to mds%d (we resend)\n", tid, next_mds); |
| 3209 | BUG_ON(req->r_err); |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3210 | BUG_ON(test_bit(CEPH_MDS_R_GOT_RESULT, &req->r_req_flags)); |
Yan, Zheng | 3de22be | 2015-02-04 14:26:22 +0800 | [diff] [blame] | 3211 | req->r_attempts = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3212 | req->r_num_fwd = fwd_seq; |
| 3213 | req->r_resend_mds = next_mds; |
| 3214 | put_request_session(req); |
| 3215 | __do_request(mdsc, req); |
| 3216 | } |
| 3217 | ceph_mdsc_put_request(req); |
| 3218 | out: |
| 3219 | mutex_unlock(&mdsc->mutex); |
| 3220 | return; |
| 3221 | |
| 3222 | bad: |
| 3223 | pr_err("mdsc_handle_forward decode error err=%d\n", err); |
| 3224 | } |
| 3225 | |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3226 | static int __decode_session_metadata(void **p, void *end, |
| 3227 | bool *blacklisted) |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3228 | { |
| 3229 | /* map<string,string> */ |
| 3230 | u32 n; |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3231 | bool err_str; |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3232 | ceph_decode_32_safe(p, end, n, bad); |
| 3233 | while (n-- > 0) { |
| 3234 | u32 len; |
| 3235 | ceph_decode_32_safe(p, end, len, bad); |
| 3236 | ceph_decode_need(p, end, len, bad); |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3237 | err_str = !strncmp(*p, "error_string", len); |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3238 | *p += len; |
| 3239 | ceph_decode_32_safe(p, end, len, bad); |
| 3240 | ceph_decode_need(p, end, len, bad); |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3241 | if (err_str && strnstr(*p, "blacklisted", len)) |
| 3242 | *blacklisted = true; |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3243 | *p += len; |
| 3244 | } |
| 3245 | return 0; |
| 3246 | bad: |
| 3247 | return -1; |
| 3248 | } |
| 3249 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3250 | /* |
| 3251 | * handle a mds session control message |
| 3252 | */ |
| 3253 | static void handle_session(struct ceph_mds_session *session, |
| 3254 | struct ceph_msg *msg) |
| 3255 | { |
| 3256 | struct ceph_mds_client *mdsc = session->s_mdsc; |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3257 | int mds = session->s_mds; |
| 3258 | int msg_version = le16_to_cpu(msg->hdr.version); |
| 3259 | void *p = msg->front.iov_base; |
| 3260 | void *end = p + msg->front.iov_len; |
| 3261 | struct ceph_mds_session_head *h; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3262 | u32 op; |
Jeff Layton | 0fa8263 | 2020-04-28 08:10:22 -0400 | [diff] [blame] | 3263 | u64 seq, features = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3264 | int wake = 0; |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3265 | bool blacklisted = false; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3266 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3267 | /* decode */ |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3268 | ceph_decode_need(&p, end, sizeof(*h), bad); |
| 3269 | h = p; |
| 3270 | p += sizeof(*h); |
| 3271 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3272 | op = le32_to_cpu(h->op); |
| 3273 | seq = le64_to_cpu(h->seq); |
| 3274 | |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3275 | if (msg_version >= 3) { |
| 3276 | u32 len; |
| 3277 | /* version >= 2, metadata */ |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3278 | if (__decode_session_metadata(&p, end, &blacklisted) < 0) |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3279 | goto bad; |
| 3280 | /* version >= 3, feature bits */ |
| 3281 | ceph_decode_32_safe(&p, end, len, bad); |
Jeff Layton | 0fa8263 | 2020-04-28 08:10:22 -0400 | [diff] [blame] | 3282 | ceph_decode_64_safe(&p, end, features, bad); |
| 3283 | p += len - sizeof(features); |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3284 | } |
| 3285 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3286 | mutex_lock(&mdsc->mutex); |
Yan, Zheng | 0a07fc8 | 2017-03-29 15:30:24 +0800 | [diff] [blame] | 3287 | if (op == CEPH_SESSION_CLOSE) { |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 3288 | ceph_get_mds_session(session); |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 3289 | __unregister_session(mdsc, session); |
Yan, Zheng | 0a07fc8 | 2017-03-29 15:30:24 +0800 | [diff] [blame] | 3290 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3291 | /* FIXME: this ttl calculation is generous */ |
| 3292 | session->s_ttl = jiffies + HZ*mdsc->mdsmap->m_session_autoclose; |
| 3293 | mutex_unlock(&mdsc->mutex); |
| 3294 | |
| 3295 | mutex_lock(&session->s_mutex); |
| 3296 | |
| 3297 | dout("handle_session mds%d %s %p state %s seq %llu\n", |
| 3298 | mds, ceph_session_op_name(op), session, |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 3299 | ceph_session_state_name(session->s_state), seq); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3300 | |
| 3301 | if (session->s_state == CEPH_MDS_SESSION_HUNG) { |
| 3302 | session->s_state = CEPH_MDS_SESSION_OPEN; |
| 3303 | pr_info("mds%d came back\n", session->s_mds); |
| 3304 | } |
| 3305 | |
| 3306 | switch (op) { |
| 3307 | case CEPH_SESSION_OPEN: |
Sage Weil | 29790f2 | 2010-03-18 14:45:05 -0700 | [diff] [blame] | 3308 | if (session->s_state == CEPH_MDS_SESSION_RECONNECTING) |
| 3309 | pr_info("mds%d reconnect success\n", session->s_mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3310 | session->s_state = CEPH_MDS_SESSION_OPEN; |
Yan, Zheng | 84bf395 | 2018-12-21 17:41:39 +0800 | [diff] [blame] | 3311 | session->s_features = features; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3312 | renewed_caps(mdsc, session, 0); |
| 3313 | wake = 1; |
| 3314 | if (mdsc->stopping) |
| 3315 | __close_session(mdsc, session); |
| 3316 | break; |
| 3317 | |
| 3318 | case CEPH_SESSION_RENEWCAPS: |
| 3319 | if (session->s_renew_seq == seq) |
| 3320 | renewed_caps(mdsc, session, 1); |
| 3321 | break; |
| 3322 | |
| 3323 | case CEPH_SESSION_CLOSE: |
Sage Weil | 29790f2 | 2010-03-18 14:45:05 -0700 | [diff] [blame] | 3324 | if (session->s_state == CEPH_MDS_SESSION_RECONNECTING) |
| 3325 | pr_info("mds%d reconnect denied\n", session->s_mds); |
Xiubo Li | 4d681c2 | 2019-12-05 22:35:51 -0500 | [diff] [blame] | 3326 | session->s_state = CEPH_MDS_SESSION_CLOSED; |
Yan, Zheng | 1c841a9 | 2015-03-24 20:15:36 +0800 | [diff] [blame] | 3327 | cleanup_session_requests(mdsc, session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3328 | remove_session_caps(session); |
Yan, Zheng | 656e438 | 2014-09-11 14:25:18 +0800 | [diff] [blame] | 3329 | wake = 2; /* for good measure */ |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 3330 | wake_up_all(&mdsc->session_close_wq); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3331 | break; |
| 3332 | |
| 3333 | case CEPH_SESSION_STALE: |
| 3334 | pr_info("mds%d caps went stale, renewing\n", |
| 3335 | session->s_mds); |
Alex Elder | d8fb02a | 2012-01-12 17:48:10 -0800 | [diff] [blame] | 3336 | spin_lock(&session->s_gen_ttl_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3337 | session->s_cap_gen++; |
Alex Elder | 1ce208a | 2012-01-12 17:48:11 -0800 | [diff] [blame] | 3338 | session->s_cap_ttl = jiffies - 1; |
Alex Elder | d8fb02a | 2012-01-12 17:48:10 -0800 | [diff] [blame] | 3339 | spin_unlock(&session->s_gen_ttl_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3340 | send_renew_caps(mdsc, session); |
| 3341 | break; |
| 3342 | |
| 3343 | case CEPH_SESSION_RECALL_STATE: |
Zhi Zhang | e30ee58 | 2018-01-24 21:24:33 +0800 | [diff] [blame] | 3344 | ceph_trim_caps(mdsc, session, le32_to_cpu(h->max_caps)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3345 | break; |
| 3346 | |
Yan, Zheng | 186e4f7 | 2013-11-22 14:48:37 +0800 | [diff] [blame] | 3347 | case CEPH_SESSION_FLUSHMSG: |
| 3348 | send_flushmsg_ack(mdsc, session, seq); |
| 3349 | break; |
| 3350 | |
Yan, Zheng | 03f4fcb | 2015-01-05 11:04:04 +0800 | [diff] [blame] | 3351 | case CEPH_SESSION_FORCE_RO: |
| 3352 | dout("force_session_readonly %p\n", session); |
| 3353 | spin_lock(&session->s_cap_lock); |
| 3354 | session->s_readonly = true; |
| 3355 | spin_unlock(&session->s_cap_lock); |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 3356 | wake_up_session_caps(session, FORCE_RO); |
Yan, Zheng | 03f4fcb | 2015-01-05 11:04:04 +0800 | [diff] [blame] | 3357 | break; |
| 3358 | |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 3359 | case CEPH_SESSION_REJECT: |
| 3360 | WARN_ON(session->s_state != CEPH_MDS_SESSION_OPENING); |
| 3361 | pr_info("mds%d rejected session\n", session->s_mds); |
| 3362 | session->s_state = CEPH_MDS_SESSION_REJECTED; |
| 3363 | cleanup_session_requests(mdsc, session); |
| 3364 | remove_session_caps(session); |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 3365 | if (blacklisted) |
| 3366 | mdsc->fsc->blacklisted = true; |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 3367 | wake = 2; /* for good measure */ |
| 3368 | break; |
| 3369 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3370 | default: |
| 3371 | pr_err("mdsc_handle_session bad op %d mds%d\n", op, mds); |
| 3372 | WARN_ON(1); |
| 3373 | } |
| 3374 | |
| 3375 | mutex_unlock(&session->s_mutex); |
| 3376 | if (wake) { |
| 3377 | mutex_lock(&mdsc->mutex); |
| 3378 | __wake_requests(mdsc, &session->s_waiting); |
Yan, Zheng | 656e438 | 2014-09-11 14:25:18 +0800 | [diff] [blame] | 3379 | if (wake == 2) |
| 3380 | kick_requests(mdsc, mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3381 | mutex_unlock(&mdsc->mutex); |
| 3382 | } |
Yan, Zheng | 0a07fc8 | 2017-03-29 15:30:24 +0800 | [diff] [blame] | 3383 | if (op == CEPH_SESSION_CLOSE) |
| 3384 | ceph_put_mds_session(session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3385 | return; |
| 3386 | |
| 3387 | bad: |
| 3388 | pr_err("mdsc_handle_session corrupt message mds%d len %d\n", mds, |
| 3389 | (int)msg->front.iov_len); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 3390 | ceph_msg_dump(msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3391 | return; |
| 3392 | } |
| 3393 | |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3394 | void ceph_mdsc_release_dir_caps(struct ceph_mds_request *req) |
| 3395 | { |
| 3396 | int dcaps; |
| 3397 | |
| 3398 | dcaps = xchg(&req->r_dir_caps, 0); |
| 3399 | if (dcaps) { |
| 3400 | dout("releasing r_dir_caps=%s\n", ceph_cap_string(dcaps)); |
| 3401 | ceph_put_cap_refs(ceph_inode(req->r_parent), dcaps); |
| 3402 | } |
| 3403 | } |
| 3404 | |
Xiubo Li | e64f44a | 2020-05-27 09:09:27 -0400 | [diff] [blame] | 3405 | void ceph_mdsc_release_dir_caps_no_check(struct ceph_mds_request *req) |
| 3406 | { |
| 3407 | int dcaps; |
| 3408 | |
| 3409 | dcaps = xchg(&req->r_dir_caps, 0); |
| 3410 | if (dcaps) { |
| 3411 | dout("releasing r_dir_caps=%s\n", ceph_cap_string(dcaps)); |
| 3412 | ceph_put_cap_refs_no_check_caps(ceph_inode(req->r_parent), |
| 3413 | dcaps); |
| 3414 | } |
| 3415 | } |
| 3416 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3417 | /* |
| 3418 | * called under session->mutex. |
| 3419 | */ |
| 3420 | static void replay_unsafe_requests(struct ceph_mds_client *mdsc, |
| 3421 | struct ceph_mds_session *session) |
| 3422 | { |
| 3423 | struct ceph_mds_request *req, *nreq; |
Yan, Zheng | 3de22be | 2015-02-04 14:26:22 +0800 | [diff] [blame] | 3424 | struct rb_node *p; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3425 | |
| 3426 | dout("replay_unsafe_requests mds%d\n", session->s_mds); |
| 3427 | |
| 3428 | mutex_lock(&mdsc->mutex); |
Xiubo Li | 9cf5456 | 2019-12-05 20:50:21 -0500 | [diff] [blame] | 3429 | list_for_each_entry_safe(req, nreq, &session->s_unsafe, r_unsafe_item) |
| 3430 | __send_request(mdsc, session, req, true); |
Yan, Zheng | 3de22be | 2015-02-04 14:26:22 +0800 | [diff] [blame] | 3431 | |
| 3432 | /* |
| 3433 | * also re-send old requests when MDS enters reconnect stage. So that MDS |
| 3434 | * can process completed request in clientreplay stage. |
| 3435 | */ |
| 3436 | p = rb_first(&mdsc->request_tree); |
| 3437 | while (p) { |
| 3438 | req = rb_entry(p, struct ceph_mds_request, r_node); |
| 3439 | p = rb_next(p); |
Jeff Layton | bc2de10d | 2017-02-01 13:49:09 -0500 | [diff] [blame] | 3440 | if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) |
Yan, Zheng | 3de22be | 2015-02-04 14:26:22 +0800 | [diff] [blame] | 3441 | continue; |
| 3442 | if (req->r_attempts == 0) |
| 3443 | continue; /* only old requests */ |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3444 | if (!req->r_session) |
| 3445 | continue; |
| 3446 | if (req->r_session->s_mds != session->s_mds) |
| 3447 | continue; |
| 3448 | |
Xiubo Li | e64f44a | 2020-05-27 09:09:27 -0400 | [diff] [blame] | 3449 | ceph_mdsc_release_dir_caps_no_check(req); |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3450 | |
| 3451 | __send_request(mdsc, session, req, true); |
Yan, Zheng | 3de22be | 2015-02-04 14:26:22 +0800 | [diff] [blame] | 3452 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3453 | mutex_unlock(&mdsc->mutex); |
| 3454 | } |
| 3455 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3456 | static int send_reconnect_partial(struct ceph_reconnect_state *recon_state) |
| 3457 | { |
| 3458 | struct ceph_msg *reply; |
| 3459 | struct ceph_pagelist *_pagelist; |
| 3460 | struct page *page; |
| 3461 | __le32 *addr; |
| 3462 | int err = -ENOMEM; |
| 3463 | |
| 3464 | if (!recon_state->allow_multi) |
| 3465 | return -ENOSPC; |
| 3466 | |
| 3467 | /* can't handle message that contains both caps and realm */ |
| 3468 | BUG_ON(!recon_state->nr_caps == !recon_state->nr_realms); |
| 3469 | |
| 3470 | /* pre-allocate new pagelist */ |
| 3471 | _pagelist = ceph_pagelist_alloc(GFP_NOFS); |
| 3472 | if (!_pagelist) |
| 3473 | return -ENOMEM; |
| 3474 | |
| 3475 | reply = ceph_msg_new2(CEPH_MSG_CLIENT_RECONNECT, 0, 1, GFP_NOFS, false); |
| 3476 | if (!reply) |
| 3477 | goto fail_msg; |
| 3478 | |
| 3479 | /* placeholder for nr_caps */ |
| 3480 | err = ceph_pagelist_encode_32(_pagelist, 0); |
| 3481 | if (err < 0) |
| 3482 | goto fail; |
| 3483 | |
| 3484 | if (recon_state->nr_caps) { |
| 3485 | /* currently encoding caps */ |
| 3486 | err = ceph_pagelist_encode_32(recon_state->pagelist, 0); |
| 3487 | if (err) |
| 3488 | goto fail; |
| 3489 | } else { |
| 3490 | /* placeholder for nr_realms (currently encoding relams) */ |
| 3491 | err = ceph_pagelist_encode_32(_pagelist, 0); |
| 3492 | if (err < 0) |
| 3493 | goto fail; |
| 3494 | } |
| 3495 | |
| 3496 | err = ceph_pagelist_encode_8(recon_state->pagelist, 1); |
| 3497 | if (err) |
| 3498 | goto fail; |
| 3499 | |
| 3500 | page = list_first_entry(&recon_state->pagelist->head, struct page, lru); |
| 3501 | addr = kmap_atomic(page); |
| 3502 | if (recon_state->nr_caps) { |
| 3503 | /* currently encoding caps */ |
| 3504 | *addr = cpu_to_le32(recon_state->nr_caps); |
| 3505 | } else { |
| 3506 | /* currently encoding relams */ |
| 3507 | *(addr + 1) = cpu_to_le32(recon_state->nr_realms); |
| 3508 | } |
| 3509 | kunmap_atomic(addr); |
| 3510 | |
| 3511 | reply->hdr.version = cpu_to_le16(5); |
| 3512 | reply->hdr.compat_version = cpu_to_le16(4); |
| 3513 | |
| 3514 | reply->hdr.data_len = cpu_to_le32(recon_state->pagelist->length); |
| 3515 | ceph_msg_data_add_pagelist(reply, recon_state->pagelist); |
| 3516 | |
| 3517 | ceph_con_send(&recon_state->session->s_con, reply); |
| 3518 | ceph_pagelist_release(recon_state->pagelist); |
| 3519 | |
| 3520 | recon_state->pagelist = _pagelist; |
| 3521 | recon_state->nr_caps = 0; |
| 3522 | recon_state->nr_realms = 0; |
| 3523 | recon_state->msg_version = 5; |
| 3524 | return 0; |
| 3525 | fail: |
| 3526 | ceph_msg_put(reply); |
| 3527 | fail_msg: |
| 3528 | ceph_pagelist_release(_pagelist); |
| 3529 | return err; |
| 3530 | } |
| 3531 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3532 | /* |
| 3533 | * Encode information about a cap for a reconnect with the MDS. |
| 3534 | */ |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3535 | static int reconnect_caps_cb(struct inode *inode, struct ceph_cap *cap, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3536 | void *arg) |
| 3537 | { |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3538 | union { |
| 3539 | struct ceph_mds_cap_reconnect v2; |
| 3540 | struct ceph_mds_cap_reconnect_v1 v1; |
| 3541 | } rec; |
Yan, Zheng | b3f8d68 | 2017-09-11 10:58:55 +0800 | [diff] [blame] | 3542 | struct ceph_inode_info *ci = cap->ci; |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3543 | struct ceph_reconnect_state *recon_state = arg; |
| 3544 | struct ceph_pagelist *pagelist = recon_state->pagelist; |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3545 | int err; |
Yan, Zheng | 3469ed0 | 2016-07-05 09:32:31 +0800 | [diff] [blame] | 3546 | u64 snap_follows; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3547 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3548 | dout(" adding %p ino %llx.%llx cap %p %lld %s\n", |
| 3549 | inode, ceph_vinop(inode), cap, cap->cap_id, |
| 3550 | ceph_cap_string(cap->issued)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3551 | |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 3552 | spin_lock(&ci->i_ceph_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3553 | cap->seq = 0; /* reset cap seq */ |
| 3554 | cap->issue_seq = 0; /* and issue_seq */ |
Yan, Zheng | 667ca05 | 2013-05-31 16:25:36 +0800 | [diff] [blame] | 3555 | cap->mseq = 0; /* and migrate_seq */ |
Yan, Zheng | 99a9c27 | 2013-09-22 11:08:14 +0800 | [diff] [blame] | 3556 | cap->cap_gen = cap->session->s_cap_gen; |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3557 | |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3558 | /* These are lost when the session goes away */ |
Jeff Layton | 785892f | 2020-01-02 07:11:38 -0500 | [diff] [blame] | 3559 | if (S_ISDIR(inode->i_mode)) { |
| 3560 | if (cap->issued & CEPH_CAP_DIR_CREATE) { |
| 3561 | ceph_put_string(rcu_dereference_raw(ci->i_cached_layout.pool_ns)); |
| 3562 | memset(&ci->i_cached_layout, 0, sizeof(ci->i_cached_layout)); |
| 3563 | } |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3564 | cap->issued &= ~CEPH_CAP_ANY_DIR_OPS; |
Jeff Layton | 785892f | 2020-01-02 07:11:38 -0500 | [diff] [blame] | 3565 | } |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3566 | |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3567 | if (recon_state->msg_version >= 2) { |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3568 | rec.v2.cap_id = cpu_to_le64(cap->cap_id); |
| 3569 | rec.v2.wanted = cpu_to_le32(__ceph_caps_wanted(ci)); |
| 3570 | rec.v2.issued = cpu_to_le32(cap->issued); |
| 3571 | rec.v2.snaprealm = cpu_to_le64(ci->i_snap_realm->ino); |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3572 | rec.v2.pathbase = 0; |
Jeff Layton | ec1dff2 | 2017-10-31 15:51:14 -0400 | [diff] [blame] | 3573 | rec.v2.flock_len = (__force __le32) |
| 3574 | ((ci->i_ceph_flags & CEPH_I_ERROR_FILELOCK) ? 0 : 1); |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3575 | } else { |
| 3576 | rec.v1.cap_id = cpu_to_le64(cap->cap_id); |
| 3577 | rec.v1.wanted = cpu_to_le32(__ceph_caps_wanted(ci)); |
| 3578 | rec.v1.issued = cpu_to_le32(cap->issued); |
| 3579 | rec.v1.size = cpu_to_le64(inode->i_size); |
Arnd Bergmann | 9bbeab4 | 2018-07-13 22:18:36 +0200 | [diff] [blame] | 3580 | ceph_encode_timespec64(&rec.v1.mtime, &inode->i_mtime); |
| 3581 | ceph_encode_timespec64(&rec.v1.atime, &inode->i_atime); |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3582 | rec.v1.snaprealm = cpu_to_le64(ci->i_snap_realm->ino); |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3583 | rec.v1.pathbase = 0; |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3584 | } |
Yan, Zheng | 3469ed0 | 2016-07-05 09:32:31 +0800 | [diff] [blame] | 3585 | |
| 3586 | if (list_empty(&ci->i_cap_snaps)) { |
Yan, Zheng | 92776fd | 2017-08-16 21:42:39 +0800 | [diff] [blame] | 3587 | snap_follows = ci->i_head_snapc ? ci->i_head_snapc->seq : 0; |
Yan, Zheng | 3469ed0 | 2016-07-05 09:32:31 +0800 | [diff] [blame] | 3588 | } else { |
| 3589 | struct ceph_cap_snap *capsnap = |
| 3590 | list_first_entry(&ci->i_cap_snaps, |
| 3591 | struct ceph_cap_snap, ci_item); |
| 3592 | snap_follows = capsnap->follows; |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3593 | } |
Sage Weil | be65559 | 2011-11-30 09:47:09 -0800 | [diff] [blame] | 3594 | spin_unlock(&ci->i_ceph_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3595 | |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3596 | if (recon_state->msg_version >= 2) { |
Greg Farnum | 40819f6 | 2010-08-02 15:34:23 -0700 | [diff] [blame] | 3597 | int num_fcntl_locks, num_flock_locks; |
Yan, Zheng | 4deb14a | 2017-09-11 10:36:28 +0800 | [diff] [blame] | 3598 | struct ceph_filelock *flocks = NULL; |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3599 | size_t struct_len, total_len = sizeof(u64); |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3600 | u8 struct_v = 0; |
Greg Farnum | 40819f6 | 2010-08-02 15:34:23 -0700 | [diff] [blame] | 3601 | |
Jim Schutt | 39be95e | 2013-05-15 13:03:35 -0500 | [diff] [blame] | 3602 | encode_again: |
Yan, Zheng | b3f8d68 | 2017-09-11 10:58:55 +0800 | [diff] [blame] | 3603 | if (rec.v2.flock_len) { |
| 3604 | ceph_count_locks(inode, &num_fcntl_locks, &num_flock_locks); |
| 3605 | } else { |
| 3606 | num_fcntl_locks = 0; |
| 3607 | num_flock_locks = 0; |
| 3608 | } |
Yan, Zheng | 4deb14a | 2017-09-11 10:36:28 +0800 | [diff] [blame] | 3609 | if (num_fcntl_locks + num_flock_locks > 0) { |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 3610 | flocks = kmalloc_array(num_fcntl_locks + num_flock_locks, |
| 3611 | sizeof(struct ceph_filelock), |
| 3612 | GFP_NOFS); |
Yan, Zheng | 4deb14a | 2017-09-11 10:36:28 +0800 | [diff] [blame] | 3613 | if (!flocks) { |
| 3614 | err = -ENOMEM; |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3615 | goto out_err; |
Yan, Zheng | 4deb14a | 2017-09-11 10:36:28 +0800 | [diff] [blame] | 3616 | } |
| 3617 | err = ceph_encode_locks_to_buffer(inode, flocks, |
| 3618 | num_fcntl_locks, |
| 3619 | num_flock_locks); |
| 3620 | if (err) { |
| 3621 | kfree(flocks); |
| 3622 | flocks = NULL; |
| 3623 | if (err == -ENOSPC) |
| 3624 | goto encode_again; |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3625 | goto out_err; |
Yan, Zheng | 4deb14a | 2017-09-11 10:36:28 +0800 | [diff] [blame] | 3626 | } |
| 3627 | } else { |
Jim Schutt | 39be95e | 2013-05-15 13:03:35 -0500 | [diff] [blame] | 3628 | kfree(flocks); |
Yan, Zheng | 4deb14a | 2017-09-11 10:36:28 +0800 | [diff] [blame] | 3629 | flocks = NULL; |
Jim Schutt | 39be95e | 2013-05-15 13:03:35 -0500 | [diff] [blame] | 3630 | } |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3631 | |
| 3632 | if (recon_state->msg_version >= 3) { |
| 3633 | /* version, compat_version and struct_len */ |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3634 | total_len += 2 * sizeof(u8) + sizeof(u32); |
Yan, Zheng | 3469ed0 | 2016-07-05 09:32:31 +0800 | [diff] [blame] | 3635 | struct_v = 2; |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3636 | } |
Jim Schutt | 39be95e | 2013-05-15 13:03:35 -0500 | [diff] [blame] | 3637 | /* |
| 3638 | * number of encoded locks is stable, so copy to pagelist |
| 3639 | */ |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3640 | struct_len = 2 * sizeof(u32) + |
| 3641 | (num_fcntl_locks + num_flock_locks) * |
| 3642 | sizeof(struct ceph_filelock); |
| 3643 | rec.v2.flock_len = cpu_to_le32(struct_len); |
| 3644 | |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3645 | struct_len += sizeof(u32) + sizeof(rec.v2); |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3646 | |
Yan, Zheng | 3469ed0 | 2016-07-05 09:32:31 +0800 | [diff] [blame] | 3647 | if (struct_v >= 2) |
| 3648 | struct_len += sizeof(u64); /* snap_follows */ |
| 3649 | |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3650 | total_len += struct_len; |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3651 | |
| 3652 | if (pagelist->length + total_len > RECONNECT_MAX_SIZE) { |
| 3653 | err = send_reconnect_partial(recon_state); |
| 3654 | if (err) |
| 3655 | goto out_freeflocks; |
| 3656 | pagelist = recon_state->pagelist; |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3657 | } |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3658 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3659 | err = ceph_pagelist_reserve(pagelist, total_len); |
| 3660 | if (err) |
| 3661 | goto out_freeflocks; |
| 3662 | |
| 3663 | ceph_pagelist_encode_64(pagelist, ceph_ino(inode)); |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3664 | if (recon_state->msg_version >= 3) { |
| 3665 | ceph_pagelist_encode_8(pagelist, struct_v); |
| 3666 | ceph_pagelist_encode_8(pagelist, 1); |
| 3667 | ceph_pagelist_encode_32(pagelist, struct_len); |
| 3668 | } |
| 3669 | ceph_pagelist_encode_string(pagelist, NULL, 0); |
| 3670 | ceph_pagelist_append(pagelist, &rec, sizeof(rec.v2)); |
| 3671 | ceph_locks_to_pagelist(flocks, pagelist, |
| 3672 | num_fcntl_locks, num_flock_locks); |
| 3673 | if (struct_v >= 2) |
| 3674 | ceph_pagelist_encode_64(pagelist, snap_follows); |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3675 | out_freeflocks: |
Jim Schutt | 39be95e | 2013-05-15 13:03:35 -0500 | [diff] [blame] | 3676 | kfree(flocks); |
Sage Weil | 3612abb | 2010-09-07 15:59:27 -0700 | [diff] [blame] | 3677 | } else { |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3678 | u64 pathbase = 0; |
| 3679 | int pathlen = 0; |
| 3680 | char *path = NULL; |
| 3681 | struct dentry *dentry; |
| 3682 | |
| 3683 | dentry = d_find_alias(inode); |
| 3684 | if (dentry) { |
| 3685 | path = ceph_mdsc_build_path(dentry, |
| 3686 | &pathlen, &pathbase, 0); |
| 3687 | dput(dentry); |
| 3688 | if (IS_ERR(path)) { |
| 3689 | err = PTR_ERR(path); |
| 3690 | goto out_err; |
| 3691 | } |
| 3692 | rec.v1.pathbase = cpu_to_le64(pathbase); |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3693 | } |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3694 | |
| 3695 | err = ceph_pagelist_reserve(pagelist, |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3696 | sizeof(u64) + sizeof(u32) + |
| 3697 | pathlen + sizeof(rec.v1)); |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3698 | if (err) { |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3699 | goto out_freepath; |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3700 | } |
| 3701 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3702 | ceph_pagelist_encode_64(pagelist, ceph_ino(inode)); |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3703 | ceph_pagelist_encode_string(pagelist, path, pathlen); |
| 3704 | ceph_pagelist_append(pagelist, &rec, sizeof(rec.v1)); |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3705 | out_freepath: |
Jeff Layton | f77f21b | 2019-04-29 12:13:14 -0400 | [diff] [blame] | 3706 | ceph_mdsc_free_path(path, pathlen); |
Greg Farnum | 40819f6 | 2010-08-02 15:34:23 -0700 | [diff] [blame] | 3707 | } |
Yan, Zheng | 44c9975 | 2013-09-22 10:28:10 +0800 | [diff] [blame] | 3708 | |
Yan, Zheng | 5ccedf1 | 2018-12-13 16:34:11 +0800 | [diff] [blame] | 3709 | out_err: |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3710 | if (err >= 0) |
| 3711 | recon_state->nr_caps++; |
| 3712 | return err; |
| 3713 | } |
| 3714 | |
| 3715 | static int encode_snap_realms(struct ceph_mds_client *mdsc, |
| 3716 | struct ceph_reconnect_state *recon_state) |
| 3717 | { |
| 3718 | struct rb_node *p; |
| 3719 | struct ceph_pagelist *pagelist = recon_state->pagelist; |
| 3720 | int err = 0; |
| 3721 | |
| 3722 | if (recon_state->msg_version >= 4) { |
| 3723 | err = ceph_pagelist_encode_32(pagelist, mdsc->num_snap_realms); |
| 3724 | if (err < 0) |
| 3725 | goto fail; |
| 3726 | } |
| 3727 | |
| 3728 | /* |
| 3729 | * snaprealms. we provide mds with the ino, seq (version), and |
| 3730 | * parent for all of our realms. If the mds has any newer info, |
| 3731 | * it will tell us. |
| 3732 | */ |
| 3733 | for (p = rb_first(&mdsc->snap_realms); p; p = rb_next(p)) { |
| 3734 | struct ceph_snap_realm *realm = |
| 3735 | rb_entry(p, struct ceph_snap_realm, node); |
| 3736 | struct ceph_mds_snaprealm_reconnect sr_rec; |
| 3737 | |
| 3738 | if (recon_state->msg_version >= 4) { |
| 3739 | size_t need = sizeof(u8) * 2 + sizeof(u32) + |
| 3740 | sizeof(sr_rec); |
| 3741 | |
| 3742 | if (pagelist->length + need > RECONNECT_MAX_SIZE) { |
| 3743 | err = send_reconnect_partial(recon_state); |
| 3744 | if (err) |
| 3745 | goto fail; |
| 3746 | pagelist = recon_state->pagelist; |
| 3747 | } |
| 3748 | |
| 3749 | err = ceph_pagelist_reserve(pagelist, need); |
| 3750 | if (err) |
| 3751 | goto fail; |
| 3752 | |
| 3753 | ceph_pagelist_encode_8(pagelist, 1); |
| 3754 | ceph_pagelist_encode_8(pagelist, 1); |
| 3755 | ceph_pagelist_encode_32(pagelist, sizeof(sr_rec)); |
| 3756 | } |
| 3757 | |
| 3758 | dout(" adding snap realm %llx seq %lld parent %llx\n", |
| 3759 | realm->ino, realm->seq, realm->parent_ino); |
| 3760 | sr_rec.ino = cpu_to_le64(realm->ino); |
| 3761 | sr_rec.seq = cpu_to_le64(realm->seq); |
| 3762 | sr_rec.parent = cpu_to_le64(realm->parent_ino); |
| 3763 | |
| 3764 | err = ceph_pagelist_append(pagelist, &sr_rec, sizeof(sr_rec)); |
| 3765 | if (err) |
| 3766 | goto fail; |
| 3767 | |
| 3768 | recon_state->nr_realms++; |
| 3769 | } |
| 3770 | fail: |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3771 | return err; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | |
| 3775 | /* |
| 3776 | * If an MDS fails and recovers, clients need to reconnect in order to |
| 3777 | * reestablish shared state. This includes all caps issued through |
| 3778 | * this session _and_ the snap_realm hierarchy. Because it's not |
| 3779 | * clear which snap realms the mds cares about, we send everything we |
| 3780 | * know about.. that ensures we'll then get any new info the |
| 3781 | * recovering MDS might have. |
| 3782 | * |
| 3783 | * This is a relatively heavyweight operation, but it's rare. |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3784 | */ |
Sage Weil | 34b6c85 | 2010-05-10 16:31:25 -0700 | [diff] [blame] | 3785 | static void send_mds_reconnect(struct ceph_mds_client *mdsc, |
| 3786 | struct ceph_mds_session *session) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3787 | { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3788 | struct ceph_msg *reply; |
Sage Weil | 34b6c85 | 2010-05-10 16:31:25 -0700 | [diff] [blame] | 3789 | int mds = session->s_mds; |
Sage Weil | 9abf82b | 2010-05-10 21:58:38 -0700 | [diff] [blame] | 3790 | int err = -ENOMEM; |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3791 | struct ceph_reconnect_state recon_state = { |
| 3792 | .session = session, |
| 3793 | }; |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 3794 | LIST_HEAD(dispose); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3795 | |
Sage Weil | 34b6c85 | 2010-05-10 16:31:25 -0700 | [diff] [blame] | 3796 | pr_info("mds%d reconnect start\n", mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3797 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3798 | recon_state.pagelist = ceph_pagelist_alloc(GFP_NOFS); |
| 3799 | if (!recon_state.pagelist) |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3800 | goto fail_nopagelist; |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3801 | |
Ilya Dryomov | 0d9c1ab | 2018-10-15 17:38:23 +0200 | [diff] [blame] | 3802 | reply = ceph_msg_new2(CEPH_MSG_CLIENT_RECONNECT, 0, 1, GFP_NOFS, false); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 3803 | if (!reply) |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3804 | goto fail_nomsg; |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3805 | |
Jeff Layton | d484648 | 2019-11-15 11:51:55 -0500 | [diff] [blame] | 3806 | xa_destroy(&session->s_delegated_inos); |
| 3807 | |
Sage Weil | 34b6c85 | 2010-05-10 16:31:25 -0700 | [diff] [blame] | 3808 | mutex_lock(&session->s_mutex); |
| 3809 | session->s_state = CEPH_MDS_SESSION_RECONNECTING; |
| 3810 | session->s_seq = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3811 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3812 | dout("session %p state %s\n", session, |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 3813 | ceph_session_state_name(session->s_state)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3814 | |
Yan, Zheng | 99a9c27 | 2013-09-22 11:08:14 +0800 | [diff] [blame] | 3815 | spin_lock(&session->s_gen_ttl_lock); |
| 3816 | session->s_cap_gen++; |
| 3817 | spin_unlock(&session->s_gen_ttl_lock); |
| 3818 | |
| 3819 | spin_lock(&session->s_cap_lock); |
Yan, Zheng | 03f4fcb | 2015-01-05 11:04:04 +0800 | [diff] [blame] | 3820 | /* don't know if session is readonly */ |
| 3821 | session->s_readonly = 0; |
Yan, Zheng | 99a9c27 | 2013-09-22 11:08:14 +0800 | [diff] [blame] | 3822 | /* |
| 3823 | * notify __ceph_remove_cap() that we are composing cap reconnect. |
| 3824 | * If a cap get released before being added to the cap reconnect, |
| 3825 | * __ceph_remove_cap() should skip queuing cap release. |
| 3826 | */ |
| 3827 | session->s_cap_reconnect = 1; |
Sage Weil | e01a594 | 2010-05-10 15:36:44 -0700 | [diff] [blame] | 3828 | /* drop old cap expires; we're about to reestablish that state */ |
Jeff Layton | c8a96a3 | 2017-10-19 08:53:58 -0400 | [diff] [blame] | 3829 | detach_cap_releases(session, &dispose); |
| 3830 | spin_unlock(&session->s_cap_lock); |
| 3831 | dispose_cap_releases(mdsc, &dispose); |
Sage Weil | e01a594 | 2010-05-10 15:36:44 -0700 | [diff] [blame] | 3832 | |
Yan, Zheng | 5d23371 | 2014-09-10 16:56:23 +0800 | [diff] [blame] | 3833 | /* trim unused caps to reduce MDS's cache rejoin time */ |
Yan, Zheng | c0bd50e | 2015-04-07 15:51:08 +0800 | [diff] [blame] | 3834 | if (mdsc->fsc->sb->s_root) |
| 3835 | shrink_dcache_parent(mdsc->fsc->sb->s_root); |
Yan, Zheng | 5d23371 | 2014-09-10 16:56:23 +0800 | [diff] [blame] | 3836 | |
| 3837 | ceph_con_close(&session->s_con); |
| 3838 | ceph_con_open(&session->s_con, |
| 3839 | CEPH_ENTITY_TYPE_MDS, mds, |
| 3840 | ceph_mdsmap_get_addr(mdsc->mdsmap, mds)); |
| 3841 | |
| 3842 | /* replay unsafe requests */ |
| 3843 | replay_unsafe_requests(mdsc, session); |
| 3844 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3845 | ceph_early_kick_flushing_caps(mdsc, session); |
| 3846 | |
Yan, Zheng | 5d23371 | 2014-09-10 16:56:23 +0800 | [diff] [blame] | 3847 | down_read(&mdsc->snap_rwsem); |
| 3848 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3849 | /* placeholder for nr_caps */ |
| 3850 | err = ceph_pagelist_encode_32(recon_state.pagelist, 0); |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3851 | if (err) |
| 3852 | goto fail; |
Sage Weil | 20cb34a | 2010-05-12 15:21:32 -0700 | [diff] [blame] | 3853 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3854 | if (test_bit(CEPHFS_FEATURE_MULTI_RECONNECT, &session->s_features)) { |
Yan, Zheng | 121f22a | 2016-07-04 22:05:18 +0800 | [diff] [blame] | 3855 | recon_state.msg_version = 3; |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3856 | recon_state.allow_multi = true; |
| 3857 | } else if (session->s_con.peer_features & CEPH_FEATURE_MDSENC) { |
| 3858 | recon_state.msg_version = 3; |
| 3859 | } else { |
Ilya Dryomov | 23c625c | 2018-11-08 14:55:21 +0100 | [diff] [blame] | 3860 | recon_state.msg_version = 2; |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3861 | } |
| 3862 | /* trsaverse this session's caps */ |
Jeff Layton | a25949b | 2020-02-18 14:12:45 -0500 | [diff] [blame] | 3863 | err = ceph_iterate_session_caps(session, reconnect_caps_cb, &recon_state); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3864 | |
Yan, Zheng | 99a9c27 | 2013-09-22 11:08:14 +0800 | [diff] [blame] | 3865 | spin_lock(&session->s_cap_lock); |
| 3866 | session->s_cap_reconnect = 0; |
| 3867 | spin_unlock(&session->s_cap_lock); |
| 3868 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3869 | if (err < 0) |
| 3870 | goto fail; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3871 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3872 | /* check if all realms can be encoded into current message */ |
| 3873 | if (mdsc->num_snap_realms) { |
| 3874 | size_t total_len = |
| 3875 | recon_state.pagelist->length + |
| 3876 | mdsc->num_snap_realms * |
| 3877 | sizeof(struct ceph_mds_snaprealm_reconnect); |
| 3878 | if (recon_state.msg_version >= 4) { |
| 3879 | /* number of realms */ |
| 3880 | total_len += sizeof(u32); |
| 3881 | /* version, compat_version and struct_len */ |
| 3882 | total_len += mdsc->num_snap_realms * |
| 3883 | (2 * sizeof(u8) + sizeof(u32)); |
| 3884 | } |
| 3885 | if (total_len > RECONNECT_MAX_SIZE) { |
| 3886 | if (!recon_state.allow_multi) { |
| 3887 | err = -ENOSPC; |
| 3888 | goto fail; |
| 3889 | } |
| 3890 | if (recon_state.nr_caps) { |
| 3891 | err = send_reconnect_partial(&recon_state); |
| 3892 | if (err) |
| 3893 | goto fail; |
| 3894 | } |
| 3895 | recon_state.msg_version = 5; |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | err = encode_snap_realms(mdsc, &recon_state); |
| 3900 | if (err < 0) |
| 3901 | goto fail; |
| 3902 | |
| 3903 | if (recon_state.msg_version >= 5) { |
| 3904 | err = ceph_pagelist_encode_8(recon_state.pagelist, 0); |
| 3905 | if (err < 0) |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3906 | goto fail; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3907 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3908 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3909 | if (recon_state.nr_caps || recon_state.nr_realms) { |
| 3910 | struct page *page = |
| 3911 | list_first_entry(&recon_state.pagelist->head, |
| 3912 | struct page, lru); |
Yan, Zheng | 44c9975 | 2013-09-22 10:28:10 +0800 | [diff] [blame] | 3913 | __le32 *addr = kmap_atomic(page); |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3914 | if (recon_state.nr_caps) { |
| 3915 | WARN_ON(recon_state.nr_realms != mdsc->num_snap_realms); |
| 3916 | *addr = cpu_to_le32(recon_state.nr_caps); |
| 3917 | } else if (recon_state.msg_version >= 4) { |
| 3918 | *(addr + 1) = cpu_to_le32(recon_state.nr_realms); |
| 3919 | } |
Yan, Zheng | 44c9975 | 2013-09-22 10:28:10 +0800 | [diff] [blame] | 3920 | kunmap_atomic(addr); |
Alex Elder | ebf18f4 | 2013-03-04 22:29:57 -0600 | [diff] [blame] | 3921 | } |
Yan, Zheng | 44c9975 | 2013-09-22 10:28:10 +0800 | [diff] [blame] | 3922 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3923 | reply->hdr.version = cpu_to_le16(recon_state.msg_version); |
| 3924 | if (recon_state.msg_version >= 4) |
| 3925 | reply->hdr.compat_version = cpu_to_le16(4); |
Yan, Zheng | e548e9b | 2015-06-10 15:17:56 +0800 | [diff] [blame] | 3926 | |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3927 | reply->hdr.data_len = cpu_to_le32(recon_state.pagelist->length); |
| 3928 | ceph_msg_data_add_pagelist(reply, recon_state.pagelist); |
Yan, Zheng | e548e9b | 2015-06-10 15:17:56 +0800 | [diff] [blame] | 3929 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3930 | ceph_con_send(&session->s_con, reply); |
| 3931 | |
Sage Weil | 9abf82b | 2010-05-10 21:58:38 -0700 | [diff] [blame] | 3932 | mutex_unlock(&session->s_mutex); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3933 | |
Sage Weil | 9abf82b | 2010-05-10 21:58:38 -0700 | [diff] [blame] | 3934 | mutex_lock(&mdsc->mutex); |
| 3935 | __wake_requests(mdsc, &session->s_waiting); |
| 3936 | mutex_unlock(&mdsc->mutex); |
| 3937 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3938 | up_read(&mdsc->snap_rwsem); |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3939 | ceph_pagelist_release(recon_state.pagelist); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3940 | return; |
| 3941 | |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3942 | fail: |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3943 | ceph_msg_put(reply); |
Sage Weil | 9abf82b | 2010-05-10 21:58:38 -0700 | [diff] [blame] | 3944 | up_read(&mdsc->snap_rwsem); |
| 3945 | mutex_unlock(&session->s_mutex); |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3946 | fail_nomsg: |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 3947 | ceph_pagelist_release(recon_state.pagelist); |
Sage Weil | 93cea5b | 2009-12-23 12:21:51 -0800 | [diff] [blame] | 3948 | fail_nopagelist: |
Sage Weil | 9abf82b | 2010-05-10 21:58:38 -0700 | [diff] [blame] | 3949 | pr_err("error %d preparing reconnect for mds%d\n", err, mds); |
Sage Weil | 9abf82b | 2010-05-10 21:58:38 -0700 | [diff] [blame] | 3950 | return; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | |
| 3954 | /* |
| 3955 | * compare old and new mdsmaps, kicking requests |
| 3956 | * and closing out old connections as necessary |
| 3957 | * |
| 3958 | * called under mdsc->mutex. |
| 3959 | */ |
| 3960 | static void check_new_map(struct ceph_mds_client *mdsc, |
| 3961 | struct ceph_mdsmap *newmap, |
| 3962 | struct ceph_mdsmap *oldmap) |
| 3963 | { |
| 3964 | int i; |
| 3965 | int oldstate, newstate; |
| 3966 | struct ceph_mds_session *s; |
| 3967 | |
| 3968 | dout("check_new_map new %u old %u\n", |
| 3969 | newmap->m_epoch, oldmap->m_epoch); |
| 3970 | |
Xiubo Li | b38c9eb | 2019-12-04 06:57:39 -0500 | [diff] [blame] | 3971 | for (i = 0; i < oldmap->possible_max_rank && i < mdsc->max_sessions; i++) { |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 3972 | if (!mdsc->sessions[i]) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3973 | continue; |
| 3974 | s = mdsc->sessions[i]; |
| 3975 | oldstate = ceph_mdsmap_get_state(oldmap, i); |
| 3976 | newstate = ceph_mdsmap_get_state(newmap, i); |
| 3977 | |
Sage Weil | 0deb01c | 2010-06-17 14:19:01 -0700 | [diff] [blame] | 3978 | dout("check_new_map mds%d state %s%s -> %s%s (session %s)\n", |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3979 | i, ceph_mds_state_name(oldstate), |
Sage Weil | 0deb01c | 2010-06-17 14:19:01 -0700 | [diff] [blame] | 3980 | ceph_mdsmap_is_laggy(oldmap, i) ? " (laggy)" : "", |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3981 | ceph_mds_state_name(newstate), |
Sage Weil | 0deb01c | 2010-06-17 14:19:01 -0700 | [diff] [blame] | 3982 | ceph_mdsmap_is_laggy(newmap, i) ? " (laggy)" : "", |
John Spray | a687eca | 2014-09-19 13:51:08 +0100 | [diff] [blame] | 3983 | ceph_session_state_name(s->s_state)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 3984 | |
Xiubo Li | b38c9eb | 2019-12-04 06:57:39 -0500 | [diff] [blame] | 3985 | if (i >= newmap->possible_max_rank) { |
Yan, Zheng | 6f0f597 | 2019-06-10 15:45:09 +0800 | [diff] [blame] | 3986 | /* force close session for stopped mds */ |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 3987 | ceph_get_mds_session(s); |
Yan, Zheng | 6f0f597 | 2019-06-10 15:45:09 +0800 | [diff] [blame] | 3988 | __unregister_session(mdsc, s); |
| 3989 | __wake_requests(mdsc, &s->s_waiting); |
| 3990 | mutex_unlock(&mdsc->mutex); |
| 3991 | |
| 3992 | mutex_lock(&s->s_mutex); |
| 3993 | cleanup_session_requests(mdsc, s); |
| 3994 | remove_session_caps(s); |
| 3995 | mutex_unlock(&s->s_mutex); |
| 3996 | |
| 3997 | ceph_put_mds_session(s); |
| 3998 | |
| 3999 | mutex_lock(&mdsc->mutex); |
| 4000 | kick_requests(mdsc, i); |
| 4001 | continue; |
| 4002 | } |
| 4003 | |
| 4004 | if (memcmp(ceph_mdsmap_get_addr(oldmap, i), |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4005 | ceph_mdsmap_get_addr(newmap, i), |
| 4006 | sizeof(struct ceph_entity_addr))) { |
Yan, Zheng | 6f0f597 | 2019-06-10 15:45:09 +0800 | [diff] [blame] | 4007 | /* just close it */ |
| 4008 | mutex_unlock(&mdsc->mutex); |
| 4009 | mutex_lock(&s->s_mutex); |
| 4010 | mutex_lock(&mdsc->mutex); |
| 4011 | ceph_con_close(&s->s_con); |
| 4012 | mutex_unlock(&s->s_mutex); |
| 4013 | s->s_state = CEPH_MDS_SESSION_RESTARTING; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4014 | } else if (oldstate == newstate) { |
| 4015 | continue; /* nothing new with this mds */ |
| 4016 | } |
| 4017 | |
| 4018 | /* |
| 4019 | * send reconnect? |
| 4020 | */ |
| 4021 | if (s->s_state == CEPH_MDS_SESSION_RESTARTING && |
Sage Weil | 34b6c85 | 2010-05-10 16:31:25 -0700 | [diff] [blame] | 4022 | newstate >= CEPH_MDS_STATE_RECONNECT) { |
| 4023 | mutex_unlock(&mdsc->mutex); |
| 4024 | send_mds_reconnect(mdsc, s); |
| 4025 | mutex_lock(&mdsc->mutex); |
| 4026 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4027 | |
| 4028 | /* |
Sage Weil | 29790f2 | 2010-03-18 14:45:05 -0700 | [diff] [blame] | 4029 | * kick request on any mds that has gone active. |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4030 | */ |
| 4031 | if (oldstate < CEPH_MDS_STATE_ACTIVE && |
| 4032 | newstate >= CEPH_MDS_STATE_ACTIVE) { |
Sage Weil | 29790f2 | 2010-03-18 14:45:05 -0700 | [diff] [blame] | 4033 | if (oldstate != CEPH_MDS_STATE_CREATING && |
| 4034 | oldstate != CEPH_MDS_STATE_STARTING) |
| 4035 | pr_info("mds%d recovery completed\n", s->s_mds); |
| 4036 | kick_requests(mdsc, i); |
Xiubo Li | ea8412b | 2020-05-20 03:51:19 -0400 | [diff] [blame] | 4037 | mutex_unlock(&mdsc->mutex); |
Jeff Layton | 829ad4d | 2020-04-03 13:09:07 -0400 | [diff] [blame] | 4038 | mutex_lock(&s->s_mutex); |
Xiubo Li | ea8412b | 2020-05-20 03:51:19 -0400 | [diff] [blame] | 4039 | mutex_lock(&mdsc->mutex); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4040 | ceph_kick_flushing_caps(mdsc, s); |
Jeff Layton | 829ad4d | 2020-04-03 13:09:07 -0400 | [diff] [blame] | 4041 | mutex_unlock(&s->s_mutex); |
Yan, Zheng | d2f8bb2 | 2018-12-10 16:35:09 +0800 | [diff] [blame] | 4042 | wake_up_session_caps(s, RECONNECT); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4043 | } |
| 4044 | } |
Sage Weil | cb170a2 | 2010-06-21 13:38:35 -0700 | [diff] [blame] | 4045 | |
Xiubo Li | b38c9eb | 2019-12-04 06:57:39 -0500 | [diff] [blame] | 4046 | for (i = 0; i < newmap->possible_max_rank && i < mdsc->max_sessions; i++) { |
Sage Weil | cb170a2 | 2010-06-21 13:38:35 -0700 | [diff] [blame] | 4047 | s = mdsc->sessions[i]; |
| 4048 | if (!s) |
| 4049 | continue; |
| 4050 | if (!ceph_mdsmap_is_laggy(newmap, i)) |
| 4051 | continue; |
| 4052 | if (s->s_state == CEPH_MDS_SESSION_OPEN || |
| 4053 | s->s_state == CEPH_MDS_SESSION_HUNG || |
| 4054 | s->s_state == CEPH_MDS_SESSION_CLOSING) { |
| 4055 | dout(" connecting to export targets of laggy mds%d\n", |
| 4056 | i); |
| 4057 | __open_export_target_sessions(mdsc, s); |
| 4058 | } |
| 4059 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | |
| 4063 | |
| 4064 | /* |
| 4065 | * leases |
| 4066 | */ |
| 4067 | |
| 4068 | /* |
| 4069 | * caller must hold session s_mutex, dentry->d_lock |
| 4070 | */ |
| 4071 | void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry) |
| 4072 | { |
| 4073 | struct ceph_dentry_info *di = ceph_dentry(dentry); |
| 4074 | |
| 4075 | ceph_put_mds_session(di->lease_session); |
| 4076 | di->lease_session = NULL; |
| 4077 | } |
| 4078 | |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4079 | static void handle_lease(struct ceph_mds_client *mdsc, |
| 4080 | struct ceph_mds_session *session, |
| 4081 | struct ceph_msg *msg) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4082 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4083 | struct super_block *sb = mdsc->fsc->sb; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4084 | struct inode *inode; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4085 | struct dentry *parent, *dentry; |
| 4086 | struct ceph_dentry_info *di; |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4087 | int mds = session->s_mds; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4088 | struct ceph_mds_lease *h = msg->front.iov_base; |
Sage Weil | 1e5ea23 | 2010-06-04 10:05:40 -0700 | [diff] [blame] | 4089 | u32 seq; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4090 | struct ceph_vino vino; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4091 | struct qstr dname; |
| 4092 | int release = 0; |
| 4093 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4094 | dout("handle_lease from mds%d\n", mds); |
| 4095 | |
| 4096 | /* decode */ |
| 4097 | if (msg->front.iov_len < sizeof(*h) + sizeof(u32)) |
| 4098 | goto bad; |
| 4099 | vino.ino = le64_to_cpu(h->ino); |
| 4100 | vino.snap = CEPH_NOSNAP; |
Sage Weil | 1e5ea23 | 2010-06-04 10:05:40 -0700 | [diff] [blame] | 4101 | seq = le32_to_cpu(h->seq); |
Yan, Zheng | 0fcf6c0 | 2018-08-03 16:24:49 +0800 | [diff] [blame] | 4102 | dname.len = get_unaligned_le32(h + 1); |
| 4103 | if (msg->front.iov_len < sizeof(*h) + sizeof(u32) + dname.len) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4104 | goto bad; |
Yan, Zheng | 0fcf6c0 | 2018-08-03 16:24:49 +0800 | [diff] [blame] | 4105 | dname.name = (void *)(h + 1) + sizeof(u32); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4106 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4107 | /* lookup inode */ |
| 4108 | inode = ceph_find_inode(sb, vino); |
Sage Weil | 2f90b85 | 2011-07-26 11:28:25 -0700 | [diff] [blame] | 4109 | dout("handle_lease %s, ino %llx %p %.*s\n", |
| 4110 | ceph_lease_op_name(h->action), vino.ino, inode, |
Sage Weil | 1e5ea23 | 2010-06-04 10:05:40 -0700 | [diff] [blame] | 4111 | dname.len, dname.name); |
Yan, Zheng | 6cd3bca | 2014-09-17 07:45:12 +0800 | [diff] [blame] | 4112 | |
| 4113 | mutex_lock(&session->s_mutex); |
| 4114 | session->s_seq++; |
| 4115 | |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 4116 | if (!inode) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4117 | dout("handle_lease no inode %llx\n", vino.ino); |
| 4118 | goto release; |
| 4119 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4120 | |
| 4121 | /* dentry */ |
| 4122 | parent = d_find_alias(inode); |
| 4123 | if (!parent) { |
| 4124 | dout("no parent dentry on inode %p\n", inode); |
| 4125 | WARN_ON(1); |
| 4126 | goto release; /* hrm... */ |
| 4127 | } |
Linus Torvalds | 8387ff2 | 2016-06-10 07:51:30 -0700 | [diff] [blame] | 4128 | dname.hash = full_name_hash(parent, dname.name, dname.len); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4129 | dentry = d_lookup(parent, &dname); |
| 4130 | dput(parent); |
| 4131 | if (!dentry) |
| 4132 | goto release; |
| 4133 | |
| 4134 | spin_lock(&dentry->d_lock); |
| 4135 | di = ceph_dentry(dentry); |
| 4136 | switch (h->action) { |
| 4137 | case CEPH_MDS_LEASE_REVOKE: |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 4138 | if (di->lease_session == session) { |
Sage Weil | 1e5ea23 | 2010-06-04 10:05:40 -0700 | [diff] [blame] | 4139 | if (ceph_seq_cmp(di->lease_seq, seq) > 0) |
| 4140 | h->seq = cpu_to_le32(di->lease_seq); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4141 | __ceph_mdsc_drop_dentry_lease(dentry); |
| 4142 | } |
| 4143 | release = 1; |
| 4144 | break; |
| 4145 | |
| 4146 | case CEPH_MDS_LEASE_RENEW: |
Sage Weil | 3d8eb7a | 2011-11-11 09:48:53 -0800 | [diff] [blame] | 4147 | if (di->lease_session == session && |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4148 | di->lease_gen == session->s_cap_gen && |
| 4149 | di->lease_renew_from && |
| 4150 | di->lease_renew_after == 0) { |
| 4151 | unsigned long duration = |
Nicholas Mc Guire | 3563dbdd | 2015-02-06 06:52:17 -0500 | [diff] [blame] | 4152 | msecs_to_jiffies(le32_to_cpu(h->duration_ms)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4153 | |
Sage Weil | 1e5ea23 | 2010-06-04 10:05:40 -0700 | [diff] [blame] | 4154 | di->lease_seq = seq; |
Miklos Szeredi | 9b16f03c | 2016-06-22 16:35:04 +0200 | [diff] [blame] | 4155 | di->time = di->lease_renew_from + duration; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4156 | di->lease_renew_after = di->lease_renew_from + |
| 4157 | (duration >> 1); |
| 4158 | di->lease_renew_from = 0; |
| 4159 | } |
| 4160 | break; |
| 4161 | } |
| 4162 | spin_unlock(&dentry->d_lock); |
| 4163 | dput(dentry); |
| 4164 | |
| 4165 | if (!release) |
| 4166 | goto out; |
| 4167 | |
| 4168 | release: |
| 4169 | /* let's just reuse the same message */ |
| 4170 | h->action = CEPH_MDS_LEASE_REVOKE_ACK; |
| 4171 | ceph_msg_get(msg); |
| 4172 | ceph_con_send(&session->s_con, msg); |
| 4173 | |
| 4174 | out: |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4175 | mutex_unlock(&session->s_mutex); |
Yan, Zheng | 3e1d045 | 2019-05-18 20:39:55 +0800 | [diff] [blame] | 4176 | /* avoid calling iput_final() in mds dispatch threads */ |
| 4177 | ceph_async_iput(inode); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4178 | return; |
| 4179 | |
| 4180 | bad: |
| 4181 | pr_err("corrupt lease message\n"); |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 4182 | ceph_msg_dump(msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4186 | struct dentry *dentry, char action, |
| 4187 | u32 seq) |
| 4188 | { |
| 4189 | struct ceph_msg *msg; |
| 4190 | struct ceph_mds_lease *lease; |
Yan, Zheng | 8f2a98ef | 2019-05-23 10:45:24 +0800 | [diff] [blame] | 4191 | struct inode *dir; |
| 4192 | int len = sizeof(*lease) + sizeof(u32) + NAME_MAX; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4193 | |
Yan, Zheng | 8f2a98ef | 2019-05-23 10:45:24 +0800 | [diff] [blame] | 4194 | dout("lease_send_msg identry %p %s to mds%d\n", |
| 4195 | dentry, ceph_lease_op_name(action), session->s_mds); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4196 | |
Sage Weil | b61c276 | 2011-08-09 15:03:46 -0700 | [diff] [blame] | 4197 | msg = ceph_msg_new(CEPH_MSG_CLIENT_LEASE, len, GFP_NOFS, false); |
Sage Weil | a79832f | 2010-04-01 16:06:19 -0700 | [diff] [blame] | 4198 | if (!msg) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4199 | return; |
| 4200 | lease = msg->front.iov_base; |
| 4201 | lease->action = action; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4202 | lease->seq = cpu_to_le32(seq); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4203 | |
Yan, Zheng | 8f2a98ef | 2019-05-23 10:45:24 +0800 | [diff] [blame] | 4204 | spin_lock(&dentry->d_lock); |
| 4205 | dir = d_inode(dentry->d_parent); |
| 4206 | lease->ino = cpu_to_le64(ceph_ino(dir)); |
| 4207 | lease->first = lease->last = cpu_to_le64(ceph_snap(dir)); |
| 4208 | |
| 4209 | put_unaligned_le32(dentry->d_name.len, lease + 1); |
| 4210 | memcpy((void *)(lease + 1) + 4, |
| 4211 | dentry->d_name.name, dentry->d_name.len); |
| 4212 | spin_unlock(&dentry->d_lock); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4213 | /* |
| 4214 | * if this is a preemptive lease RELEASE, no need to |
| 4215 | * flush request stream, since the actual request will |
| 4216 | * soon follow. |
| 4217 | */ |
| 4218 | msg->more_to_follow = (action == CEPH_MDS_LEASE_RELEASE); |
| 4219 | |
| 4220 | ceph_con_send(&session->s_con, msg); |
| 4221 | } |
| 4222 | |
| 4223 | /* |
Yan, Zheng | 7aac453 | 2018-03-13 19:52:20 +0800 | [diff] [blame] | 4224 | * lock unlock sessions, to wait ongoing session activities |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4225 | */ |
Yan, Zheng | 7aac453 | 2018-03-13 19:52:20 +0800 | [diff] [blame] | 4226 | static void lock_unlock_sessions(struct ceph_mds_client *mdsc) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4227 | { |
| 4228 | int i; |
| 4229 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4230 | mutex_lock(&mdsc->mutex); |
| 4231 | for (i = 0; i < mdsc->max_sessions; i++) { |
| 4232 | struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); |
| 4233 | if (!s) |
| 4234 | continue; |
| 4235 | mutex_unlock(&mdsc->mutex); |
| 4236 | mutex_lock(&s->s_mutex); |
| 4237 | mutex_unlock(&s->s_mutex); |
| 4238 | ceph_put_mds_session(s); |
| 4239 | mutex_lock(&mdsc->mutex); |
| 4240 | } |
| 4241 | mutex_unlock(&mdsc->mutex); |
| 4242 | } |
| 4243 | |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 4244 | static void maybe_recover_session(struct ceph_mds_client *mdsc) |
| 4245 | { |
| 4246 | struct ceph_fs_client *fsc = mdsc->fsc; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4247 | |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 4248 | if (!ceph_test_mount_opt(fsc, CLEANRECOVER)) |
| 4249 | return; |
| 4250 | |
| 4251 | if (READ_ONCE(fsc->mount_state) != CEPH_MOUNT_MOUNTED) |
| 4252 | return; |
| 4253 | |
| 4254 | if (!READ_ONCE(fsc->blacklisted)) |
| 4255 | return; |
| 4256 | |
| 4257 | if (fsc->last_auto_reconnect && |
| 4258 | time_before(jiffies, fsc->last_auto_reconnect + HZ * 60 * 30)) |
| 4259 | return; |
| 4260 | |
| 4261 | pr_info("auto reconnect after blacklisted\n"); |
| 4262 | fsc->last_auto_reconnect = jiffies; |
| 4263 | ceph_force_reconnect(fsc->sb); |
| 4264 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4265 | |
Xiubo Li | 3e699bd | 2020-06-30 03:52:15 -0400 | [diff] [blame] | 4266 | bool check_session_state(struct ceph_mds_session *s) |
| 4267 | { |
| 4268 | if (s->s_state == CEPH_MDS_SESSION_CLOSING) { |
| 4269 | dout("resending session close request for mds%d\n", |
| 4270 | s->s_mds); |
| 4271 | request_close_session(s); |
| 4272 | return false; |
| 4273 | } |
| 4274 | if (s->s_ttl && time_after(jiffies, s->s_ttl)) { |
| 4275 | if (s->s_state == CEPH_MDS_SESSION_OPEN) { |
| 4276 | s->s_state = CEPH_MDS_SESSION_HUNG; |
| 4277 | pr_info("mds%d hung\n", s->s_mds); |
| 4278 | } |
| 4279 | } |
| 4280 | if (s->s_state == CEPH_MDS_SESSION_NEW || |
| 4281 | s->s_state == CEPH_MDS_SESSION_RESTARTING || |
| 4282 | s->s_state == CEPH_MDS_SESSION_REJECTED) |
| 4283 | /* this mds is failed or recovering, just wait */ |
| 4284 | return false; |
| 4285 | |
| 4286 | return true; |
| 4287 | } |
| 4288 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4289 | /* |
| 4290 | * delayed work -- periodically trim expired leases, renew caps with mds |
| 4291 | */ |
| 4292 | static void schedule_delayed(struct ceph_mds_client *mdsc) |
| 4293 | { |
| 4294 | int delay = 5; |
| 4295 | unsigned hz = round_jiffies_relative(HZ * delay); |
| 4296 | schedule_delayed_work(&mdsc->delayed_work, hz); |
| 4297 | } |
| 4298 | |
| 4299 | static void delayed_work(struct work_struct *work) |
| 4300 | { |
| 4301 | int i; |
| 4302 | struct ceph_mds_client *mdsc = |
| 4303 | container_of(work, struct ceph_mds_client, delayed_work.work); |
| 4304 | int renew_interval; |
| 4305 | int renew_caps; |
| 4306 | |
| 4307 | dout("mdsc delayed_work\n"); |
Yan, Zheng | 75c9627 | 2017-12-14 15:11:09 +0800 | [diff] [blame] | 4308 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4309 | mutex_lock(&mdsc->mutex); |
| 4310 | renew_interval = mdsc->mdsmap->m_session_timeout >> 2; |
| 4311 | renew_caps = time_after_eq(jiffies, HZ*renew_interval + |
| 4312 | mdsc->last_renew_caps); |
| 4313 | if (renew_caps) |
| 4314 | mdsc->last_renew_caps = jiffies; |
| 4315 | |
| 4316 | for (i = 0; i < mdsc->max_sessions; i++) { |
| 4317 | struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 4318 | if (!s) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4319 | continue; |
Xiubo Li | 3e699bd | 2020-06-30 03:52:15 -0400 | [diff] [blame] | 4320 | |
| 4321 | if (!check_session_state(s)) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4322 | ceph_put_mds_session(s); |
| 4323 | continue; |
| 4324 | } |
| 4325 | mutex_unlock(&mdsc->mutex); |
| 4326 | |
| 4327 | mutex_lock(&s->s_mutex); |
| 4328 | if (renew_caps) |
| 4329 | send_renew_caps(mdsc, s); |
| 4330 | else |
| 4331 | ceph_con_keepalive(&s->s_con); |
Sage Weil | aab53dd | 2010-03-17 16:30:21 -0700 | [diff] [blame] | 4332 | if (s->s_state == CEPH_MDS_SESSION_OPEN || |
| 4333 | s->s_state == CEPH_MDS_SESSION_HUNG) |
Sage Weil | 3d7ded4 | 2010-06-09 16:47:10 -0700 | [diff] [blame] | 4334 | ceph_send_cap_releases(mdsc, s); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4335 | mutex_unlock(&s->s_mutex); |
| 4336 | ceph_put_mds_session(s); |
| 4337 | |
| 4338 | mutex_lock(&mdsc->mutex); |
| 4339 | } |
| 4340 | mutex_unlock(&mdsc->mutex); |
| 4341 | |
Yan, Zheng | 37c4efc | 2019-01-31 16:55:51 +0800 | [diff] [blame] | 4342 | ceph_check_delayed_caps(mdsc); |
| 4343 | |
| 4344 | ceph_queue_cap_reclaim_work(mdsc); |
| 4345 | |
| 4346 | ceph_trim_snapid_map(mdsc); |
| 4347 | |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 4348 | maybe_recover_session(mdsc); |
| 4349 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4350 | schedule_delayed(mdsc); |
| 4351 | } |
| 4352 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4353 | int ceph_mdsc_init(struct ceph_fs_client *fsc) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4354 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4355 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4356 | struct ceph_mds_client *mdsc; |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 4357 | int err; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4358 | |
| 4359 | mdsc = kzalloc(sizeof(struct ceph_mds_client), GFP_NOFS); |
| 4360 | if (!mdsc) |
| 4361 | return -ENOMEM; |
| 4362 | mdsc->fsc = fsc; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4363 | mutex_init(&mdsc->mutex); |
| 4364 | mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 4365 | if (!mdsc->mdsmap) { |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 4366 | err = -ENOMEM; |
| 4367 | goto err_mdsc; |
majianpeng | fb3101b | 2013-06-25 14:48:19 +0800 | [diff] [blame] | 4368 | } |
Cheng Renquan | 2d06eeb | 2010-03-26 18:04:40 +0800 | [diff] [blame] | 4369 | |
Chengguang Xu | 50c55ae | 2018-03-14 13:47:33 +0800 | [diff] [blame] | 4370 | fsc->mdsc = mdsc; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4371 | init_completion(&mdsc->safe_umount_waiters); |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4372 | init_waitqueue_head(&mdsc->session_close_wq); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4373 | INIT_LIST_HEAD(&mdsc->waiting_for_map); |
| 4374 | mdsc->sessions = NULL; |
Yan, Zheng | 86d8f67 | 2015-01-09 17:00:42 +0800 | [diff] [blame] | 4375 | atomic_set(&mdsc->num_sessions, 0); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4376 | mdsc->max_sessions = 0; |
| 4377 | mdsc->stopping = 0; |
Luis Henriques | d557c48 | 2018-01-12 17:19:29 +0000 | [diff] [blame] | 4378 | atomic64_set(&mdsc->quotarealms_count, 0); |
Luis Henriques | 0c44a8e | 2019-03-21 10:20:10 +0000 | [diff] [blame] | 4379 | mdsc->quotarealms_inodes = RB_ROOT; |
| 4380 | mutex_init(&mdsc->quotarealms_inodes_mutex); |
Yan, Zheng | affbc19 | 2015-05-05 21:22:13 +0800 | [diff] [blame] | 4381 | mdsc->last_snap_seq = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4382 | init_rwsem(&mdsc->snap_rwsem); |
Sage Weil | a105f00 | 2010-02-15 14:37:55 -0800 | [diff] [blame] | 4383 | mdsc->snap_realms = RB_ROOT; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4384 | INIT_LIST_HEAD(&mdsc->snap_empty); |
Yan, Zheng | 81c5a14 | 2019-01-01 16:28:33 +0800 | [diff] [blame] | 4385 | mdsc->num_snap_realms = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4386 | spin_lock_init(&mdsc->snap_empty_lock); |
| 4387 | mdsc->last_tid = 0; |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 4388 | mdsc->oldest_tid = 0; |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4389 | mdsc->request_tree = RB_ROOT; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4390 | INIT_DELAYED_WORK(&mdsc->delayed_work, delayed_work); |
| 4391 | mdsc->last_renew_caps = jiffies; |
| 4392 | INIT_LIST_HEAD(&mdsc->cap_delay_list); |
Jeff Layton | 3a3430a | 2019-11-20 12:00:59 -0500 | [diff] [blame] | 4393 | INIT_LIST_HEAD(&mdsc->cap_wait_list); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4394 | spin_lock_init(&mdsc->cap_delay_lock); |
| 4395 | INIT_LIST_HEAD(&mdsc->snap_flush_list); |
| 4396 | spin_lock_init(&mdsc->snap_flush_lock); |
Yan, Zheng | 553adfd | 2015-06-09 15:48:57 +0800 | [diff] [blame] | 4397 | mdsc->last_cap_flush_tid = 1; |
Yan, Zheng | e4500b5 | 2016-07-06 11:12:56 +0800 | [diff] [blame] | 4398 | INIT_LIST_HEAD(&mdsc->cap_flush_list); |
Sage Weil | db35405 | 2011-05-24 11:46:31 -0700 | [diff] [blame] | 4399 | INIT_LIST_HEAD(&mdsc->cap_dirty_migrating); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4400 | mdsc->num_cap_flushing = 0; |
| 4401 | spin_lock_init(&mdsc->cap_dirty_lock); |
| 4402 | init_waitqueue_head(&mdsc->cap_flushing_wq); |
Yan, Zheng | 37c4efc | 2019-01-31 16:55:51 +0800 | [diff] [blame] | 4403 | INIT_WORK(&mdsc->cap_reclaim_work, ceph_cap_reclaim_work); |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 4404 | atomic_set(&mdsc->cap_reclaim_pending, 0); |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 4405 | err = ceph_metric_init(&mdsc->metric); |
| 4406 | if (err) |
| 4407 | goto err_mdsmap; |
Yan, Zheng | 37c4efc | 2019-01-31 16:55:51 +0800 | [diff] [blame] | 4408 | |
| 4409 | spin_lock_init(&mdsc->dentry_list_lock); |
| 4410 | INIT_LIST_HEAD(&mdsc->dentry_leases); |
| 4411 | INIT_LIST_HEAD(&mdsc->dentry_dir_leases); |
Cheng Renquan | 2d06eeb | 2010-03-26 18:04:40 +0800 | [diff] [blame] | 4412 | |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 4413 | ceph_caps_init(mdsc); |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 4414 | ceph_adjust_caps_max_min(mdsc, fsc->mount_options); |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 4415 | |
Yan, Zheng | 75c9627 | 2017-12-14 15:11:09 +0800 | [diff] [blame] | 4416 | spin_lock_init(&mdsc->snapid_map_lock); |
| 4417 | mdsc->snapid_map_tree = RB_ROOT; |
| 4418 | INIT_LIST_HEAD(&mdsc->snapid_map_lru); |
| 4419 | |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 4420 | init_rwsem(&mdsc->pool_perm_rwsem); |
| 4421 | mdsc->pool_perm_tree = RB_ROOT; |
| 4422 | |
Yan, Zheng | dfeb84d | 2018-07-02 15:55:23 +0800 | [diff] [blame] | 4423 | strscpy(mdsc->nodename, utsname()->nodename, |
| 4424 | sizeof(mdsc->nodename)); |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 4425 | return 0; |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 4426 | |
| 4427 | err_mdsmap: |
| 4428 | kfree(mdsc->mdsmap); |
| 4429 | err_mdsc: |
| 4430 | kfree(mdsc); |
| 4431 | return err; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /* |
| 4435 | * Wait for safe replies on open mds requests. If we time out, drop |
| 4436 | * all requests from the tree to avoid dangling dentry refs. |
| 4437 | */ |
| 4438 | static void wait_requests(struct ceph_mds_client *mdsc) |
| 4439 | { |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 4440 | struct ceph_options *opts = mdsc->fsc->client->options; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4441 | struct ceph_mds_request *req; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4442 | |
| 4443 | mutex_lock(&mdsc->mutex); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4444 | if (__get_oldest_req(mdsc)) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4445 | mutex_unlock(&mdsc->mutex); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4446 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4447 | dout("wait_requests waiting for requests\n"); |
| 4448 | wait_for_completion_timeout(&mdsc->safe_umount_waiters, |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 4449 | ceph_timeout_jiffies(opts->mount_timeout)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4450 | |
| 4451 | /* tear down remaining requests */ |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4452 | mutex_lock(&mdsc->mutex); |
| 4453 | while ((req = __get_oldest_req(mdsc))) { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4454 | dout("wait_requests timed out on tid %llu\n", |
| 4455 | req->r_tid); |
Yan, Zheng | 428138c | 2019-06-14 10:55:05 +0800 | [diff] [blame] | 4456 | list_del_init(&req->r_wait); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4457 | __unregister_request(mdsc, req); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4458 | } |
| 4459 | } |
| 4460 | mutex_unlock(&mdsc->mutex); |
| 4461 | dout("wait_requests done\n"); |
| 4462 | } |
| 4463 | |
| 4464 | /* |
| 4465 | * called before mount is ro, and before dentries are torn down. |
| 4466 | * (hmm, does this still race with new lookups?) |
| 4467 | */ |
| 4468 | void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc) |
| 4469 | { |
| 4470 | dout("pre_umount\n"); |
| 4471 | mdsc->stopping = 1; |
| 4472 | |
Yan, Zheng | 7aac453 | 2018-03-13 19:52:20 +0800 | [diff] [blame] | 4473 | lock_unlock_sessions(mdsc); |
Sage Weil | afcdaea | 2009-10-14 14:27:38 -0700 | [diff] [blame] | 4474 | ceph_flush_dirty_caps(mdsc); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4475 | wait_requests(mdsc); |
Sage Weil | 17c688c | 2010-06-21 16:12:26 -0700 | [diff] [blame] | 4476 | |
| 4477 | /* |
| 4478 | * wait for reply handlers to drop their request refs and |
| 4479 | * their inode/dcache refs |
| 4480 | */ |
| 4481 | ceph_msgr_flush(); |
Luis Henriques | 0c44a8e | 2019-03-21 10:20:10 +0000 | [diff] [blame] | 4482 | |
| 4483 | ceph_cleanup_quotarealms_inodes(mdsc); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | /* |
| 4487 | * wait for all write mds requests to flush. |
| 4488 | */ |
| 4489 | static void wait_unsafe_requests(struct ceph_mds_client *mdsc, u64 want_tid) |
| 4490 | { |
Sage Weil | 80fc731 | 2010-03-16 15:28:54 -0700 | [diff] [blame] | 4491 | struct ceph_mds_request *req = NULL, *nextreq; |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4492 | struct rb_node *n; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4493 | |
| 4494 | mutex_lock(&mdsc->mutex); |
| 4495 | dout("wait_unsafe_requests want %lld\n", want_tid); |
Sage Weil | 80fc731 | 2010-03-16 15:28:54 -0700 | [diff] [blame] | 4496 | restart: |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4497 | req = __get_oldest_req(mdsc); |
| 4498 | while (req && req->r_tid <= want_tid) { |
Sage Weil | 80fc731 | 2010-03-16 15:28:54 -0700 | [diff] [blame] | 4499 | /* find next request */ |
| 4500 | n = rb_next(&req->r_node); |
| 4501 | if (n) |
| 4502 | nextreq = rb_entry(n, struct ceph_mds_request, r_node); |
| 4503 | else |
| 4504 | nextreq = NULL; |
Yan, Zheng | e8a7b8b | 2015-05-19 18:54:40 +0800 | [diff] [blame] | 4505 | if (req->r_op != CEPH_MDS_OP_SETFILELOCK && |
| 4506 | (req->r_op & CEPH_MDS_OP_WRITE)) { |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4507 | /* write op */ |
| 4508 | ceph_mdsc_get_request(req); |
Sage Weil | 80fc731 | 2010-03-16 15:28:54 -0700 | [diff] [blame] | 4509 | if (nextreq) |
| 4510 | ceph_mdsc_get_request(nextreq); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4511 | mutex_unlock(&mdsc->mutex); |
| 4512 | dout("wait_unsafe_requests wait on %llu (want %llu)\n", |
| 4513 | req->r_tid, want_tid); |
| 4514 | wait_for_completion(&req->r_safe_completion); |
| 4515 | mutex_lock(&mdsc->mutex); |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4516 | ceph_mdsc_put_request(req); |
Sage Weil | 80fc731 | 2010-03-16 15:28:54 -0700 | [diff] [blame] | 4517 | if (!nextreq) |
| 4518 | break; /* next dne before, so we're done! */ |
| 4519 | if (RB_EMPTY_NODE(&nextreq->r_node)) { |
| 4520 | /* next request was removed from tree */ |
| 4521 | ceph_mdsc_put_request(nextreq); |
| 4522 | goto restart; |
| 4523 | } |
| 4524 | ceph_mdsc_put_request(nextreq); /* won't go away */ |
Sage Weil | 44ca18f | 2010-02-15 12:08:46 -0800 | [diff] [blame] | 4525 | } |
Sage Weil | 80fc731 | 2010-03-16 15:28:54 -0700 | [diff] [blame] | 4526 | req = nextreq; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4527 | } |
| 4528 | mutex_unlock(&mdsc->mutex); |
| 4529 | dout("wait_unsafe_requests done\n"); |
| 4530 | } |
| 4531 | |
| 4532 | void ceph_mdsc_sync(struct ceph_mds_client *mdsc) |
| 4533 | { |
Yan, Zheng | 0e29438 | 2016-07-04 18:06:41 +0800 | [diff] [blame] | 4534 | u64 want_tid, want_flush; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4535 | |
Seraphime Kirkovski | 52953d5 | 2016-12-26 10:26:34 +0100 | [diff] [blame] | 4536 | if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) |
Sage Weil | 56b7cf9 | 2010-05-03 15:22:00 -0700 | [diff] [blame] | 4537 | return; |
| 4538 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4539 | dout("sync\n"); |
| 4540 | mutex_lock(&mdsc->mutex); |
| 4541 | want_tid = mdsc->last_tid; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4542 | mutex_unlock(&mdsc->mutex); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4543 | |
Sage Weil | afcdaea | 2009-10-14 14:27:38 -0700 | [diff] [blame] | 4544 | ceph_flush_dirty_caps(mdsc); |
Yan, Zheng | d3383a8 | 2015-01-08 21:30:12 +0800 | [diff] [blame] | 4545 | spin_lock(&mdsc->cap_dirty_lock); |
Yan, Zheng | 8310b08 | 2015-06-09 17:20:12 +0800 | [diff] [blame] | 4546 | want_flush = mdsc->last_cap_flush_tid; |
Yan, Zheng | c8799fc | 2016-07-07 15:22:38 +0800 | [diff] [blame] | 4547 | if (!list_empty(&mdsc->cap_flush_list)) { |
| 4548 | struct ceph_cap_flush *cf = |
| 4549 | list_last_entry(&mdsc->cap_flush_list, |
| 4550 | struct ceph_cap_flush, g_list); |
| 4551 | cf->wake = true; |
| 4552 | } |
Yan, Zheng | d3383a8 | 2015-01-08 21:30:12 +0800 | [diff] [blame] | 4553 | spin_unlock(&mdsc->cap_dirty_lock); |
| 4554 | |
Yan, Zheng | 0e29438 | 2016-07-04 18:06:41 +0800 | [diff] [blame] | 4555 | dout("sync want tid %lld flush_seq %lld\n", |
| 4556 | want_tid, want_flush); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4557 | |
| 4558 | wait_unsafe_requests(mdsc, want_tid); |
Yan, Zheng | 0e29438 | 2016-07-04 18:06:41 +0800 | [diff] [blame] | 4559 | wait_caps_flush(mdsc, want_flush); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4560 | } |
| 4561 | |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4562 | /* |
| 4563 | * true if all sessions are closed, or we force unmount |
| 4564 | */ |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 4565 | static bool done_closing_sessions(struct ceph_mds_client *mdsc, int skipped) |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4566 | { |
Seraphime Kirkovski | 52953d5 | 2016-12-26 10:26:34 +0100 | [diff] [blame] | 4567 | if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4568 | return true; |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 4569 | return atomic_read(&mdsc->num_sessions) <= skipped; |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4570 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4571 | |
| 4572 | /* |
| 4573 | * called after sb is ro. |
| 4574 | */ |
| 4575 | void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc) |
| 4576 | { |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 4577 | struct ceph_options *opts = mdsc->fsc->client->options; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4578 | struct ceph_mds_session *session; |
| 4579 | int i; |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 4580 | int skipped = 0; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4581 | |
| 4582 | dout("close_sessions\n"); |
| 4583 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4584 | /* close sessions */ |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4585 | mutex_lock(&mdsc->mutex); |
| 4586 | for (i = 0; i < mdsc->max_sessions; i++) { |
| 4587 | session = __ceph_lookup_mds_session(mdsc, i); |
| 4588 | if (!session) |
| 4589 | continue; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4590 | mutex_unlock(&mdsc->mutex); |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4591 | mutex_lock(&session->s_mutex); |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 4592 | if (__close_session(mdsc, session) <= 0) |
| 4593 | skipped++; |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4594 | mutex_unlock(&session->s_mutex); |
| 4595 | ceph_put_mds_session(session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4596 | mutex_lock(&mdsc->mutex); |
| 4597 | } |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4598 | mutex_unlock(&mdsc->mutex); |
| 4599 | |
| 4600 | dout("waiting for sessions to close\n"); |
Yan, Zheng | fcff415 | 2016-09-14 16:39:51 +0800 | [diff] [blame] | 4601 | wait_event_timeout(mdsc->session_close_wq, |
| 4602 | done_closing_sessions(mdsc, skipped), |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 4603 | ceph_timeout_jiffies(opts->mount_timeout)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4604 | |
| 4605 | /* tear down remaining sessions */ |
Sage Weil | f3c60c5 | 2010-08-11 14:51:23 -0700 | [diff] [blame] | 4606 | mutex_lock(&mdsc->mutex); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4607 | for (i = 0; i < mdsc->max_sessions; i++) { |
| 4608 | if (mdsc->sessions[i]) { |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 4609 | session = ceph_get_mds_session(mdsc->sessions[i]); |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4610 | __unregister_session(mdsc, session); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4611 | mutex_unlock(&mdsc->mutex); |
| 4612 | mutex_lock(&session->s_mutex); |
| 4613 | remove_session_caps(session); |
| 4614 | mutex_unlock(&session->s_mutex); |
| 4615 | ceph_put_mds_session(session); |
| 4616 | mutex_lock(&mdsc->mutex); |
| 4617 | } |
| 4618 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4619 | WARN_ON(!list_empty(&mdsc->cap_delay_list)); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4620 | mutex_unlock(&mdsc->mutex); |
| 4621 | |
Yan, Zheng | 75c9627 | 2017-12-14 15:11:09 +0800 | [diff] [blame] | 4622 | ceph_cleanup_snapid_map(mdsc); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4623 | ceph_cleanup_empty_realms(mdsc); |
| 4624 | |
Yan, Zheng | 37c4efc | 2019-01-31 16:55:51 +0800 | [diff] [blame] | 4625 | cancel_work_sync(&mdsc->cap_reclaim_work); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4626 | cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ |
| 4627 | |
| 4628 | dout("stopped\n"); |
| 4629 | } |
| 4630 | |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 4631 | void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc) |
| 4632 | { |
| 4633 | struct ceph_mds_session *session; |
| 4634 | int mds; |
| 4635 | |
| 4636 | dout("force umount\n"); |
| 4637 | |
| 4638 | mutex_lock(&mdsc->mutex); |
| 4639 | for (mds = 0; mds < mdsc->max_sessions; mds++) { |
| 4640 | session = __ceph_lookup_mds_session(mdsc, mds); |
| 4641 | if (!session) |
| 4642 | continue; |
Yan, Zheng | d468e72 | 2019-07-25 20:16:44 +0800 | [diff] [blame] | 4643 | |
| 4644 | if (session->s_state == CEPH_MDS_SESSION_REJECTED) |
| 4645 | __unregister_session(mdsc, session); |
| 4646 | __wake_requests(mdsc, &session->s_waiting); |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 4647 | mutex_unlock(&mdsc->mutex); |
Yan, Zheng | d468e72 | 2019-07-25 20:16:44 +0800 | [diff] [blame] | 4648 | |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 4649 | mutex_lock(&session->s_mutex); |
| 4650 | __close_session(mdsc, session); |
| 4651 | if (session->s_state == CEPH_MDS_SESSION_CLOSING) { |
| 4652 | cleanup_session_requests(mdsc, session); |
| 4653 | remove_session_caps(session); |
| 4654 | } |
| 4655 | mutex_unlock(&session->s_mutex); |
| 4656 | ceph_put_mds_session(session); |
Yan, Zheng | d468e72 | 2019-07-25 20:16:44 +0800 | [diff] [blame] | 4657 | |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 4658 | mutex_lock(&mdsc->mutex); |
| 4659 | kick_requests(mdsc, mds); |
| 4660 | } |
| 4661 | __wake_requests(mdsc, &mdsc->waiting_for_map); |
| 4662 | mutex_unlock(&mdsc->mutex); |
| 4663 | } |
| 4664 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4665 | static void ceph_mdsc_stop(struct ceph_mds_client *mdsc) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4666 | { |
| 4667 | dout("stop\n"); |
| 4668 | cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */ |
| 4669 | if (mdsc->mdsmap) |
| 4670 | ceph_mdsmap_destroy(mdsc->mdsmap); |
| 4671 | kfree(mdsc->sessions); |
Yehuda Sadeh | 3715166 | 2010-06-17 16:16:12 -0700 | [diff] [blame] | 4672 | ceph_caps_finalize(mdsc); |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 4673 | ceph_pool_perm_destroy(mdsc); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4676 | void ceph_mdsc_destroy(struct ceph_fs_client *fsc) |
| 4677 | { |
| 4678 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | ef550f6 | 2011-03-25 13:27:48 -0700 | [diff] [blame] | 4679 | dout("mdsc_destroy %p\n", mdsc); |
Sage Weil | ef550f6 | 2011-03-25 13:27:48 -0700 | [diff] [blame] | 4680 | |
Chengguang Xu | 50c55ae | 2018-03-14 13:47:33 +0800 | [diff] [blame] | 4681 | if (!mdsc) |
| 4682 | return; |
| 4683 | |
Sage Weil | ef550f6 | 2011-03-25 13:27:48 -0700 | [diff] [blame] | 4684 | /* flush out any connection work with references to us */ |
| 4685 | ceph_msgr_flush(); |
| 4686 | |
Yan, Zheng | 62a65f3 | 2017-06-22 16:26:34 +0800 | [diff] [blame] | 4687 | ceph_mdsc_stop(mdsc); |
| 4688 | |
Xiubo Li | f9009ef | 2020-03-19 23:44:59 -0400 | [diff] [blame] | 4689 | ceph_metric_destroy(&mdsc->metric); |
| 4690 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4691 | fsc->mdsc = NULL; |
| 4692 | kfree(mdsc); |
Sage Weil | ef550f6 | 2011-03-25 13:27:48 -0700 | [diff] [blame] | 4693 | dout("mdsc_destroy %p done\n", mdsc); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4694 | } |
| 4695 | |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 4696 | void ceph_mdsc_handle_fsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) |
| 4697 | { |
| 4698 | struct ceph_fs_client *fsc = mdsc->fsc; |
| 4699 | const char *mds_namespace = fsc->mount_options->mds_namespace; |
| 4700 | void *p = msg->front.iov_base; |
| 4701 | void *end = p + msg->front.iov_len; |
| 4702 | u32 epoch; |
| 4703 | u32 map_len; |
| 4704 | u32 num_fs; |
| 4705 | u32 mount_fscid = (u32)-1; |
| 4706 | u8 struct_v, struct_cv; |
| 4707 | int err = -EINVAL; |
| 4708 | |
| 4709 | ceph_decode_need(&p, end, sizeof(u32), bad); |
| 4710 | epoch = ceph_decode_32(&p); |
| 4711 | |
| 4712 | dout("handle_fsmap epoch %u\n", epoch); |
| 4713 | |
| 4714 | ceph_decode_need(&p, end, 2 + sizeof(u32), bad); |
| 4715 | struct_v = ceph_decode_8(&p); |
| 4716 | struct_cv = ceph_decode_8(&p); |
| 4717 | map_len = ceph_decode_32(&p); |
| 4718 | |
| 4719 | ceph_decode_need(&p, end, sizeof(u32) * 3, bad); |
| 4720 | p += sizeof(u32) * 2; /* skip epoch and legacy_client_fscid */ |
| 4721 | |
| 4722 | num_fs = ceph_decode_32(&p); |
| 4723 | while (num_fs-- > 0) { |
| 4724 | void *info_p, *info_end; |
| 4725 | u32 info_len; |
| 4726 | u8 info_v, info_cv; |
| 4727 | u32 fscid, namelen; |
| 4728 | |
| 4729 | ceph_decode_need(&p, end, 2 + sizeof(u32), bad); |
| 4730 | info_v = ceph_decode_8(&p); |
| 4731 | info_cv = ceph_decode_8(&p); |
| 4732 | info_len = ceph_decode_32(&p); |
| 4733 | ceph_decode_need(&p, end, info_len, bad); |
| 4734 | info_p = p; |
| 4735 | info_end = p + info_len; |
| 4736 | p = info_end; |
| 4737 | |
| 4738 | ceph_decode_need(&info_p, info_end, sizeof(u32) * 2, bad); |
| 4739 | fscid = ceph_decode_32(&info_p); |
| 4740 | namelen = ceph_decode_32(&info_p); |
| 4741 | ceph_decode_need(&info_p, info_end, namelen, bad); |
| 4742 | |
| 4743 | if (mds_namespace && |
| 4744 | strlen(mds_namespace) == namelen && |
| 4745 | !strncmp(mds_namespace, (char *)info_p, namelen)) { |
| 4746 | mount_fscid = fscid; |
| 4747 | break; |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | ceph_monc_got_map(&fsc->client->monc, CEPH_SUB_FSMAP, epoch); |
| 4752 | if (mount_fscid != (u32)-1) { |
| 4753 | fsc->client->monc.fs_cluster_id = mount_fscid; |
| 4754 | ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP, |
| 4755 | 0, true); |
| 4756 | ceph_monc_renew_subs(&fsc->client->monc); |
| 4757 | } else { |
| 4758 | err = -ENOENT; |
| 4759 | goto err_out; |
| 4760 | } |
| 4761 | return; |
Ilya Dryomov | 76bd6ec | 2017-10-16 10:32:50 +0200 | [diff] [blame] | 4762 | |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 4763 | bad: |
| 4764 | pr_err("error decoding fsmap\n"); |
| 4765 | err_out: |
| 4766 | mutex_lock(&mdsc->mutex); |
Ilya Dryomov | 76bd6ec | 2017-10-16 10:32:50 +0200 | [diff] [blame] | 4767 | mdsc->mdsmap_err = err; |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 4768 | __wake_requests(mdsc, &mdsc->waiting_for_map); |
| 4769 | mutex_unlock(&mdsc->mutex); |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 4770 | } |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4771 | |
| 4772 | /* |
| 4773 | * handle mds map update. |
| 4774 | */ |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 4775 | void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4776 | { |
| 4777 | u32 epoch; |
| 4778 | u32 maplen; |
| 4779 | void *p = msg->front.iov_base; |
| 4780 | void *end = p + msg->front.iov_len; |
| 4781 | struct ceph_mdsmap *newmap, *oldmap; |
| 4782 | struct ceph_fsid fsid; |
| 4783 | int err = -EINVAL; |
| 4784 | |
| 4785 | ceph_decode_need(&p, end, sizeof(fsid)+2*sizeof(u32), bad); |
| 4786 | ceph_decode_copy(&p, &fsid, sizeof(fsid)); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4787 | if (ceph_check_fsid(mdsc->fsc->client, &fsid) < 0) |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 4788 | return; |
Sage Weil | c89136e | 2009-10-14 09:59:09 -0700 | [diff] [blame] | 4789 | epoch = ceph_decode_32(&p); |
| 4790 | maplen = ceph_decode_32(&p); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4791 | dout("handle_map epoch %u len %d\n", epoch, (int)maplen); |
| 4792 | |
| 4793 | /* do we need it? */ |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4794 | mutex_lock(&mdsc->mutex); |
| 4795 | if (mdsc->mdsmap && epoch <= mdsc->mdsmap->m_epoch) { |
| 4796 | dout("handle_map epoch %u <= our %u\n", |
| 4797 | epoch, mdsc->mdsmap->m_epoch); |
| 4798 | mutex_unlock(&mdsc->mutex); |
| 4799 | return; |
| 4800 | } |
| 4801 | |
| 4802 | newmap = ceph_mdsmap_decode(&p, end); |
| 4803 | if (IS_ERR(newmap)) { |
| 4804 | err = PTR_ERR(newmap); |
| 4805 | goto bad_unlock; |
| 4806 | } |
| 4807 | |
| 4808 | /* swap into place */ |
| 4809 | if (mdsc->mdsmap) { |
| 4810 | oldmap = mdsc->mdsmap; |
| 4811 | mdsc->mdsmap = newmap; |
| 4812 | check_new_map(mdsc, newmap, oldmap); |
| 4813 | ceph_mdsmap_destroy(oldmap); |
| 4814 | } else { |
| 4815 | mdsc->mdsmap = newmap; /* first mds map */ |
| 4816 | } |
Chengguang Xu | 719784b | 2018-07-19 22:15:24 +0800 | [diff] [blame] | 4817 | mdsc->fsc->max_file_size = min((loff_t)mdsc->mdsmap->m_max_file_size, |
| 4818 | MAX_LFS_FILESIZE); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4819 | |
| 4820 | __wake_requests(mdsc, &mdsc->waiting_for_map); |
Ilya Dryomov | 82dcaba | 2016-01-19 16:19:06 +0100 | [diff] [blame] | 4821 | ceph_monc_got_map(&mdsc->fsc->client->monc, CEPH_SUB_MDSMAP, |
| 4822 | mdsc->mdsmap->m_epoch); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4823 | |
| 4824 | mutex_unlock(&mdsc->mutex); |
| 4825 | schedule_delayed(mdsc); |
| 4826 | return; |
| 4827 | |
| 4828 | bad_unlock: |
| 4829 | mutex_unlock(&mdsc->mutex); |
| 4830 | bad: |
| 4831 | pr_err("error decoding mdsmap %d\n", err); |
| 4832 | return; |
| 4833 | } |
| 4834 | |
| 4835 | static struct ceph_connection *con_get(struct ceph_connection *con) |
| 4836 | { |
| 4837 | struct ceph_mds_session *s = con->private; |
| 4838 | |
Xiubo Li | 5b3248c | 2019-12-19 19:44:09 -0500 | [diff] [blame] | 4839 | if (ceph_get_mds_session(s)) |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4840 | return con; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4841 | return NULL; |
| 4842 | } |
| 4843 | |
| 4844 | static void con_put(struct ceph_connection *con) |
| 4845 | { |
| 4846 | struct ceph_mds_session *s = con->private; |
| 4847 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4848 | ceph_put_mds_session(s); |
| 4849 | } |
| 4850 | |
| 4851 | /* |
| 4852 | * if the client is unresponsive for long enough, the mds will kill |
| 4853 | * the session entirely. |
| 4854 | */ |
| 4855 | static void peer_reset(struct ceph_connection *con) |
| 4856 | { |
| 4857 | struct ceph_mds_session *s = con->private; |
Sage Weil | 7e70f0e | 2010-03-18 13:59:12 -0700 | [diff] [blame] | 4858 | struct ceph_mds_client *mdsc = s->s_mdsc; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4859 | |
Fabian Frederick | f3ae1b9 | 2014-06-06 14:35:37 -0700 | [diff] [blame] | 4860 | pr_warn("mds%d closed our session\n", s->s_mds); |
Sage Weil | 7e70f0e | 2010-03-18 13:59:12 -0700 | [diff] [blame] | 4861 | send_mds_reconnect(mdsc, s); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | static void dispatch(struct ceph_connection *con, struct ceph_msg *msg) |
| 4865 | { |
| 4866 | struct ceph_mds_session *s = con->private; |
| 4867 | struct ceph_mds_client *mdsc = s->s_mdsc; |
| 4868 | int type = le16_to_cpu(msg->hdr.type); |
| 4869 | |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4870 | mutex_lock(&mdsc->mutex); |
| 4871 | if (__verify_registered_session(mdsc, s) < 0) { |
| 4872 | mutex_unlock(&mdsc->mutex); |
| 4873 | goto out; |
| 4874 | } |
| 4875 | mutex_unlock(&mdsc->mutex); |
| 4876 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4877 | switch (type) { |
| 4878 | case CEPH_MSG_MDS_MAP: |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 4879 | ceph_mdsc_handle_mdsmap(mdsc, msg); |
| 4880 | break; |
| 4881 | case CEPH_MSG_FS_MAP_USER: |
| 4882 | ceph_mdsc_handle_fsmap(mdsc, msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4883 | break; |
| 4884 | case CEPH_MSG_CLIENT_SESSION: |
| 4885 | handle_session(s, msg); |
| 4886 | break; |
| 4887 | case CEPH_MSG_CLIENT_REPLY: |
| 4888 | handle_reply(s, msg); |
| 4889 | break; |
| 4890 | case CEPH_MSG_CLIENT_REQUEST_FORWARD: |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4891 | handle_forward(mdsc, s, msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4892 | break; |
| 4893 | case CEPH_MSG_CLIENT_CAPS: |
| 4894 | ceph_handle_caps(s, msg); |
| 4895 | break; |
| 4896 | case CEPH_MSG_CLIENT_SNAP: |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4897 | ceph_handle_snap(mdsc, s, msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4898 | break; |
| 4899 | case CEPH_MSG_CLIENT_LEASE: |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4900 | handle_lease(mdsc, s, msg); |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4901 | break; |
Luis Henriques | fb18a57 | 2018-01-05 10:47:18 +0000 | [diff] [blame] | 4902 | case CEPH_MSG_CLIENT_QUOTA: |
| 4903 | ceph_handle_quota(mdsc, s, msg); |
| 4904 | break; |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4905 | |
| 4906 | default: |
| 4907 | pr_err("received unknown message type %d %s\n", type, |
| 4908 | ceph_msg_type_name(type)); |
| 4909 | } |
Sage Weil | 2600d2d | 2010-02-22 15:12:16 -0800 | [diff] [blame] | 4910 | out: |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 4911 | ceph_msg_put(msg); |
| 4912 | } |
| 4913 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4914 | /* |
| 4915 | * authentication |
| 4916 | */ |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4917 | |
| 4918 | /* |
| 4919 | * Note: returned pointer is the address of a structure that's |
| 4920 | * managed separately. Caller must *not* attempt to free it. |
| 4921 | */ |
| 4922 | static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con, |
Alex Elder | 8f43fb5 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4923 | int *proto, int force_new) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4924 | { |
| 4925 | struct ceph_mds_session *s = con->private; |
| 4926 | struct ceph_mds_client *mdsc = s->s_mdsc; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4927 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4928 | struct ceph_auth_handshake *auth = &s->s_auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4929 | |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4930 | if (force_new && auth->authorizer) { |
Ilya Dryomov | 6c1ea26 | 2016-04-11 19:34:49 +0200 | [diff] [blame] | 4931 | ceph_auth_destroy_authorizer(auth->authorizer); |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4932 | auth->authorizer = NULL; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4933 | } |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 4934 | if (!auth->authorizer) { |
| 4935 | int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_MDS, |
| 4936 | auth); |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 4937 | if (ret) |
| 4938 | return ERR_PTR(ret); |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 4939 | } else { |
| 4940 | int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_MDS, |
| 4941 | auth); |
Alex Elder | a255651 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4942 | if (ret) |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4943 | return ERR_PTR(ret); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4944 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4945 | *proto = ac->protocol; |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4946 | |
Alex Elder | a3530df | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 4947 | return auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4948 | } |
| 4949 | |
Ilya Dryomov | 6daca13 | 2018-07-27 19:18:34 +0200 | [diff] [blame] | 4950 | static int add_authorizer_challenge(struct ceph_connection *con, |
| 4951 | void *challenge_buf, int challenge_buf_len) |
| 4952 | { |
| 4953 | struct ceph_mds_session *s = con->private; |
| 4954 | struct ceph_mds_client *mdsc = s->s_mdsc; |
| 4955 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
| 4956 | |
| 4957 | return ceph_auth_add_authorizer_challenge(ac, s->s_auth.authorizer, |
| 4958 | challenge_buf, challenge_buf_len); |
| 4959 | } |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4960 | |
Ilya Dryomov | 0dde584 | 2016-12-02 16:35:09 +0100 | [diff] [blame] | 4961 | static int verify_authorizer_reply(struct ceph_connection *con) |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4962 | { |
| 4963 | struct ceph_mds_session *s = con->private; |
| 4964 | struct ceph_mds_client *mdsc = s->s_mdsc; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4965 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4966 | |
Ilya Dryomov | 0dde584 | 2016-12-02 16:35:09 +0100 | [diff] [blame] | 4967 | return ceph_auth_verify_authorizer_reply(ac, s->s_auth.authorizer); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 4968 | } |
| 4969 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 4970 | static int invalidate_authorizer(struct ceph_connection *con) |
| 4971 | { |
| 4972 | struct ceph_mds_session *s = con->private; |
| 4973 | struct ceph_mds_client *mdsc = s->s_mdsc; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4974 | struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth; |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 4975 | |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 4976 | ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_MDS); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 4977 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4978 | return ceph_monc_validate_auth(&mdsc->fsc->client->monc); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 4979 | } |
| 4980 | |
Alex Elder | 53ded49 | 2013-03-01 18:00:14 -0600 | [diff] [blame] | 4981 | static struct ceph_msg *mds_alloc_msg(struct ceph_connection *con, |
| 4982 | struct ceph_msg_header *hdr, int *skip) |
| 4983 | { |
| 4984 | struct ceph_msg *msg; |
| 4985 | int type = (int) le16_to_cpu(hdr->type); |
| 4986 | int front_len = (int) le32_to_cpu(hdr->front_len); |
| 4987 | |
| 4988 | if (con->in_msg) |
| 4989 | return con->in_msg; |
| 4990 | |
| 4991 | *skip = 0; |
| 4992 | msg = ceph_msg_new(type, front_len, GFP_NOFS, false); |
| 4993 | if (!msg) { |
| 4994 | pr_err("unable to allocate msg type %d len %d\n", |
| 4995 | type, front_len); |
| 4996 | return NULL; |
| 4997 | } |
Alex Elder | 53ded49 | 2013-03-01 18:00:14 -0600 | [diff] [blame] | 4998 | |
| 4999 | return msg; |
| 5000 | } |
| 5001 | |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5002 | static int mds_sign_message(struct ceph_msg *msg) |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5003 | { |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5004 | struct ceph_mds_session *s = msg->con->private; |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5005 | struct ceph_auth_handshake *auth = &s->s_auth; |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5006 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5007 | return ceph_auth_sign_message(auth, msg); |
| 5008 | } |
| 5009 | |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5010 | static int mds_check_message_signature(struct ceph_msg *msg) |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5011 | { |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5012 | struct ceph_mds_session *s = msg->con->private; |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5013 | struct ceph_auth_handshake *auth = &s->s_auth; |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5014 | |
Yan, Zheng | 33d0733 | 2014-11-04 16:33:37 +0800 | [diff] [blame] | 5015 | return ceph_auth_check_message_signature(auth, msg); |
| 5016 | } |
| 5017 | |
Tobias Klauser | 9e32789 | 2010-05-20 10:40:19 +0200 | [diff] [blame] | 5018 | static const struct ceph_connection_operations mds_con_ops = { |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 5019 | .get = con_get, |
| 5020 | .put = con_put, |
| 5021 | .dispatch = dispatch, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5022 | .get_authorizer = get_authorizer, |
Ilya Dryomov | 6daca13 | 2018-07-27 19:18:34 +0200 | [diff] [blame] | 5023 | .add_authorizer_challenge = add_authorizer_challenge, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 5024 | .verify_authorizer_reply = verify_authorizer_reply, |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 5025 | .invalidate_authorizer = invalidate_authorizer, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 5026 | .peer_reset = peer_reset, |
Alex Elder | 53ded49 | 2013-03-01 18:00:14 -0600 | [diff] [blame] | 5027 | .alloc_msg = mds_alloc_msg, |
Ilya Dryomov | 79dbd1b | 2015-10-26 22:23:56 +0100 | [diff] [blame] | 5028 | .sign_message = mds_sign_message, |
| 5029 | .check_message_signature = mds_check_message_signature, |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 5030 | }; |
| 5031 | |
Sage Weil | 2f2dc05 | 2009-10-06 11:31:09 -0700 | [diff] [blame] | 5032 | /* eof */ |