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