blob: dfc25ceeffed7737be14768e27887f1eb2d27d13 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weil963b61e2009-10-06 11:31:12 -07003
Sage Weil963b61e2009-10-06 11:31:12 -07004#include <linux/sort.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Sage Weil963b61e2009-10-06 11:31:12 -07006
7#include "super.h"
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07008#include "mds_client.h"
9
10#include <linux/ceph/decode.h>
Sage Weil963b61e2009-10-06 11:31:12 -070011
12/*
13 * Snapshots in ceph are driven in large part by cooperation from the
14 * client. In contrast to local file systems or file servers that
15 * implement snapshots at a single point in the system, ceph's
16 * distributed access to storage requires clients to help decide
17 * whether a write logically occurs before or after a recently created
18 * snapshot.
19 *
20 * This provides a perfect instantanous client-wide snapshot. Between
21 * clients, however, snapshots may appear to be applied at slightly
22 * different points in time, depending on delays in delivering the
23 * snapshot notification.
24 *
25 * Snapshots are _not_ file system-wide. Instead, each snapshot
26 * applies to the subdirectory nested beneath some directory. This
27 * effectively divides the hierarchy into multiple "realms," where all
28 * of the files contained by each realm share the same set of
29 * snapshots. An individual realm's snap set contains snapshots
30 * explicitly created on that realm, as well as any snaps in its
31 * parent's snap set _after_ the point at which the parent became it's
32 * parent (due to, say, a rename). Similarly, snaps from prior parents
33 * during the time intervals during which they were the parent are included.
34 *
35 * The client is spared most of this detail, fortunately... it must only
36 * maintains a hierarchy of realms reflecting the current parent/child
37 * realm relationship, and for each realm has an explicit list of snaps
38 * inherited from prior parents.
39 *
40 * A snap_realm struct is maintained for realms containing every inode
41 * with an open cap in the system. (The needed snap realm information is
42 * provided by the MDS whenever a cap is issued, i.e., on open.) A 'seq'
43 * version number is used to ensure that as realm parameters change (new
44 * snapshot, new parent, etc.) the client's realm hierarchy is updated.
45 *
46 * The realm hierarchy drives the generation of a 'snap context' for each
47 * realm, which simply lists the resulting set of snaps for the realm. This
48 * is attached to any writes sent to OSDs.
49 */
50/*
51 * Unfortunately error handling is a bit mixed here. If we get a snap
52 * update, but don't have enough memory to update our realm hierarchy,
53 * it's not clear what we can do about it (besides complaining to the
54 * console).
55 */
56
57
58/*
59 * increase ref count for the realm
60 *
61 * caller must hold snap_rwsem for write.
62 */
63void ceph_get_snap_realm(struct ceph_mds_client *mdsc,
64 struct ceph_snap_realm *realm)
65{
66 dout("get_realm %p %d -> %d\n", realm,
67 atomic_read(&realm->nref), atomic_read(&realm->nref)+1);
68 /*
69 * since we _only_ increment realm refs or empty the empty
70 * list with snap_rwsem held, adjusting the empty list here is
71 * safe. we do need to protect against concurrent empty list
72 * additions, however.
73 */
Yan, Zheng982d6012014-12-23 15:30:54 +080074 if (atomic_inc_return(&realm->nref) == 1) {
Sage Weil963b61e2009-10-06 11:31:12 -070075 spin_lock(&mdsc->snap_empty_lock);
76 list_del_init(&realm->empty_item);
77 spin_unlock(&mdsc->snap_empty_lock);
78 }
Sage Weil963b61e2009-10-06 11:31:12 -070079}
80
Sage Weila105f002010-02-15 14:37:55 -080081static void __insert_snap_realm(struct rb_root *root,
82 struct ceph_snap_realm *new)
83{
84 struct rb_node **p = &root->rb_node;
85 struct rb_node *parent = NULL;
86 struct ceph_snap_realm *r = NULL;
87
88 while (*p) {
89 parent = *p;
90 r = rb_entry(parent, struct ceph_snap_realm, node);
91 if (new->ino < r->ino)
92 p = &(*p)->rb_left;
93 else if (new->ino > r->ino)
94 p = &(*p)->rb_right;
95 else
96 BUG();
97 }
98
99 rb_link_node(&new->node, parent, p);
100 rb_insert_color(&new->node, root);
101}
102
Sage Weil963b61e2009-10-06 11:31:12 -0700103/*
104 * create and get the realm rooted at @ino and bump its ref count.
105 *
106 * caller must hold snap_rwsem for write.
107 */
108static struct ceph_snap_realm *ceph_create_snap_realm(
109 struct ceph_mds_client *mdsc,
110 u64 ino)
111{
112 struct ceph_snap_realm *realm;
113
114 realm = kzalloc(sizeof(*realm), GFP_NOFS);
115 if (!realm)
116 return ERR_PTR(-ENOMEM);
117
Yan, Zheng982d6012014-12-23 15:30:54 +0800118 atomic_set(&realm->nref, 1); /* for caller */
Sage Weil963b61e2009-10-06 11:31:12 -0700119 realm->ino = ino;
120 INIT_LIST_HEAD(&realm->children);
121 INIT_LIST_HEAD(&realm->child_item);
122 INIT_LIST_HEAD(&realm->empty_item);
Sage Weilae00d4f2010-09-16 16:26:51 -0700123 INIT_LIST_HEAD(&realm->dirty_item);
Sage Weil963b61e2009-10-06 11:31:12 -0700124 INIT_LIST_HEAD(&realm->inodes_with_caps);
125 spin_lock_init(&realm->inodes_with_caps_lock);
Sage Weila105f002010-02-15 14:37:55 -0800126 __insert_snap_realm(&mdsc->snap_realms, realm);
Yan, Zheng81c5a142019-01-01 16:28:33 +0800127 mdsc->num_snap_realms++;
128
Sage Weil963b61e2009-10-06 11:31:12 -0700129 dout("create_snap_realm %llx %p\n", realm->ino, realm);
130 return realm;
131}
132
133/*
Sage Weila105f002010-02-15 14:37:55 -0800134 * lookup the realm rooted at @ino.
Sage Weil963b61e2009-10-06 11:31:12 -0700135 *
136 * caller must hold snap_rwsem for write.
137 */
Yan, Zheng982d6012014-12-23 15:30:54 +0800138static struct ceph_snap_realm *__lookup_snap_realm(struct ceph_mds_client *mdsc,
139 u64 ino)
Sage Weil963b61e2009-10-06 11:31:12 -0700140{
Sage Weila105f002010-02-15 14:37:55 -0800141 struct rb_node *n = mdsc->snap_realms.rb_node;
142 struct ceph_snap_realm *r;
Sage Weil963b61e2009-10-06 11:31:12 -0700143
Sage Weila105f002010-02-15 14:37:55 -0800144 while (n) {
145 r = rb_entry(n, struct ceph_snap_realm, node);
146 if (ino < r->ino)
147 n = n->rb_left;
148 else if (ino > r->ino)
149 n = n->rb_right;
150 else {
151 dout("lookup_snap_realm %llx %p\n", r->ino, r);
152 return r;
153 }
154 }
155 return NULL;
Sage Weil963b61e2009-10-06 11:31:12 -0700156}
157
Yan, Zheng982d6012014-12-23 15:30:54 +0800158struct ceph_snap_realm *ceph_lookup_snap_realm(struct ceph_mds_client *mdsc,
159 u64 ino)
160{
161 struct ceph_snap_realm *r;
162 r = __lookup_snap_realm(mdsc, ino);
163 if (r)
164 ceph_get_snap_realm(mdsc, r);
165 return r;
166}
167
Sage Weil963b61e2009-10-06 11:31:12 -0700168static void __put_snap_realm(struct ceph_mds_client *mdsc,
169 struct ceph_snap_realm *realm);
170
171/*
172 * called with snap_rwsem (write)
173 */
174static void __destroy_snap_realm(struct ceph_mds_client *mdsc,
175 struct ceph_snap_realm *realm)
176{
177 dout("__destroy_snap_realm %p %llx\n", realm, realm->ino);
178
Sage Weila105f002010-02-15 14:37:55 -0800179 rb_erase(&realm->node, &mdsc->snap_realms);
Yan, Zheng81c5a142019-01-01 16:28:33 +0800180 mdsc->num_snap_realms--;
Sage Weil963b61e2009-10-06 11:31:12 -0700181
182 if (realm->parent) {
183 list_del_init(&realm->child_item);
184 __put_snap_realm(mdsc, realm->parent);
185 }
186
187 kfree(realm->prior_parent_snaps);
188 kfree(realm->snaps);
189 ceph_put_snap_context(realm->cached_context);
190 kfree(realm);
191}
192
193/*
194 * caller holds snap_rwsem (write)
195 */
196static void __put_snap_realm(struct ceph_mds_client *mdsc,
197 struct ceph_snap_realm *realm)
198{
199 dout("__put_snap_realm %llx %p %d -> %d\n", realm->ino, realm,
200 atomic_read(&realm->nref), atomic_read(&realm->nref)-1);
201 if (atomic_dec_and_test(&realm->nref))
202 __destroy_snap_realm(mdsc, realm);
203}
204
205/*
206 * caller needn't hold any locks
207 */
208void ceph_put_snap_realm(struct ceph_mds_client *mdsc,
209 struct ceph_snap_realm *realm)
210{
211 dout("put_snap_realm %llx %p %d -> %d\n", realm->ino, realm,
212 atomic_read(&realm->nref), atomic_read(&realm->nref)-1);
213 if (!atomic_dec_and_test(&realm->nref))
214 return;
215
216 if (down_write_trylock(&mdsc->snap_rwsem)) {
217 __destroy_snap_realm(mdsc, realm);
218 up_write(&mdsc->snap_rwsem);
219 } else {
220 spin_lock(&mdsc->snap_empty_lock);
Henry C Changa26a1852011-05-11 10:29:53 +0000221 list_add(&realm->empty_item, &mdsc->snap_empty);
Sage Weil963b61e2009-10-06 11:31:12 -0700222 spin_unlock(&mdsc->snap_empty_lock);
223 }
224}
225
226/*
227 * Clean up any realms whose ref counts have dropped to zero. Note
228 * that this does not include realms who were created but not yet
229 * used.
230 *
231 * Called under snap_rwsem (write)
232 */
233static void __cleanup_empty_realms(struct ceph_mds_client *mdsc)
234{
235 struct ceph_snap_realm *realm;
236
237 spin_lock(&mdsc->snap_empty_lock);
238 while (!list_empty(&mdsc->snap_empty)) {
239 realm = list_first_entry(&mdsc->snap_empty,
240 struct ceph_snap_realm, empty_item);
241 list_del(&realm->empty_item);
242 spin_unlock(&mdsc->snap_empty_lock);
243 __destroy_snap_realm(mdsc, realm);
244 spin_lock(&mdsc->snap_empty_lock);
245 }
246 spin_unlock(&mdsc->snap_empty_lock);
247}
248
249void ceph_cleanup_empty_realms(struct ceph_mds_client *mdsc)
250{
251 down_write(&mdsc->snap_rwsem);
252 __cleanup_empty_realms(mdsc);
253 up_write(&mdsc->snap_rwsem);
254}
255
256/*
257 * adjust the parent realm of a given @realm. adjust child list, and parent
258 * pointers, and ref counts appropriately.
259 *
260 * return true if parent was changed, 0 if unchanged, <0 on error.
261 *
262 * caller must hold snap_rwsem for write.
263 */
264static int adjust_snap_realm_parent(struct ceph_mds_client *mdsc,
265 struct ceph_snap_realm *realm,
266 u64 parentino)
267{
268 struct ceph_snap_realm *parent;
269
270 if (realm->parent_ino == parentino)
271 return 0;
272
273 parent = ceph_lookup_snap_realm(mdsc, parentino);
Sage Weil963b61e2009-10-06 11:31:12 -0700274 if (!parent) {
275 parent = ceph_create_snap_realm(mdsc, parentino);
276 if (IS_ERR(parent))
277 return PTR_ERR(parent);
278 }
279 dout("adjust_snap_realm_parent %llx %p: %llx %p -> %llx %p\n",
280 realm->ino, realm, realm->parent_ino, realm->parent,
281 parentino, parent);
282 if (realm->parent) {
283 list_del_init(&realm->child_item);
284 ceph_put_snap_realm(mdsc, realm->parent);
285 }
286 realm->parent_ino = parentino;
287 realm->parent = parent;
Sage Weil963b61e2009-10-06 11:31:12 -0700288 list_add(&realm->child_item, &parent->children);
289 return 1;
290}
291
292
293static int cmpu64_rev(const void *a, const void *b)
294{
295 if (*(u64 *)a < *(u64 *)b)
296 return 1;
297 if (*(u64 *)a > *(u64 *)b)
298 return -1;
299 return 0;
300}
301
Yan, Zheng97c85a82014-11-06 15:09:41 +0800302
Sage Weil963b61e2009-10-06 11:31:12 -0700303/*
304 * build the snap context for a given realm.
305 */
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800306static int build_snap_context(struct ceph_snap_realm *realm,
307 struct list_head* dirty_realms)
Sage Weil963b61e2009-10-06 11:31:12 -0700308{
309 struct ceph_snap_realm *parent = realm->parent;
310 struct ceph_snap_context *snapc;
311 int err = 0;
Alex Elderaa711ee32012-07-13 20:35:11 -0500312 u32 num = realm->num_prior_parent_snaps + realm->num_snaps;
Sage Weil963b61e2009-10-06 11:31:12 -0700313
314 /*
315 * build parent context, if it hasn't been built.
316 * conservatively estimate that all parent snaps might be
317 * included by us.
318 */
319 if (parent) {
320 if (!parent->cached_context) {
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800321 err = build_snap_context(parent, dirty_realms);
Sage Weil963b61e2009-10-06 11:31:12 -0700322 if (err)
323 goto fail;
324 }
325 num += parent->cached_context->num_snaps;
326 }
327
328 /* do i actually need to update? not if my context seq
329 matches realm seq, and my parents' does to. (this works
330 because we rebuild_snap_realms() works _downward_ in
331 hierarchy after each update.) */
332 if (realm->cached_context &&
Sage Weilec4318bc2010-03-19 13:24:39 -0700333 realm->cached_context->seq == realm->seq &&
Sage Weil963b61e2009-10-06 11:31:12 -0700334 (!parent ||
Sage Weilec4318bc2010-03-19 13:24:39 -0700335 realm->cached_context->seq >= parent->cached_context->seq)) {
Alex Elderaa711ee32012-07-13 20:35:11 -0500336 dout("build_snap_context %llx %p: %p seq %lld (%u snaps)"
Sage Weil963b61e2009-10-06 11:31:12 -0700337 " (unchanged)\n",
338 realm->ino, realm, realm->cached_context,
339 realm->cached_context->seq,
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800340 (unsigned int)realm->cached_context->num_snaps);
Sage Weil963b61e2009-10-06 11:31:12 -0700341 return 0;
342 }
343
344 /* alloc new snap context */
345 err = -ENOMEM;
Xi Wanga3860c12012-05-31 16:26:04 -0700346 if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
Sage Weil963b61e2009-10-06 11:31:12 -0700347 goto fail;
Alex Elder812164f82013-04-30 00:44:32 -0500348 snapc = ceph_create_snap_context(num, GFP_NOFS);
Sage Weil963b61e2009-10-06 11:31:12 -0700349 if (!snapc)
350 goto fail;
Sage Weil963b61e2009-10-06 11:31:12 -0700351
352 /* build (reverse sorted) snap vector */
353 num = 0;
354 snapc->seq = realm->seq;
355 if (parent) {
Alex Elderaa711ee32012-07-13 20:35:11 -0500356 u32 i;
357
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300358 /* include any of parent's snaps occurring _after_ my
Sage Weil963b61e2009-10-06 11:31:12 -0700359 parent became my parent */
360 for (i = 0; i < parent->cached_context->num_snaps; i++)
361 if (parent->cached_context->snaps[i] >=
362 realm->parent_since)
363 snapc->snaps[num++] =
364 parent->cached_context->snaps[i];
365 if (parent->cached_context->seq > snapc->seq)
366 snapc->seq = parent->cached_context->seq;
367 }
368 memcpy(snapc->snaps + num, realm->snaps,
369 sizeof(u64)*realm->num_snaps);
370 num += realm->num_snaps;
371 memcpy(snapc->snaps + num, realm->prior_parent_snaps,
372 sizeof(u64)*realm->num_prior_parent_snaps);
373 num += realm->num_prior_parent_snaps;
374
375 sort(snapc->snaps, num, sizeof(u64), cmpu64_rev, NULL);
376 snapc->num_snaps = num;
Alex Elderaa711ee32012-07-13 20:35:11 -0500377 dout("build_snap_context %llx %p: %p seq %lld (%u snaps)\n",
378 realm->ino, realm, snapc, snapc->seq,
379 (unsigned int) snapc->num_snaps);
Sage Weil963b61e2009-10-06 11:31:12 -0700380
Yan, Zheng9f4057f2017-09-22 09:26:57 +0800381 ceph_put_snap_context(realm->cached_context);
Sage Weil963b61e2009-10-06 11:31:12 -0700382 realm->cached_context = snapc;
Yan, Zheng9f4057f2017-09-22 09:26:57 +0800383 /* queue realm for cap_snap creation */
384 list_add_tail(&realm->dirty_item, dirty_realms);
Sage Weil963b61e2009-10-06 11:31:12 -0700385 return 0;
386
387fail:
388 /*
389 * if we fail, clear old (incorrect) cached_context... hopefully
390 * we'll have better luck building it later
391 */
392 if (realm->cached_context) {
393 ceph_put_snap_context(realm->cached_context);
394 realm->cached_context = NULL;
395 }
396 pr_err("build_snap_context %llx %p fail %d\n", realm->ino,
397 realm, err);
398 return err;
399}
400
401/*
402 * rebuild snap context for the given realm and all of its children.
403 */
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800404static void rebuild_snap_realms(struct ceph_snap_realm *realm,
405 struct list_head *dirty_realms)
Sage Weil963b61e2009-10-06 11:31:12 -0700406{
407 struct ceph_snap_realm *child;
408
409 dout("rebuild_snap_realms %llx %p\n", realm->ino, realm);
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800410 build_snap_context(realm, dirty_realms);
Sage Weil963b61e2009-10-06 11:31:12 -0700411
412 list_for_each_entry(child, &realm->children, child_item)
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800413 rebuild_snap_realms(child, dirty_realms);
Sage Weil963b61e2009-10-06 11:31:12 -0700414}
415
416
417/*
418 * helper to allocate and decode an array of snapids. free prior
419 * instance, if any.
420 */
Alex Elderaa711ee32012-07-13 20:35:11 -0500421static int dup_array(u64 **dst, __le64 *src, u32 num)
Sage Weil963b61e2009-10-06 11:31:12 -0700422{
Alex Elderaa711ee32012-07-13 20:35:11 -0500423 u32 i;
Sage Weil963b61e2009-10-06 11:31:12 -0700424
425 kfree(*dst);
426 if (num) {
427 *dst = kcalloc(num, sizeof(u64), GFP_NOFS);
428 if (!*dst)
429 return -ENOMEM;
430 for (i = 0; i < num; i++)
431 (*dst)[i] = get_unaligned_le64(src + i);
432 } else {
433 *dst = NULL;
434 }
435 return 0;
436}
437
Yan, Zheng86056092015-05-01 16:57:16 +0800438static bool has_new_snaps(struct ceph_snap_context *o,
439 struct ceph_snap_context *n)
440{
441 if (n->num_snaps == 0)
442 return false;
443 /* snaps are in descending order */
444 return n->snaps[0] > o->seq;
445}
Sage Weil963b61e2009-10-06 11:31:12 -0700446
447/*
448 * When a snapshot is applied, the size/mtime inode metadata is queued
449 * in a ceph_cap_snap (one for each snapshot) until writeback
450 * completes and the metadata can be flushed back to the MDS.
451 *
452 * However, if a (sync) write is currently in-progress when we apply
453 * the snapshot, we have to wait until the write succeeds or fails
454 * (and a final size/mtime is known). In this case the
455 * cap_snap->writing = 1, and is said to be "pending." When the write
456 * finishes, we __ceph_finish_cap_snap().
457 *
458 * Caller must hold snap_rwsem for read (i.e., the realm topology won't
459 * change).
460 */
Sage Weilfc837c8f2010-04-13 11:41:22 -0700461void ceph_queue_cap_snap(struct ceph_inode_info *ci)
Sage Weil963b61e2009-10-06 11:31:12 -0700462{
463 struct inode *inode = &ci->vfs_inode;
464 struct ceph_cap_snap *capsnap;
Yan, Zheng86056092015-05-01 16:57:16 +0800465 struct ceph_snap_context *old_snapc, *new_snapc;
Sage Weil4a625be2010-08-22 15:03:56 -0700466 int used, dirty;
Sage Weil963b61e2009-10-06 11:31:12 -0700467
468 capsnap = kzalloc(sizeof(*capsnap), GFP_NOFS);
469 if (!capsnap) {
470 pr_err("ENOMEM allocating ceph_cap_snap on %p\n", inode);
471 return;
472 }
473
Sage Weilbe655592011-11-30 09:47:09 -0800474 spin_lock(&ci->i_ceph_lock);
Sage Weil963b61e2009-10-06 11:31:12 -0700475 used = __ceph_caps_used(ci);
Sage Weil4a625be2010-08-22 15:03:56 -0700476 dirty = __ceph_caps_dirty(ci);
Sage Weilaf0ed562011-07-26 11:26:31 -0700477
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800478 old_snapc = ci->i_head_snapc;
Yan, Zheng86056092015-05-01 16:57:16 +0800479 new_snapc = ci->i_snap_realm->cached_context;
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800480
Sage Weilaf0ed562011-07-26 11:26:31 -0700481 /*
482 * If there is a write in progress, treat that as a dirty Fw,
483 * even though it hasn't completed yet; by the time we finish
484 * up this capsnap it will be.
485 */
486 if (used & CEPH_CAP_FILE_WR)
487 dirty |= CEPH_CAP_FILE_WR;
488
Sage Weil963b61e2009-10-06 11:31:12 -0700489 if (__ceph_have_pending_cap_snap(ci)) {
490 /* there is no point in queuing multiple "pending" cap_snaps,
491 as no new writes are allowed to start when pending, so any
492 writes in progress now were started before the previous
493 cap_snap. lucky us. */
Sage Weilfc837c8f2010-04-13 11:41:22 -0700494 dout("queue_cap_snap %p already pending\n", inode);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800495 goto update_snapc;
496 }
Yan, Zheng86056092015-05-01 16:57:16 +0800497 if (ci->i_wrbuffer_ref_head == 0 &&
498 !(dirty & (CEPH_CAP_ANY_EXCL|CEPH_CAP_FILE_WR))) {
Sage Weil963b61e2009-10-06 11:31:12 -0700499 dout("queue_cap_snap %p nothing dirty|writing\n", inode);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800500 goto update_snapc;
Sage Weil963b61e2009-10-06 11:31:12 -0700501 }
502
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800503 BUG_ON(!old_snapc);
504
Yan, Zheng86056092015-05-01 16:57:16 +0800505 /*
506 * There is no need to send FLUSHSNAP message to MDS if there is
507 * no new snapshot. But when there is dirty pages or on-going
508 * writes, we still need to create cap_snap. cap_snap is needed
509 * by the write path and page writeback path.
510 *
511 * also see ceph_try_drop_cap_snap()
512 */
513 if (has_new_snaps(old_snapc, new_snapc)) {
514 if (dirty & (CEPH_CAP_ANY_EXCL|CEPH_CAP_FILE_WR))
515 capsnap->need_flush = true;
516 } else {
517 if (!(used & CEPH_CAP_FILE_WR) &&
518 ci->i_wrbuffer_ref_head == 0) {
519 dout("queue_cap_snap %p "
520 "no new_snap|dirty_page|writing\n", inode);
521 goto update_snapc;
522 }
523 }
524
525 dout("queue_cap_snap %p cap_snap %p queuing under %p %s %s\n",
526 inode, capsnap, old_snapc, ceph_cap_string(dirty),
527 capsnap->need_flush ? "" : "no_flush");
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800528 ihold(inode);
529
Elena Reshetova805692d2017-03-03 11:15:07 +0200530 refcount_set(&capsnap->nref, 1);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800531 INIT_LIST_HEAD(&capsnap->ci_item);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800532
533 capsnap->follows = old_snapc->seq;
534 capsnap->issued = __ceph_caps_issued(ci, NULL);
535 capsnap->dirty = dirty;
536
537 capsnap->mode = inode->i_mode;
538 capsnap->uid = inode->i_uid;
539 capsnap->gid = inode->i_gid;
540
541 if (dirty & CEPH_CAP_XATTR_EXCL) {
542 __ceph_build_xattrs_blob(ci);
543 capsnap->xattr_blob =
544 ceph_buffer_get(ci->i_xattrs.blob);
545 capsnap->xattr_version = ci->i_xattrs.version;
546 } else {
547 capsnap->xattr_blob = NULL;
548 capsnap->xattr_version = 0;
549 }
550
551 capsnap->inline_data = ci->i_inline_version != CEPH_INLINE_NONE;
552
553 /* dirty page count moved from _head to this cap_snap;
554 all subsequent writes page dirties occur _after_ this
555 snapshot. */
556 capsnap->dirty_pages = ci->i_wrbuffer_ref_head;
557 ci->i_wrbuffer_ref_head = 0;
558 capsnap->context = old_snapc;
559 list_add_tail(&capsnap->ci_item, &ci->i_cap_snaps);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800560
561 if (used & CEPH_CAP_FILE_WR) {
562 dout("queue_cap_snap %p cap_snap %p snapc %p"
563 " seq %llu used WR, now pending\n", inode,
564 capsnap, old_snapc, old_snapc->seq);
565 capsnap->writing = 1;
566 } else {
567 /* note mtime, size NOW. */
568 __ceph_finish_cap_snap(ci, capsnap);
569 }
570 capsnap = NULL;
Yan, Zhengfce85152016-06-15 20:51:22 +0800571 old_snapc = NULL;
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800572
573update_snapc:
574 if (ci->i_head_snapc) {
Yan, Zheng86056092015-05-01 16:57:16 +0800575 ci->i_head_snapc = ceph_get_snap_context(new_snapc);
576 dout(" new snapc is %p\n", new_snapc);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800577 }
Sage Weilbe655592011-11-30 09:47:09 -0800578 spin_unlock(&ci->i_ceph_lock);
Yan, Zheng5dda377c2015-04-30 14:40:54 +0800579
580 kfree(capsnap);
581 ceph_put_snap_context(old_snapc);
Sage Weil963b61e2009-10-06 11:31:12 -0700582}
583
584/*
585 * Finalize the size, mtime for a cap_snap.. that is, settle on final values
586 * to be used for the snapshot, to be flushed back to the mds.
587 *
588 * If capsnap can now be flushed, add to snap_flush list, and return 1.
589 *
Sage Weilbe655592011-11-30 09:47:09 -0800590 * Caller must hold i_ceph_lock.
Sage Weil963b61e2009-10-06 11:31:12 -0700591 */
592int __ceph_finish_cap_snap(struct ceph_inode_info *ci,
593 struct ceph_cap_snap *capsnap)
594{
595 struct inode *inode = &ci->vfs_inode;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700596 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
Sage Weil963b61e2009-10-06 11:31:12 -0700597
598 BUG_ON(capsnap->writing);
599 capsnap->size = inode->i_size;
Arnd Bergmann9bbeab42018-07-13 22:18:36 +0200600 capsnap->mtime = inode->i_mtime;
601 capsnap->atime = inode->i_atime;
602 capsnap->ctime = inode->i_ctime;
Sage Weil963b61e2009-10-06 11:31:12 -0700603 capsnap->time_warp_seq = ci->i_time_warp_seq;
Yan, Zheng5f743e42016-11-15 16:04:37 +0800604 capsnap->truncate_size = ci->i_truncate_size;
605 capsnap->truncate_seq = ci->i_truncate_seq;
Sage Weil963b61e2009-10-06 11:31:12 -0700606 if (capsnap->dirty_pages) {
Sage Weil819ccbf2010-04-01 09:33:46 -0700607 dout("finish_cap_snap %p cap_snap %p snapc %p %llu %s s=%llu "
Sage Weil963b61e2009-10-06 11:31:12 -0700608 "still has %d dirty pages\n", inode, capsnap,
609 capsnap->context, capsnap->context->seq,
Sage Weil819ccbf2010-04-01 09:33:46 -0700610 ceph_cap_string(capsnap->dirty), capsnap->size,
611 capsnap->dirty_pages);
Sage Weil963b61e2009-10-06 11:31:12 -0700612 return 0;
613 }
Yan, Zheng70220ac2016-07-06 16:21:30 +0800614
615 ci->i_ceph_flags |= CEPH_I_FLUSH_SNAPS;
Sage Weil819ccbf2010-04-01 09:33:46 -0700616 dout("finish_cap_snap %p cap_snap %p snapc %p %llu %s s=%llu\n",
Sage Weil963b61e2009-10-06 11:31:12 -0700617 inode, capsnap, capsnap->context,
Sage Weil819ccbf2010-04-01 09:33:46 -0700618 capsnap->context->seq, ceph_cap_string(capsnap->dirty),
619 capsnap->size);
Sage Weil963b61e2009-10-06 11:31:12 -0700620
621 spin_lock(&mdsc->snap_flush_lock);
Yan, Zheng04242ff2019-02-11 15:18:52 +0800622 if (list_empty(&ci->i_snap_flush_item))
623 list_add_tail(&ci->i_snap_flush_item, &mdsc->snap_flush_list);
Sage Weil963b61e2009-10-06 11:31:12 -0700624 spin_unlock(&mdsc->snap_flush_lock);
625 return 1; /* caller may want to ceph_flush_snaps */
626}
627
Sage Weiled326042010-08-16 13:37:31 -0700628/*
629 * Queue cap_snaps for snap writeback for this realm and its children.
630 * Called under snap_rwsem, so realm topology won't change.
631 */
632static void queue_realm_cap_snaps(struct ceph_snap_realm *realm)
633{
634 struct ceph_inode_info *ci;
635 struct inode *lastinode = NULL;
Sage Weiled326042010-08-16 13:37:31 -0700636
637 dout("queue_realm_cap_snaps %p %llx inodes\n", realm, realm->ino);
638
639 spin_lock(&realm->inodes_with_caps_lock);
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800640 list_for_each_entry(ci, &realm->inodes_with_caps, i_snap_realm_item) {
Sage Weiled326042010-08-16 13:37:31 -0700641 struct inode *inode = igrab(&ci->vfs_inode);
642 if (!inode)
643 continue;
644 spin_unlock(&realm->inodes_with_caps_lock);
SF Markus Elfringe96a6502014-11-02 15:20:59 +0100645 iput(lastinode);
Sage Weiled326042010-08-16 13:37:31 -0700646 lastinode = inode;
647 ceph_queue_cap_snap(ci);
648 spin_lock(&realm->inodes_with_caps_lock);
649 }
650 spin_unlock(&realm->inodes_with_caps_lock);
SF Markus Elfringe96a6502014-11-02 15:20:59 +0100651 iput(lastinode);
Sage Weiled326042010-08-16 13:37:31 -0700652
Sage Weiled326042010-08-16 13:37:31 -0700653 dout("queue_realm_cap_snaps %p %llx done\n", realm, realm->ino);
654}
Sage Weil963b61e2009-10-06 11:31:12 -0700655
656/*
657 * Parse and apply a snapblob "snap trace" from the MDS. This specifies
658 * the snap realm parameters from a given realm and all of its ancestors,
659 * up to the root.
660 *
661 * Caller must hold snap_rwsem for write.
662 */
663int ceph_update_snap_trace(struct ceph_mds_client *mdsc,
Yan, Zheng982d6012014-12-23 15:30:54 +0800664 void *p, void *e, bool deletion,
665 struct ceph_snap_realm **realm_ret)
Sage Weil963b61e2009-10-06 11:31:12 -0700666{
667 struct ceph_mds_snap_realm *ri; /* encoded */
668 __le64 *snaps; /* encoded */
669 __le64 *prior_parent_snaps; /* encoded */
Yan, Zheng982d6012014-12-23 15:30:54 +0800670 struct ceph_snap_realm *realm = NULL;
671 struct ceph_snap_realm *first_realm = NULL;
Sage Weil963b61e2009-10-06 11:31:12 -0700672 int invalidate = 0;
673 int err = -ENOMEM;
Sage Weilae00d4f2010-09-16 16:26:51 -0700674 LIST_HEAD(dirty_realms);
Sage Weil963b61e2009-10-06 11:31:12 -0700675
676 dout("update_snap_trace deletion=%d\n", deletion);
677more:
678 ceph_decode_need(&p, e, sizeof(*ri), bad);
679 ri = p;
680 p += sizeof(*ri);
681 ceph_decode_need(&p, e, sizeof(u64)*(le32_to_cpu(ri->num_snaps) +
682 le32_to_cpu(ri->num_prior_parent_snaps)), bad);
683 snaps = p;
684 p += sizeof(u64) * le32_to_cpu(ri->num_snaps);
685 prior_parent_snaps = p;
686 p += sizeof(u64) * le32_to_cpu(ri->num_prior_parent_snaps);
687
688 realm = ceph_lookup_snap_realm(mdsc, le64_to_cpu(ri->ino));
Sage Weil963b61e2009-10-06 11:31:12 -0700689 if (!realm) {
690 realm = ceph_create_snap_realm(mdsc, le64_to_cpu(ri->ino));
691 if (IS_ERR(realm)) {
692 err = PTR_ERR(realm);
693 goto fail;
694 }
695 }
696
Sage Weil963b61e2009-10-06 11:31:12 -0700697 /* ensure the parent is correct */
698 err = adjust_snap_realm_parent(mdsc, realm, le64_to_cpu(ri->parent));
699 if (err < 0)
700 goto fail;
701 invalidate += err;
702
703 if (le64_to_cpu(ri->seq) > realm->seq) {
Sage Weilae00d4f2010-09-16 16:26:51 -0700704 dout("update_snap_trace updating %llx %p %lld -> %lld\n",
705 realm->ino, realm, realm->seq, le64_to_cpu(ri->seq));
Sage Weil963b61e2009-10-06 11:31:12 -0700706 /* update realm parameters, snap lists */
707 realm->seq = le64_to_cpu(ri->seq);
708 realm->created = le64_to_cpu(ri->created);
709 realm->parent_since = le64_to_cpu(ri->parent_since);
710
711 realm->num_snaps = le32_to_cpu(ri->num_snaps);
712 err = dup_array(&realm->snaps, snaps, realm->num_snaps);
713 if (err < 0)
714 goto fail;
715
716 realm->num_prior_parent_snaps =
717 le32_to_cpu(ri->num_prior_parent_snaps);
718 err = dup_array(&realm->prior_parent_snaps, prior_parent_snaps,
719 realm->num_prior_parent_snaps);
720 if (err < 0)
721 goto fail;
722
Yan, Zhengaffbc192015-05-05 21:22:13 +0800723 if (realm->seq > mdsc->last_snap_seq)
724 mdsc->last_snap_seq = realm->seq;
Sage Weilae00d4f2010-09-16 16:26:51 -0700725
Sage Weil963b61e2009-10-06 11:31:12 -0700726 invalidate = 1;
727 } else if (!realm->cached_context) {
Sage Weilae00d4f2010-09-16 16:26:51 -0700728 dout("update_snap_trace %llx %p seq %lld new\n",
729 realm->ino, realm, realm->seq);
Sage Weil963b61e2009-10-06 11:31:12 -0700730 invalidate = 1;
Sage Weilae00d4f2010-09-16 16:26:51 -0700731 } else {
732 dout("update_snap_trace %llx %p seq %lld unchanged\n",
733 realm->ino, realm, realm->seq);
Sage Weil963b61e2009-10-06 11:31:12 -0700734 }
735
736 dout("done with %llx %p, invalidated=%d, %p %p\n", realm->ino,
737 realm, invalidate, p, e);
738
Yan, Zheng982d6012014-12-23 15:30:54 +0800739 /* invalidate when we reach the _end_ (root) of the trace */
740 if (invalidate && p >= e)
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800741 rebuild_snap_realms(realm, &dirty_realms);
Yan, Zheng982d6012014-12-23 15:30:54 +0800742
743 if (!first_realm)
744 first_realm = realm;
745 else
746 ceph_put_snap_realm(mdsc, realm);
747
Sage Weil963b61e2009-10-06 11:31:12 -0700748 if (p < e)
749 goto more;
750
Sage Weilae00d4f2010-09-16 16:26:51 -0700751 /*
752 * queue cap snaps _after_ we've built the new snap contexts,
753 * so that i_head_snapc can be set appropriately.
754 */
Sage Weile8e1ba962011-02-04 20:45:58 -0800755 while (!list_empty(&dirty_realms)) {
756 realm = list_first_entry(&dirty_realms, struct ceph_snap_realm,
757 dirty_item);
Yan, Zheng3ae0beb2017-08-28 16:36:53 +0800758 list_del_init(&realm->dirty_item);
Sage Weilae00d4f2010-09-16 16:26:51 -0700759 queue_realm_cap_snaps(realm);
760 }
761
Yan, Zheng982d6012014-12-23 15:30:54 +0800762 if (realm_ret)
763 *realm_ret = first_realm;
764 else
765 ceph_put_snap_realm(mdsc, first_realm);
766
Sage Weil963b61e2009-10-06 11:31:12 -0700767 __cleanup_empty_realms(mdsc);
768 return 0;
769
770bad:
771 err = -EINVAL;
772fail:
Yan, Zheng982d6012014-12-23 15:30:54 +0800773 if (realm && !IS_ERR(realm))
774 ceph_put_snap_realm(mdsc, realm);
775 if (first_realm)
776 ceph_put_snap_realm(mdsc, first_realm);
Sage Weil963b61e2009-10-06 11:31:12 -0700777 pr_err("update_snap_trace error %d\n", err);
778 return err;
779}
780
781
782/*
783 * Send any cap_snaps that are queued for flush. Try to carry
784 * s_mutex across multiple snap flushes to avoid locking overhead.
785 *
786 * Caller holds no locks.
787 */
788static void flush_snaps(struct ceph_mds_client *mdsc)
789{
790 struct ceph_inode_info *ci;
791 struct inode *inode;
792 struct ceph_mds_session *session = NULL;
793
794 dout("flush_snaps\n");
795 spin_lock(&mdsc->snap_flush_lock);
796 while (!list_empty(&mdsc->snap_flush_list)) {
797 ci = list_first_entry(&mdsc->snap_flush_list,
798 struct ceph_inode_info, i_snap_flush_item);
799 inode = &ci->vfs_inode;
Sage Weil70b666c2011-05-27 09:24:26 -0700800 ihold(inode);
Sage Weil963b61e2009-10-06 11:31:12 -0700801 spin_unlock(&mdsc->snap_flush_lock);
Yan, Zhenged9b4302016-07-05 21:08:07 +0800802 ceph_flush_snaps(ci, &session);
Sage Weil963b61e2009-10-06 11:31:12 -0700803 iput(inode);
804 spin_lock(&mdsc->snap_flush_lock);
805 }
806 spin_unlock(&mdsc->snap_flush_lock);
807
808 if (session) {
809 mutex_unlock(&session->s_mutex);
810 ceph_put_mds_session(session);
811 }
812 dout("flush_snaps done\n");
813}
814
815
816/*
817 * Handle a snap notification from the MDS.
818 *
819 * This can take two basic forms: the simplest is just a snap creation
820 * or deletion notification on an existing realm. This should update the
821 * realm and its children.
822 *
823 * The more difficult case is realm creation, due to snap creation at a
824 * new point in the file hierarchy, or due to a rename that moves a file or
825 * directory into another realm.
826 */
827void ceph_handle_snap(struct ceph_mds_client *mdsc,
Sage Weil2600d2d2010-02-22 15:12:16 -0800828 struct ceph_mds_session *session,
Sage Weil963b61e2009-10-06 11:31:12 -0700829 struct ceph_msg *msg)
830{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700831 struct super_block *sb = mdsc->fsc->sb;
Sage Weil2600d2d2010-02-22 15:12:16 -0800832 int mds = session->s_mds;
Sage Weil963b61e2009-10-06 11:31:12 -0700833 u64 split;
834 int op;
835 int trace_len;
836 struct ceph_snap_realm *realm = NULL;
837 void *p = msg->front.iov_base;
838 void *e = p + msg->front.iov_len;
839 struct ceph_mds_snap_head *h;
840 int num_split_inos, num_split_realms;
841 __le64 *split_inos = NULL, *split_realms = NULL;
842 int i;
843 int locked_rwsem = 0;
844
Sage Weil963b61e2009-10-06 11:31:12 -0700845 /* decode */
846 if (msg->front.iov_len < sizeof(*h))
847 goto bad;
848 h = p;
849 op = le32_to_cpu(h->op);
850 split = le64_to_cpu(h->split); /* non-zero if we are splitting an
851 * existing realm */
852 num_split_inos = le32_to_cpu(h->num_split_inos);
853 num_split_realms = le32_to_cpu(h->num_split_realms);
854 trace_len = le32_to_cpu(h->trace_len);
855 p += sizeof(*h);
856
857 dout("handle_snap from mds%d op %s split %llx tracelen %d\n", mds,
858 ceph_snap_op_name(op), split, trace_len);
859
Sage Weil963b61e2009-10-06 11:31:12 -0700860 mutex_lock(&session->s_mutex);
861 session->s_seq++;
862 mutex_unlock(&session->s_mutex);
863
864 down_write(&mdsc->snap_rwsem);
865 locked_rwsem = 1;
866
867 if (op == CEPH_SNAP_OP_SPLIT) {
868 struct ceph_mds_snap_realm *ri;
869
870 /*
871 * A "split" breaks part of an existing realm off into
872 * a new realm. The MDS provides a list of inodes
873 * (with caps) and child realms that belong to the new
874 * child.
875 */
876 split_inos = p;
877 p += sizeof(u64) * num_split_inos;
878 split_realms = p;
879 p += sizeof(u64) * num_split_realms;
880 ceph_decode_need(&p, e, sizeof(*ri), bad);
881 /* we will peek at realm info here, but will _not_
882 * advance p, as the realm update will occur below in
883 * ceph_update_snap_trace. */
884 ri = p;
885
886 realm = ceph_lookup_snap_realm(mdsc, split);
Sage Weil963b61e2009-10-06 11:31:12 -0700887 if (!realm) {
888 realm = ceph_create_snap_realm(mdsc, split);
889 if (IS_ERR(realm))
890 goto out;
891 }
Sage Weil963b61e2009-10-06 11:31:12 -0700892
893 dout("splitting snap_realm %llx %p\n", realm->ino, realm);
894 for (i = 0; i < num_split_inos; i++) {
895 struct ceph_vino vino = {
896 .ino = le64_to_cpu(split_inos[i]),
897 .snap = CEPH_NOSNAP,
898 };
899 struct inode *inode = ceph_find_inode(sb, vino);
900 struct ceph_inode_info *ci;
Sage Weilae00d4f2010-09-16 16:26:51 -0700901 struct ceph_snap_realm *oldrealm;
Sage Weil963b61e2009-10-06 11:31:12 -0700902
903 if (!inode)
904 continue;
905 ci = ceph_inode(inode);
906
Sage Weilbe655592011-11-30 09:47:09 -0800907 spin_lock(&ci->i_ceph_lock);
Sage Weil963b61e2009-10-06 11:31:12 -0700908 if (!ci->i_snap_realm)
909 goto skip_inode;
910 /*
911 * If this inode belongs to a realm that was
912 * created after our new realm, we experienced
913 * a race (due to another split notifications
914 * arriving from a different MDS). So skip
915 * this inode.
916 */
917 if (ci->i_snap_realm->created >
918 le64_to_cpu(ri->created)) {
919 dout(" leaving %p in newer realm %llx %p\n",
920 inode, ci->i_snap_realm->ino,
921 ci->i_snap_realm);
922 goto skip_inode;
923 }
924 dout(" will move %p to split realm %llx %p\n",
925 inode, realm->ino, realm);
926 /*
Sage Weilae00d4f2010-09-16 16:26:51 -0700927 * Move the inode to the new realm
Sage Weil963b61e2009-10-06 11:31:12 -0700928 */
Yan, Zheng7d9c9192017-12-19 18:00:54 +0800929 oldrealm = ci->i_snap_realm;
930 spin_lock(&oldrealm->inodes_with_caps_lock);
Sage Weil963b61e2009-10-06 11:31:12 -0700931 list_del_init(&ci->i_snap_realm_item);
Yan, Zheng7d9c9192017-12-19 18:00:54 +0800932 spin_unlock(&oldrealm->inodes_with_caps_lock);
933
934 spin_lock(&realm->inodes_with_caps_lock);
Sage Weilae00d4f2010-09-16 16:26:51 -0700935 list_add(&ci->i_snap_realm_item,
936 &realm->inodes_with_caps);
Sage Weilae00d4f2010-09-16 16:26:51 -0700937 ci->i_snap_realm = realm;
Luis Henriquese3161f12018-01-12 17:19:28 +0000938 if (realm->ino == ci->i_vino.ino)
939 realm->inode = inode;
Sage Weil052bb342010-03-09 12:52:26 -0800940 spin_unlock(&realm->inodes_with_caps_lock);
Yan, Zheng7d9c9192017-12-19 18:00:54 +0800941
Sage Weilbe655592011-11-30 09:47:09 -0800942 spin_unlock(&ci->i_ceph_lock);
Sage Weil963b61e2009-10-06 11:31:12 -0700943
Sage Weilae00d4f2010-09-16 16:26:51 -0700944 ceph_get_snap_realm(mdsc, realm);
945 ceph_put_snap_realm(mdsc, oldrealm);
Sage Weil963b61e2009-10-06 11:31:12 -0700946
947 iput(inode);
948 continue;
949
950skip_inode:
Sage Weilbe655592011-11-30 09:47:09 -0800951 spin_unlock(&ci->i_ceph_lock);
Sage Weil963b61e2009-10-06 11:31:12 -0700952 iput(inode);
953 }
954
955 /* we may have taken some of the old realm's children. */
956 for (i = 0; i < num_split_realms; i++) {
957 struct ceph_snap_realm *child =
Yan, Zheng982d6012014-12-23 15:30:54 +0800958 __lookup_snap_realm(mdsc,
Sage Weil963b61e2009-10-06 11:31:12 -0700959 le64_to_cpu(split_realms[i]));
Sage Weil963b61e2009-10-06 11:31:12 -0700960 if (!child)
961 continue;
962 adjust_snap_realm_parent(mdsc, child, realm->ino);
963 }
964 }
965
966 /*
967 * update using the provided snap trace. if we are deleting a
968 * snap, we can avoid queueing cap_snaps.
969 */
970 ceph_update_snap_trace(mdsc, p, e,
Yan, Zheng982d6012014-12-23 15:30:54 +0800971 op == CEPH_SNAP_OP_DESTROY, NULL);
Sage Weil963b61e2009-10-06 11:31:12 -0700972
Sage Weilae00d4f2010-09-16 16:26:51 -0700973 if (op == CEPH_SNAP_OP_SPLIT)
Sage Weil963b61e2009-10-06 11:31:12 -0700974 /* we took a reference when we created the realm, above */
975 ceph_put_snap_realm(mdsc, realm);
Sage Weil963b61e2009-10-06 11:31:12 -0700976
977 __cleanup_empty_realms(mdsc);
978
979 up_write(&mdsc->snap_rwsem);
980
981 flush_snaps(mdsc);
982 return;
983
984bad:
985 pr_err("corrupt snap message from mds%d\n", mds);
Sage Weil9ec7cab2009-12-14 15:13:47 -0800986 ceph_msg_dump(msg);
Sage Weil963b61e2009-10-06 11:31:12 -0700987out:
988 if (locked_rwsem)
989 up_write(&mdsc->snap_rwsem);
990 return;
991}