4 #include <linux/slab.h>
65 dout(
"get_realm %p %d -> %d\n", realm,
82 static void __insert_snap_realm(
struct rb_root *root,
92 if (new->ino < r->
ino)
94 else if (new->ino > r->
ino)
100 rb_link_node(&new->node, parent, p);
115 realm = kzalloc(
sizeof(*realm),
GFP_NOFS);
128 dout(
"create_snap_realm %llx %p\n", realm->
ino, realm);
147 else if (ino > r->
ino)
150 dout(
"lookup_snap_realm %llx %p\n", r->
ino, r);
166 dout(
"__destroy_snap_realm %p %llx\n", realm, realm->
ino);
172 __put_snap_realm(mdsc, realm->
parent);
187 dout(
"__put_snap_realm %llx %p %d -> %d\n", realm->
ino, realm,
190 __destroy_snap_realm(mdsc, realm);
199 dout(
"put_snap_realm %llx %p %d -> %d\n", realm->
ino, realm,
205 __destroy_snap_realm(mdsc, realm);
231 __destroy_snap_realm(mdsc, realm);
240 __cleanup_empty_realms(mdsc);
263 parent = ceph_create_snap_realm(mdsc, parentino);
265 return PTR_ERR(parent);
267 dout(
"adjust_snap_realm_parent %llx %p: %llx %p -> %llx %p\n",
282 static int cmpu64_rev(
const void *
a,
const void *
b)
284 if (*(
u64 *)a < *(
u64 *)b)
286 if (*(
u64 *)a > *(
u64 *)b)
308 err = build_snap_context(parent);
323 dout(
"build_snap_context %llx %p: %p seq %lld (%u snaps)"
333 if (num > (
SIZE_MAX -
sizeof(*snapc)) /
sizeof(
u64))
335 snapc = kzalloc(
sizeof(*snapc) + num*
sizeof(
u64),
GFP_NOFS);
351 snapc->
snaps[num++] =
365 dout(
"build_snap_context %llx %p: %p seq %lld (%u snaps)\n",
366 realm->
ino, realm, snapc, snapc->
seq,
383 pr_err(
"build_snap_context %llx %p fail %d\n", realm->
ino,
395 dout(
"rebuild_snap_realms %llx %p\n", realm->
ino, realm);
396 build_snap_context(realm);
399 rebuild_snap_realms(child);
416 for (i = 0; i < num; i++)
445 capsnap = kzalloc(
sizeof(*capsnap),
GFP_NOFS);
447 pr_err(
"ENOMEM allocating ceph_cap_snap on %p\n", inode);
453 dirty = __ceph_caps_dirty(ci);
463 if (__ceph_have_pending_cap_snap(ci)) {
468 dout(
"queue_cap_snap %p already pending\n", inode);
481 dout(
"queue_cap_snap %p cap_snap %p queuing under %p %s\n",
487 INIT_LIST_HEAD(&capsnap->ci_item);
515 ceph_get_snap_context(ci->
i_snap_realm->cached_context);
519 if (used & CEPH_CAP_FILE_WR) {
520 dout(
"queue_cap_snap %p cap_snap %p snapc %p"
521 " seq %llu used WR, now pending\n", inode,
522 capsnap, snapc, snapc->
seq);
529 dout(
"queue_cap_snap %p nothing dirty|writing\n", inode);
552 capsnap->mtime = inode->
i_mtime;
553 capsnap->atime = inode->
i_atime;
557 dout(
"finish_cap_snap %p cap_snap %p snapc %p %llu %s s=%llu "
558 "still has %d dirty pages\n", inode, capsnap,
564 dout(
"finish_cap_snap %p cap_snap %p snapc %p %llu %s s=%llu\n",
565 inode, capsnap, capsnap->
context,
585 dout(
"queue_realm_cap_snaps %p %llx inodes\n", realm, realm->
ino);
605 dout(
"queue_realm_cap_snaps %p %llx queue child %p %llx\n",
606 realm, realm->
ino, child, child->
ino);
612 dout(
"queue_realm_cap_snaps %p %llx done\n", realm, realm->
ino);
623 void *p,
void *
e,
bool deletion)
627 __le64 *prior_parent_snaps;
633 dout(
"update_snap_trace deletion=%d\n", deletion);
642 prior_parent_snaps =
p;
649 err = PTR_ERR(realm);
661 dout(
"update_snap_trace updating %llx %p %lld -> %lld\n",
685 dout(
"update_snap_trace %llx %p seq %lld new\n",
686 realm->
ino, realm, realm->
seq);
689 dout(
"update_snap_trace %llx %p seq %lld unchanged\n",
690 realm->
ino, realm, realm->
seq);
693 dout(
"done with %llx %p, invalidated=%d, %p %p\n", realm->
ino,
694 realm, invalidate, p, e);
701 rebuild_snap_realms(realm);
707 while (!list_empty(&dirty_realms)) {
710 queue_realm_cap_snaps(realm);
713 __cleanup_empty_realms(mdsc);
719 pr_err(
"update_snap_trace error %d\n", err);
736 dout(
"flush_snaps\n");
756 dout(
"flush_snaps done\n");
776 int mds = session->
s_mds;
781 void *p = msg->
front.iov_base;
782 void *
e = p + msg->
front.iov_len;
787 int locked_rwsem = 0;
790 if (msg->
front.iov_len <
sizeof(*h))
801 dout(
"handle_snap from mds%d op %s split %llx tracelen %d\n", mds,
821 p +=
sizeof(
u64) * num_split_inos;
823 p +=
sizeof(
u64) * num_split_realms;
832 realm = ceph_create_snap_realm(mdsc, split);
838 dout(
"splitting snap_realm %llx %p\n", realm->
ino, realm);
844 struct inode *inode = ceph_find_inode(sb, vino);
850 ci = ceph_inode(inode);
864 dout(
" leaving %p in newer realm %llx %p\n",
869 dout(
" will move %p to split realm %llx %p\n",
870 inode, realm->
ino, realm);
901 adjust_snap_realm_parent(mdsc, child, realm->
ino);
916 __cleanup_empty_realms(mdsc);
924 pr_err(
"corrupt snap message from mds%d\n", mds);