3 #include <linux/module.h>
5 #include <linux/slab.h>
6 #include <linux/string.h>
8 #include <linux/kernel.h>
40 ceph_inode(inode)->i_vino = *(
struct ceph_vino *)data;
48 ino_t t = ceph_vino_to_ino(vino);
50 inode =
iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino);
54 dout(
"get_inode created new inode %p %llx.%llx ino %llx\n",
59 dout(
"get_inode on %lu=%llx.%llx got %p\n", inode->
i_ino, vino.
ino,
70 .
ino = ceph_ino(parent),
134 pr_err(
"__get_or_create_frag ENOMEM on %p %llx.%llx "
144 rb_link_node(&frag->
node, parent, p);
147 dout(
"get_or_create_frag added %llx.%llx frag %x\n",
182 u32 t = ceph_frag_make(0, 0);
192 WARN_ON(!ceph_frag_contains_value(t, v));
198 memcpy(pfrag, frag,
sizeof(*pfrag));
206 dout(
"choose_frag(%x) %x splits by %d (%d ways)\n", v, t,
208 for (i = 0; i < nway; i++) {
209 n = ceph_frag_make_child(t, frag->
split_by, i);
210 if (ceph_frag_contains_value(n, v)) {
217 dout(
"choose_frag(%x) = %x\n", v, t);
228 static int ceph_fill_dirfrag(
struct inode *inode,
247 dout(
"fill_dirfrag removed %llx.%llx frag %x"
253 dout(
"fill_dirfrag cleared %llx.%llx frag %x"
263 frag = __get_or_create_frag(ci,
id);
267 pr_err(
"fill_dirfrag ENOMEM on mds ref %llx.%llx fg %x\n",
275 for (i = 0; i < frag->
ndist; i++)
277 dout(
"fill_dirfrag %llx.%llx frag %x ndist=%d\n",
327 INIT_LIST_HEAD(&ci->i_dirty_item);
396 dout(
"destroy_inode %p ino %llx.%llx\n", inode,
ceph_vinop(inode));
406 ceph_sb_to_client(ci->
vfs_inode.i_sb)->mdsc;
409 dout(
" dropping residual ref to snap realm %p\n", realm);
427 ceph_buffer_put(ci->
i_xattrs.prealloc_blob);
449 dout(
"size %lld -> %llu\n", inode->
i_size, size);
451 inode->
i_blocks = (size + (1<<9) - 1) >> 9;
454 dout(
"truncate_seq %u -> %u\n",
495 if (timespec_compare(ctime, &inode->
i_ctime) > 0) {
496 dout(
"ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n",
503 dout(
"mtime %ld.%09ld -> %ld.%09ld "
514 if (timespec_compare(mtime, &inode->
i_mtime) > 0) {
515 dout(
"mtime %ld.%09ld -> %ld.%09ld inc\n",
521 if (timespec_compare(atime, &inode->
i_atime) > 0) {
522 dout(
"atime %ld.%09ld -> %ld.%09ld inc\n",
545 dout(
"%p mds time_warp_seq %llu < %u\n",
553 static int fill_inode(
struct inode *inode,
557 unsigned long ttl_from,
int cap_fmode,
563 int issued = 0, implemented;
564 int updating_inode = 0;
571 dout(
"fill_inode %p ino %llx.%llx v %llu had %llu\n",
583 pr_err(
"fill_inode ENOMEM xattr blob %d bytes\n",
606 issued |= implemented | __ceph_caps_dirty(ci);
617 dout(
"%p mode 0%o uid.gid %d.%d\n", inode, inode->
i_mode,
626 ceph_decode_timespec(&
mtime, &info->mtime);
627 ceph_decode_timespec(&
ctime, &info->ctime);
663 &ceph_sb_to_client(inode->
i_sb)->backing_dev_info;
678 inode->
i_op = &ceph_symlink_iops;
715 pr_err(
"fill_inode %llx.%llx BAD mode 0%o\n",
730 for (i = 0; i <
nsplits; i++) {
742 if (info->
cap.caps) {
756 dout(
" %p got snap_caps %s\n", inode,
760 __ceph_get_fmode(ci, cap_fmode);
763 }
else if (cap_fmode >= 0) {
764 pr_warning(
"mds issued no caps on %llx.%llx\n",
766 __ceph_get_fmode(ci, cap_fmode);
777 dout(
" marking %p complete (empty)\n", inode);
784 ceph_fill_dirfrag(inode, dirinfo);
790 ceph_buffer_put(xattr_blob);
800 unsigned long from_time)
804 long unsigned ttl = from_time + (duration *
HZ) / 1000;
805 long unsigned half_ttl = from_time + (duration *
HZ / 2) / 1000;
812 spin_lock(&dentry->
d_lock);
813 dout(
"update_dentry_lease %p duration %lu ms ttl %lu\n",
814 dentry, duration, ttl);
840 spin_unlock(&dentry->
d_lock);
850 static void ceph_set_dentry_offset(
struct dentry *
dn)
853 struct inode *inode = dir->
d_inode;
859 ci = ceph_inode(inode);
860 di = ceph_dentry(dn);
867 di->
offset = ceph_inode(inode)->i_max_offset++;
873 dout(
"set_dentry_offset %p %lld (%p %p)\n", dn, di->
offset,
876 spin_unlock(&dir->
d_lock);
887 static struct dentry *splice_dentry(
struct dentry *dn,
struct inode *
in,
888 bool *prehash,
bool set_offset)
890 struct dentry *realdn;
898 if (IS_ERR(realdn)) {
899 pr_err(
"splice_dentry error %ld %p inode %p ino %llx.%llx\n",
906 dout(
"dn %p (%d) spliced with %p (%d) "
907 "inode %p ino %llx.%llx\n",
915 dout(
"dn %p attached to %p ino %llx.%llx\n",
918 if ((!prehash || *prehash) && d_unhashed(dn))
921 ceph_set_dentry_offset(dn);
941 struct inode *in =
NULL;
948 dout(
"fill_trace %p is_dentry %d is_target %d\n", req,
949 rinfo->
head->is_dentry, rinfo->
head->is_target);
963 pr_info(
"fill_trace faking empty trace on %lld %s\n",
965 if (rinfo->
head->is_dentry) {
966 rinfo->
head->is_dentry = 0;
971 if (rinfo->
head->is_target) {
972 rinfo->
head->is_target = 0;
985 if (!rinfo->
head->is_target && !rinfo->
head->is_dentry) {
986 dout(
"fill_trace reply is empty!\n");
992 if (rinfo->
head->is_dentry) {
996 err = fill_inode(dir, &rinfo->diri, rinfo->
dirfrag,
1022 bool have_dir_cap, have_lease;
1038 have_lease = have_dir_cap ||
1041 dout(
"fill_trace no dentry lease or dir cap\n");
1045 dout(
" src %p '%.*s' dst %p '%.*s'\n",
1050 dout(
"fill_trace doing d_move %p -> %p\n",
1054 dout(
" src %p '%.*s' dst %p '%.*s'\n",
1079 if (!rinfo->
head->is_target) {
1080 dout(
"fill_trace null dentry\n");
1082 dout(
"d_delete %p\n", dn);
1085 dout(
"d_instantiate %p NULL\n", dn);
1087 if (have_lease && d_unhashed(dn))
1089 update_dentry_lease(dn, rinfo->
dlease,
1104 pr_err(
"fill_trace bad get_inode "
1105 "%llx.%llx\n", vino.
ino, vino.
snap);
1110 dn = splice_dentry(dn, in, &have_lease,
true);
1117 }
else if (ceph_ino(in) == vino.
ino &&
1118 ceph_snap(in) == vino.
snap) {
1121 dout(
" %p links to %p %llx.%llx, not %llx.%llx\n",
1122 dn, in, ceph_ino(in), ceph_snap(in),
1129 update_dentry_lease(dn, rinfo->
dlease, session,
1131 dout(
" final dn %p\n", dn);
1146 pr_err(
"fill_inode get_inode badness %llx.%llx\n",
1152 dout(
" linking snapped dir %p to dn %p\n", in, dn);
1153 dn = splice_dentry(dn, in,
NULL,
true);
1160 rinfo->
head->is_dentry = 1;
1163 if (rinfo->
head->is_target) {
1167 if (in ==
NULL || ceph_ino(in) != vino.
ino ||
1168 ceph_snap(in) != vino.
snap) {
1177 err = fill_inode(in,
1184 pr_err(
"fill_inode badness %p %llx.%llx\n",
1191 dout(
"fill_trace done err=%d\n", err);
1201 struct dentry *parent = req->
r_dentry;
1207 struct inode *snapdir =
NULL;
1215 dout(
"readdir_prepopulate %d items under SNAPDIR dn %p\n",
1218 dout(
"readdir_prepopulate %d items under dn %p\n",
1224 for (i = 0; i < rinfo->
dir_nr; i++) {
1236 dout(
"d_lookup on parent=%p name=%.*s got %p\n",
1237 parent, dname.len, dname.
name, dn);
1241 dout(
"d_alloc %p '%.*s' = %p\n", parent,
1242 dname.len, dname.
name, dn);
1244 dout(
"d_alloc badness\n");
1256 dout(
" dn %p points to wrong inode %p\n",
1263 spin_lock(&parent->
d_lock);
1266 spin_unlock(&dn->
d_lock);
1267 spin_unlock(&parent->
d_lock);
1279 dout(
"new_inode badness\n");
1285 dn = splice_dentry(dn, in,
NULL,
false);
1290 if (fill_inode(in, &rinfo->
dir_in[i],
NULL, session,
1293 pr_err(
"fill_inode badness on %p\n", in);
1297 update_dentry_lease(dn, rinfo->
dir_dlease[i],
1311 dout(
"readdir_prepopulate done\n");
1321 dout(
"set_size %p %llu -> %llu\n", inode, inode->
i_size, size);
1323 inode->
i_blocks = (size + (1 << 9) - 1) >> 9;
1341 if (
queue_work(ceph_inode_to_client(inode)->wb_wq,
1343 dout(
"ceph_queue_writeback %p\n", inode);
1345 dout(
"ceph_queue_writeback %p failed\n", inode);
1356 dout(
"writeback %p\n", inode);
1367 if (
queue_work(ceph_inode_to_client(inode)->pg_inv_wq,
1368 &ceph_inode(inode)->i_pg_inv_work)) {
1369 dout(
"ceph_queue_invalidate %p\n", inode);
1371 dout(
"ceph_queue_invalidate %p failed\n", inode);
1389 dout(
"invalidate_pages %p gen %d revoking %d\n", inode,
1404 dout(
"invalidate_pages %p gen %d successful\n", inode,
1409 dout(
"invalidate_pages %p gen %d raced, now %d revoking %d\n",
1427 static void ceph_vmtruncate_work(
struct work_struct *work)
1433 dout(
"vmtruncate_work %p\n", inode);
1451 dout(
"ceph_queue_vmtruncate %p\n", inode);
1453 dout(
"ceph_queue_vmtruncate %p failed, pending=%d\n",
1469 int wrbuffer_refs, wake = 0;
1474 dout(
"__do_pending_vmtruncate %p none pending\n", inode);
1484 dout(
"__do_pending_vmtruncate %p flushing snaps first\n",
1488 inode->
i_sb->s_maxbytes);
1494 dout(
"__do_pending_vmtruncate %p (%d) to %lld\n", inode,
1506 if (wrbuffer_refs == 0)
1516 static void *ceph_sym_follow_link(
struct dentry *dentry,
struct nameidata *nd)
1525 .follow_link = ceph_sym_follow_link,
1533 struct inode *inode = dentry->
d_inode;
1535 struct inode *parent_inode;
1536 const unsigned int ia_valid = attr->
ia_valid;
1543 int inode_dirty_flags = 0;
1557 return PTR_ERR(req);
1564 dout(
"setattr %p uid %d -> %d\n", inode,
1566 if (issued & CEPH_CAP_AUTH_EXCL) {
1577 dout(
"setattr %p gid %d -> %d\n", inode,
1579 if (issued & CEPH_CAP_AUTH_EXCL) {
1590 dout(
"setattr %p mode 0%o -> 0%o\n", inode, inode->
i_mode,
1592 if (issued & CEPH_CAP_AUTH_EXCL) {
1604 dout(
"setattr %p atime %ld.%ld -> %ld.%ld\n", inode,
1607 if (issued & CEPH_CAP_FILE_EXCL) {
1612 timespec_compare(&inode->
i_atime,
1626 dout(
"setattr %p mtime %ld.%ld -> %ld.%ld\n", inode,
1629 if (issued & CEPH_CAP_FILE_EXCL) {
1634 timespec_compare(&inode->
i_mtime,
1648 dout(
"setattr %p size %lld -> %lld\n", inode,
1654 if ((issued & CEPH_CAP_FILE_EXCL) &&
1658 (attr->
ia_size + (1 << 9) - 1) >> 9;
1675 bool only = (ia_valid & (ATTR_SIZE|ATTR_MTIME|ATTR_ATIME|
1676 ATTR_MODE|ATTR_UID|
ATTR_GID)) == 0;
1677 dout(
"setattr %p ctime %ld.%ld -> %ld.%ld (%s)\n", inode,
1680 only ?
"ctime only" :
"ignored");
1688 if (issued & CEPH_CAP_AUTH_EXCL)
1690 else if (issued & CEPH_CAP_FILE_EXCL)
1692 else if (issued & CEPH_CAP_XATTR_EXCL)
1699 dout(
"setattr %p ATTR_FILE ... hrm!\n", inode);
1709 if (inode_dirty_flags)
1722 dout(
"setattr %p result=%d (%s locally, %d remote)\n", inode, err,
1725 ceph_mdsc_put_request(req);
1730 ceph_mdsc_put_request(req);
1746 dout(
"do_getattr inode %p SNAPDIR\n", inode);
1751 if (ceph_caps_issued_mask(ceph_inode(inode), mask, 1))
1756 return PTR_ERR(req);
1762 ceph_mdsc_put_request(req);
1763 dout(
"do_getattr result=%d\n", err);
1793 struct inode *inode = dentry->
d_inode;
1800 stat->
ino = ceph_translate_ino(inode->
i_sb, inode->
i_ino);
1802 stat->
dev = ceph_snap(inode);