#include <linux/ceph/ceph_debug.h> #include <linux/module.h>#include <linux/fs.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/uaccess.h>#include <linux/kernel.h>#include <linux/namei.h>#include <linux/writeback.h>#include <linux/vmalloc.h> #include "super.h"#include "mds_client.h"#include <linux/ceph/decode.h> /* * Ceph inode operations * * Implement basic inode helpers (get, alloc) and inode ops (getattr, * setattr, etc.), xattr helpers, and helpers for assimilating * metadata returned by the MDS into our cache. * * Also define helpers for doing asynchronous writeback, invalidation, * and truncation for the benefit of those who can't afford to block * (typically because they are in the message handler path). */ static const struct inode_operations ceph_symlink_iops; static void ceph_invalidate_work(struct work_struct *work);static void ceph_writeback_work(struct work_struct *work);static void ceph_vmtruncate_work(struct work_struct *work); /* * find or create an inode, given the ceph ino number */static int ceph_set_ino_cb(struct inode *inode, void *data){ ceph_inode(inode)->i_vino = *(struct ceph_vino *)data; inode->i_ino = ceph_vino_to_ino(*(struct ceph_vino *)data); return 0;} struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino){ struct inode *inode; ino_t t = ceph_vino_to_ino(vino); inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino); if (inode == NULL) return ERR_PTR(-ENOMEM); if (inode->i_state & I_NEW) { dout("get_inode created new inode %p %llx.%llx ino %llx\n", inode, ceph_vinop(inode), (u64)inode->i_ino); unlock_new_inode(inode); } dout("get_inode on %lu=%llx.%llx got %p\n", inode->i_ino, vino.ino, vino.snap, inode); return inode;} /* * get/constuct snapdir inode for a given directory */struct inode *ceph_get_snapdir(struct inode *parent){ struct ceph_vino vino = { .ino = ceph_ino(parent), .snap = CEPH_SNAPDIR, }; struct inode *inode = ceph_get_inode(parent->i_sb, vino); struct ceph_inode_info *ci = ceph_inode(inode); BUG_ON(!S_ISDIR(parent->i_mode)); if (IS_ERR(inode)) return inode; inode->i_mode = parent->i_mode; inode->i_uid = parent->i_uid; inode->i_gid = parent->i_gid; inode->i_op = &ceph_dir_iops; inode->i_fop = &ceph_dir_fops; ci->i_snap_caps = CEPH_CAP_PIN; /* so we can open */ ci->i_rbytes = 0; return inode;} const struct inode_operations ceph_file_iops = { .permission = ceph_permission, .setattr = ceph_setattr, .getattr = ceph_getattr, .setxattr = ceph_setxattr, .getxattr = ceph_getxattr, .listxattr = ceph_listxattr, .removexattr = ceph_removexattr,}; /* * We use a 'frag tree' to keep track of the MDS's directory fragments * for a given inode (usually there is just a single fragment). We * need to know when a child frag is delegated to a new MDS, or when * it is flagged as replicated, so we can direct our requests * accordingly. */ /* * find/create a frag in the tree */static struct ceph_inode_frag *__get_or_create_frag(struct ceph_inode_info *ci, u32 f){ struct rb_node **p; struct rb_node *parent = NULL; struct ceph_inode_frag *frag; int c; p = &ci->i_fragtree.rb_node; while (*p) { parent = *p; frag = rb_entry(parent, struct ceph_inode_frag, node); c = ceph_frag_compare(f, frag->frag); if (c < 0) p = &(*p)->rb_left; else if (c > 0) p = &(*p)->rb_right; else return frag; } frag = kmalloc(sizeof(*frag), GFP_NOFS); if (!frag) { pr_err("__get_or_create_frag ENOMEM on %p %llx.%llx " "frag %x\n", &ci->vfs_inode, ceph_vinop(&ci->vfs_inode), f); return ERR_PTR(-ENOMEM); } frag->frag = f; frag->split_by = 0; frag->mds = -1; frag->ndist = 0; rb_link_node(&frag->node, parent, p); rb_insert_color(&frag->node, &ci->i_fragtree); dout("get_or_create_frag added %llx.%llx frag %x\n", ceph_vinop(&ci->vfs_inode), f); return frag;} /* * find a specific frag @f */struct ceph_inode_frag *__ceph_find_frag(struct ceph_inode_info *ci, u32 f){ struct rb_node *n = ci->i_fragtree.rb_node; while (n) { struct ceph_inode_frag *frag = rb_entry(n, struct ceph_inode_frag, node); int c = ceph_frag_compare(f, frag->frag); if (c < 0) n = n->rb_left; else if (c > 0) n = n->rb_right; else return frag; } return NULL;} /* * Choose frag containing the given value @v. If @pfrag is * specified, copy the frag delegation info to the caller if * it is present. */u32 ceph_choose_frag(struct ceph_inode_info *ci, u32 v, struct ceph_inode_frag *pfrag, int *found){ u32 t = ceph_frag_make(0, 0); struct ceph_inode_frag *frag; unsigned nway, i; u32 n; if (found) *found = 0; mutex_lock(&ci->i_fragtree_mutex); while (1) { WARN_ON(!ceph_frag_contains_value(t, v)); frag = __ceph_find_frag(ci, t); if (!frag) break; /* t is a leaf */ if (frag->split_by == 0) { if (pfrag) memcpy(pfrag, frag, sizeof(*pfrag)); if (found) *found = 1; break; } /* choose child */ nway = 1 << frag->split_by; dout("choose_frag(%x) %x splits by %d (%d ways)\n", v, t, frag->split_by, nway); for (i = 0; i < nway; i++) { n = ceph_frag_make_child(t, frag->split_by, i); if (ceph_frag_contains_value(n, v)) { t = n; break; } } BUG_ON(i == nway); } dout("choose_frag(%x) = %x\n", v, t); mutex_unlock(&ci->i_fragtree_mutex); return t;} /* * Process dirfrag (delegation) info from the mds. Include leaf * fragment in tree ONLY if ndist > 0. Otherwise, only * branches/splits are included in i_fragtree) */static int ceph_fill_dirfrag(struct inode *inode, struct ceph_mds_reply_dirfrag *dirinfo){ struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_frag *frag; u32 id = le32_to_cpu(dirinfo->frag); int mds = le32_to_cpu(dirinfo->auth); int ndist = le32_to_cpu(dirinfo->ndist); int i; int err = 0; mutex_lock(&ci->i_fragtree_mutex); if (ndist == 0) { /* no delegation info needed. */ frag = __ceph_find_frag(ci, id); if (!frag) goto out; if (frag->split_by == 0) { /* tree leaf, remove */ dout("fill_dirfrag removed %llx.%llx frag %x" " (no ref)\n", ceph_vinop(inode), id); rb_erase(&frag->node, &ci->i_fragtree); kfree(frag); } else { /* tree branch, keep and clear */ dout("fill_dirfrag cleared %llx.%llx frag %x" " referral\n", ceph_vinop(inode), id); frag->mds = -1; frag->ndist = 0; } goto out; } /* find/add this frag to store mds delegation info */ frag = __get_or_create_frag(ci, id); if (IS_ERR(frag)) { /* this is not the end of the world; we can continue with bad/inaccurate delegation info */ pr_err("fill_dirfrag ENOMEM on mds ref %llx.%llx fg %x\n", ceph_vinop(inode), le32_to_cpu(dirinfo->frag)); err = -ENOMEM; goto out; } frag->mds = mds; frag->ndist = min_t(u32, ndist, CEPH_MAX_DIRFRAG_REP); for (i = 0; i < frag->ndist; i++) frag->dist[i] = le32_to_cpu(dirinfo->dist[i]); dout("fill_dirfrag %llx.%llx frag %x ndist=%d\n", ceph_vinop(inode), frag->frag, frag->ndist); out: mutex_unlock(&ci->i_fragtree_mutex); return err;} /* * initialize a newly allocated inode. */struct inode *ceph_alloc_inode(struct super_block *sb){ struct ceph_inode_info *ci; int i; ci = kmem_cache_alloc(ceph_inode_cachep, GFP_NOFS); if (!ci) return NULL; dout("alloc_inode %p\n", &ci->vfs_inode); spin_lock_init(&ci->i_ceph_lock); ci->i_version = 0; ci->i_time_warp_seq = 0; ci->i_ceph_flags = 0; ci->i_release_count = 0; ci->i_symlink = NULL; memset(&ci->i_dir_layout, 0, sizeof(ci->i_dir_layout)); ci->i_fragtree = RB_ROOT; mutex_init(&ci->i_fragtree_mutex); ci->i_xattrs.blob = NULL; ci->i_xattrs.prealloc_blob = NULL; ci->i_xattrs.dirty = false; ci->i_xattrs.index = RB_ROOT; ci->i_xattrs.count = 0; ci->i_xattrs.names_size = 0; ci->i_xattrs.vals_size = 0; ci->i_xattrs.version = 0; ci->i_xattrs.index_version = 0; ci->i_caps = RB_ROOT; ci->i_auth_cap = NULL; ci->i_dirty_caps = 0; ci->i_flushing_caps = 0; INIT_LIST_HEAD(&ci->i_dirty_item); INIT_LIST_HEAD(&ci->i_flushing_item); ci->i_cap_flush_seq = 0; ci->i_cap_flush_last_tid = 0; memset(&ci->i_cap_flush_tid, 0, sizeof(ci->i_cap_flush_tid)); init_waitqueue_head(&ci->i_cap_wq); ci->i_hold_caps_min = 0; ci->i_hold_caps_max = 0; INIT_LIST_HEAD(&ci->i_cap_delay_list); ci->i_cap_exporting_mds = 0; ci->i_cap_exporting_mseq = 0; ci->i_cap_exporting_issued = 0; INIT_LIST_HEAD(&ci->i_cap_snaps); ci->i_head_snapc = NULL; ci->i_snap_caps = 0; for (i = 0; i < CEPH_FILE_MODE_NUM; i++) ci->i_nr_by_mode[i] = 0; ci->i_truncate_seq = 0; ci->i_truncate_size = 0; ci->i_truncate_pending = 0; ci->i_max_size = 0; ci->i_reported_size = 0; ci->i_wanted_max_size = 0; ci->i_requested_max_size = 0; ci->i_pin_ref = 0; ci->i_rd_ref = 0; ci->i_rdcache_ref = 0; ci->i_wr_ref = 0; ci->i_wb_ref = 0; ci->i_wrbuffer_ref = 0; ci->i_wrbuffer_ref_head = 0; ci->i_shared_gen = 0; ci->i_rdcache_gen = 0; ci->i_rdcache_revoking = 0; INIT_LIST_HEAD(&ci->i_unsafe_writes); INIT_LIST_HEAD(&ci->i_unsafe_dirops); spin_lock_init(&ci->i_unsafe_lock); ci->i_snap_realm = NULL; INIT_LIST_HEAD(&ci->i_snap_realm_item); INIT_LIST_HEAD(&ci->i_snap_flush_item); INIT_WORK(&ci->i_wb_work, ceph_writeback_work); INIT_WORK(&ci->i_pg_inv_work, ceph_invalidate_work); INIT_WORK(&ci->i_vmtruncate_work, ceph_vmtruncate_work); return &ci->vfs_inode;} static void ceph_i_callback(struct rcu_head *head){ struct inode *inode = container_of(head, struct inode, i_rcu); struct ceph_inode_info *ci = ceph_inode(inode); kmem_cache_free(ceph_inode_cachep, ci);} void ceph_destroy_inode(struct inode *inode){ struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_frag *frag; struct rb_node *n; dout("destroy_inode %p ino %llx.%llx\n", inode, ceph_vinop(inode)); ceph_queue_caps_release(inode); /* * we may still have a snap_realm reference if there are stray * caps in i_cap_exporting_issued or i_snap_caps. */ if (ci->i_snap_realm) { struct ceph_mds_client *mdsc = ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; struct ceph_snap_realm *realm = ci->i_snap_realm; dout(" dropping residual ref to snap realm %p\n", realm); spin_lock(&realm->inodes_with_caps_lock); list_del_init(&ci->i_snap_realm_item); spin_unlock(&realm->inodes_with_caps_lock); ceph_put_snap_realm(mdsc, realm); } kfree(ci->i_symlink); while ((n = rb_first(&ci->i_fragtree)) != NULL) { frag = rb_entry(n, struct ceph_inode_frag, node); rb_erase(n, &ci->i_fragtree); kfree(frag); } __ceph_destroy_xattrs(ci); if (ci->i_xattrs.blob) ceph_buffer_put(ci->i_xattrs.blob); if (ci->i_xattrs.prealloc_blob) ceph_buffer_put(ci->i_xattrs.prealloc_blob); call_rcu(&inode->i_rcu, ceph_i_callback);} /* * Helpers to fill in size, ctime, mtime, and atime. We have to be * careful because either the client or MDS may have more up to date * info, depending on which capabilities are held, and whether * time_warp_seq or truncate_seq have increased. (Ordinarily, mtime * and size are monotonically increasing, except when utimes() or * truncate() increments the corresponding _seq values.) */int ceph_fill_file_size(struct inode *inode, int issued, u32 truncate_seq, u64 truncate_size, u64 size){ struct ceph_inode_info *ci = ceph_inode(inode); int queue_trunc = 0; if (ceph_seq_cmp(truncate_seq, ci->i_truncate_seq) > 0 || (truncate_seq == ci->i_truncate_seq && size > inode->i_size)) { dout("size %lld -> %llu\n", inode->i_size, size); inode->i_size = size; inode->i_blocks = (size + (1<<9) - 1) >> 9; ci->i_reported_size = size; if (truncate_seq != ci->i_truncate_seq) { dout("truncate_seq %u -> %u\n", ci->i_truncate_seq, truncate_seq); ci->i_truncate_seq = truncate_seq; /* * If we hold relevant caps, or in the case where we're * not the only client referencing this file and we * don't hold those caps, then we need to check whether * the file is either opened or mmaped */ if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_RD| CEPH_CAP_FILE_WR|CEPH_CAP_FILE_BUFFER| CEPH_CAP_FILE_EXCL| CEPH_CAP_FILE_LAZYIO)) || mapping_mapped(inode->i_mapping) || __ceph_caps_file_wanted(ci)) { ci->i_truncate_pending++; queue_trunc = 1; } } } if (ceph_seq_cmp(truncate_seq, ci->i_truncate_seq) >= 0 && ci->i_truncate_size != truncate_size) { dout("truncate_size %lld -> %llu\n", ci->i_truncate_size, truncate_size); ci->i_truncate_size = truncate_size; } return queue_trunc;} void ceph_fill_file_time(struct inode *inode, int issued, u64 time_warp_seq, struct timespec *ctime, struct timespec *mtime, struct timespec *atime){ struct ceph_inode_info *ci = ceph_inode(inode); int warn = 0; if (issued & (CEPH_CAP_FILE_EXCL| CEPH_CAP_FILE_WR| CEPH_CAP_FILE_BUFFER| CEPH_CAP_AUTH_EXCL| CEPH_CAP_XATTR_EXCL)) { if (timespec_compare(ctime, &inode->i_ctime) > 0) { dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n", inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec, ctime->tv_sec, ctime->tv_nsec); inode->i_ctime = *ctime; }Lines 1–500 of 1811. Load more
#include <linux/ceph/ceph_debug.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/uaccess.h> #include <linux/kernel.h> #include <linux/namei.h> #include <linux/writeback.h> #include <linux/vmalloc.h> #include "super.h" #include "mds_client.h" #include <linux/ceph/decode.h> /* * Ceph inode operations * * Implement basic inode helpers (get, alloc) and inode ops (getattr, * setattr, etc.), xattr helpers, and helpers for assimilating * metadata returned by the MDS into our cache. * * Also define helpers for doing asynchronous writeback, invalidation, * and truncation for the benefit of those who can't afford to block * (typically because they are in the message handler path). */ static const struct inode_operations ceph_symlink_iops; static void ceph_invalidate_work(struct work_struct *work); static void ceph_writeback_work(struct work_struct *work); static void ceph_vmtruncate_work(struct work_struct *work); /* * find or create an inode, given the ceph ino number */ static int ceph_set_ino_cb(struct inode *inode, void *data) { ceph_inode(inode)->i_vino = *(struct ceph_vino *)data; inode->i_ino = ceph_vino_to_ino(*(struct ceph_vino *)data); return 0; } struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino) { struct inode *inode; ino_t t = ceph_vino_to_ino(vino); inode = iget5_locked(sb, t, ceph_ino_compare, ceph_set_ino_cb, &vino); if (inode == NULL) return ERR_PTR(-ENOMEM); if (inode->i_state & I_NEW) { dout("get_inode created new inode %p %llx.%llx ino %llx\n", inode, ceph_vinop(inode), (u64)inode->i_ino); unlock_new_inode(inode); } dout("get_inode on %lu=%llx.%llx got %p\n", inode->i_ino, vino.ino, vino.snap, inode); return inode; } /* * get/constuct snapdir inode for a given directory */ struct inode *ceph_get_snapdir(struct inode *parent) { struct ceph_vino vino = { .ino = ceph_ino(parent), .snap = CEPH_SNAPDIR, }; struct inode *inode = ceph_get_inode(parent->i_sb, vino); struct ceph_inode_info *ci = ceph_inode(inode); BUG_ON(!S_ISDIR(parent->i_mode)); if (IS_ERR(inode)) return inode; inode->i_mode = parent->i_mode; inode->i_uid = parent->i_uid; inode->i_gid = parent->i_gid; inode->i_op = &ceph_dir_iops; inode->i_fop = &ceph_dir_fops; ci->i_snap_caps = CEPH_CAP_PIN; /* so we can open */ ci->i_rbytes = 0; return inode; } const struct inode_operations ceph_file_iops = { .permission = ceph_permission, .setattr = ceph_setattr, .getattr = ceph_getattr, .setxattr = ceph_setxattr, .getxattr = ceph_getxattr, .listxattr = ceph_listxattr, .removexattr = ceph_removexattr, }; /* * We use a 'frag tree' to keep track of the MDS's directory fragments * for a given inode (usually there is just a single fragment). We * need to know when a child frag is delegated to a new MDS, or when * it is flagged as replicated, so we can direct our requests * accordingly. */ /* * find/create a frag in the tree */ static struct ceph_inode_frag *__get_or_create_frag(struct ceph_inode_info *ci, u32 f) { struct rb_node **p; struct rb_node *parent = NULL; struct ceph_inode_frag *frag; int c; p = &ci->i_fragtree.rb_node; while (*p) { parent = *p; frag = rb_entry(parent, struct ceph_inode_frag, node); c = ceph_frag_compare(f, frag->frag); if (c < 0) p = &(*p)->rb_left; else if (c > 0) p = &(*p)->rb_right; else return frag; } frag = kmalloc(sizeof(*frag), GFP_NOFS); if (!frag) { pr_err("__get_or_create_frag ENOMEM on %p %llx.%llx " "frag %x\n", &ci->vfs_inode, ceph_vinop(&ci->vfs_inode), f); return ERR_PTR(-ENOMEM); } frag->frag = f; frag->split_by = 0; frag->mds = -1; frag->ndist = 0; rb_link_node(&frag->node, parent, p); rb_insert_color(&frag->node, &ci->i_fragtree); dout("get_or_create_frag added %llx.%llx frag %x\n", ceph_vinop(&ci->vfs_inode), f); return frag; } /* * find a specific frag @f */ struct ceph_inode_frag *__ceph_find_frag(struct ceph_inode_info *ci, u32 f) { struct rb_node *n = ci->i_fragtree.rb_node; while (n) { struct ceph_inode_frag *frag = rb_entry(n, struct ceph_inode_frag, node); int c = ceph_frag_compare(f, frag->frag); if (c < 0) n = n->rb_left; else if (c > 0) n = n->rb_right; else return frag; } return NULL; } /* * Choose frag containing the given value @v. If @pfrag is * specified, copy the frag delegation info to the caller if * it is present. */ u32 ceph_choose_frag(struct ceph_inode_info *ci, u32 v, struct ceph_inode_frag *pfrag, int *found) { u32 t = ceph_frag_make(0, 0); struct ceph_inode_frag *frag; unsigned nway, i; u32 n; if (found) *found = 0; mutex_lock(&ci->i_fragtree_mutex); while (1) { WARN_ON(!ceph_frag_contains_value(t, v)); frag = __ceph_find_frag(ci, t); if (!frag) break; /* t is a leaf */ if (frag->split_by == 0) { if (pfrag) memcpy(pfrag, frag, sizeof(*pfrag)); if (found) *found = 1; break; } /* choose child */ nway = 1 << frag->split_by; dout("choose_frag(%x) %x splits by %d (%d ways)\n", v, t, frag->split_by, nway); for (i = 0; i < nway; i++) { n = ceph_frag_make_child(t, frag->split_by, i); if (ceph_frag_contains_value(n, v)) { t = n; break; } } BUG_ON(i == nway); } dout("choose_frag(%x) = %x\n", v, t); mutex_unlock(&ci->i_fragtree_mutex); return t; } /* * Process dirfrag (delegation) info from the mds. Include leaf * fragment in tree ONLY if ndist > 0. Otherwise, only * branches/splits are included in i_fragtree) */ static int ceph_fill_dirfrag(struct inode *inode, struct ceph_mds_reply_dirfrag *dirinfo) { struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_frag *frag; u32 id = le32_to_cpu(dirinfo->frag); int mds = le32_to_cpu(dirinfo->auth); int ndist = le32_to_cpu(dirinfo->ndist); int i; int err = 0; mutex_lock(&ci->i_fragtree_mutex); if (ndist == 0) { /* no delegation info needed. */ frag = __ceph_find_frag(ci, id); if (!frag) goto out; if (frag->split_by == 0) { /* tree leaf, remove */ dout("fill_dirfrag removed %llx.%llx frag %x" " (no ref)\n", ceph_vinop(inode), id); rb_erase(&frag->node, &ci->i_fragtree); kfree(frag); } else { /* tree branch, keep and clear */ dout("fill_dirfrag cleared %llx.%llx frag %x" " referral\n", ceph_vinop(inode), id); frag->mds = -1; frag->ndist = 0; } goto out; } /* find/add this frag to store mds delegation info */ frag = __get_or_create_frag(ci, id); if (IS_ERR(frag)) { /* this is not the end of the world; we can continue with bad/inaccurate delegation info */ pr_err("fill_dirfrag ENOMEM on mds ref %llx.%llx fg %x\n", ceph_vinop(inode), le32_to_cpu(dirinfo->frag)); err = -ENOMEM; goto out; } frag->mds = mds; frag->ndist = min_t(u32, ndist, CEPH_MAX_DIRFRAG_REP); for (i = 0; i < frag->ndist; i++) frag->dist[i] = le32_to_cpu(dirinfo->dist[i]); dout("fill_dirfrag %llx.%llx frag %x ndist=%d\n", ceph_vinop(inode), frag->frag, frag->ndist); out: mutex_unlock(&ci->i_fragtree_mutex); return err; } /* * initialize a newly allocated inode. */ struct inode *ceph_alloc_inode(struct super_block *sb) { struct ceph_inode_info *ci; int i; ci = kmem_cache_alloc(ceph_inode_cachep, GFP_NOFS); if (!ci) return NULL; dout("alloc_inode %p\n", &ci->vfs_inode); spin_lock_init(&ci->i_ceph_lock); ci->i_version = 0; ci->i_time_warp_seq = 0; ci->i_ceph_flags = 0; ci->i_release_count = 0; ci->i_symlink = NULL; memset(&ci->i_dir_layout, 0, sizeof(ci->i_dir_layout)); ci->i_fragtree = RB_ROOT; mutex_init(&ci->i_fragtree_mutex); ci->i_xattrs.blob = NULL; ci->i_xattrs.prealloc_blob = NULL; ci->i_xattrs.dirty = false; ci->i_xattrs.index = RB_ROOT; ci->i_xattrs.count = 0; ci->i_xattrs.names_size = 0; ci->i_xattrs.vals_size = 0; ci->i_xattrs.version = 0; ci->i_xattrs.index_version = 0; ci->i_caps = RB_ROOT; ci->i_auth_cap = NULL; ci->i_dirty_caps = 0; ci->i_flushing_caps = 0; INIT_LIST_HEAD(&ci->i_dirty_item); INIT_LIST_HEAD(&ci->i_flushing_item); ci->i_cap_flush_seq = 0; ci->i_cap_flush_last_tid = 0; memset(&ci->i_cap_flush_tid, 0, sizeof(ci->i_cap_flush_tid)); init_waitqueue_head(&ci->i_cap_wq); ci->i_hold_caps_min = 0; ci->i_hold_caps_max = 0; INIT_LIST_HEAD(&ci->i_cap_delay_list); ci->i_cap_exporting_mds = 0; ci->i_cap_exporting_mseq = 0; ci->i_cap_exporting_issued = 0; INIT_LIST_HEAD(&ci->i_cap_snaps); ci->i_head_snapc = NULL; ci->i_snap_caps = 0; for (i = 0; i < CEPH_FILE_MODE_NUM; i++) ci->i_nr_by_mode[i] = 0; ci->i_truncate_seq = 0; ci->i_truncate_size = 0; ci->i_truncate_pending = 0; ci->i_max_size = 0; ci->i_reported_size = 0; ci->i_wanted_max_size = 0; ci->i_requested_max_size = 0; ci->i_pin_ref = 0; ci->i_rd_ref = 0; ci->i_rdcache_ref = 0; ci->i_wr_ref = 0; ci->i_wb_ref = 0; ci->i_wrbuffer_ref = 0; ci->i_wrbuffer_ref_head = 0; ci->i_shared_gen = 0; ci->i_rdcache_gen = 0; ci->i_rdcache_revoking = 0; INIT_LIST_HEAD(&ci->i_unsafe_writes); INIT_LIST_HEAD(&ci->i_unsafe_dirops); spin_lock_init(&ci->i_unsafe_lock); ci->i_snap_realm = NULL; INIT_LIST_HEAD(&ci->i_snap_realm_item); INIT_LIST_HEAD(&ci->i_snap_flush_item); INIT_WORK(&ci->i_wb_work, ceph_writeback_work); INIT_WORK(&ci->i_pg_inv_work, ceph_invalidate_work); INIT_WORK(&ci->i_vmtruncate_work, ceph_vmtruncate_work); return &ci->vfs_inode; } static void ceph_i_callback(struct rcu_head *head) { struct inode *inode = container_of(head, struct inode, i_rcu); struct ceph_inode_info *ci = ceph_inode(inode); kmem_cache_free(ceph_inode_cachep, ci); } void ceph_destroy_inode(struct inode *inode) { struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_frag *frag; struct rb_node *n; dout("destroy_inode %p ino %llx.%llx\n", inode, ceph_vinop(inode)); ceph_queue_caps_release(inode); /* * we may still have a snap_realm reference if there are stray * caps in i_cap_exporting_issued or i_snap_caps. */ if (ci->i_snap_realm) { struct ceph_mds_client *mdsc = ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; struct ceph_snap_realm *realm = ci->i_snap_realm; dout(" dropping residual ref to snap realm %p\n", realm); spin_lock(&realm->inodes_with_caps_lock); list_del_init(&ci->i_snap_realm_item); spin_unlock(&realm->inodes_with_caps_lock); ceph_put_snap_realm(mdsc, realm); } kfree(ci->i_symlink); while ((n = rb_first(&ci->i_fragtree)) != NULL) { frag = rb_entry(n, struct ceph_inode_frag, node); rb_erase(n, &ci->i_fragtree); kfree(frag); } __ceph_destroy_xattrs(ci); if (ci->i_xattrs.blob) ceph_buffer_put(ci->i_xattrs.blob); if (ci->i_xattrs.prealloc_blob) ceph_buffer_put(ci->i_xattrs.prealloc_blob); call_rcu(&inode->i_rcu, ceph_i_callback); } /* * Helpers to fill in size, ctime, mtime, and atime. We have to be * careful because either the client or MDS may have more up to date * info, depending on which capabilities are held, and whether * time_warp_seq or truncate_seq have increased. (Ordinarily, mtime * and size are monotonically increasing, except when utimes() or * truncate() increments the corresponding _seq values.) */ int ceph_fill_file_size(struct inode *inode, int issued, u32 truncate_seq, u64 truncate_size, u64 size) { struct ceph_inode_info *ci = ceph_inode(inode); int queue_trunc = 0; if (ceph_seq_cmp(truncate_seq, ci->i_truncate_seq) > 0 || (truncate_seq == ci->i_truncate_seq && size > inode->i_size)) { dout("size %lld -> %llu\n", inode->i_size, size); inode->i_size = size; inode->i_blocks = (size + (1<<9) - 1) >> 9; ci->i_reported_size = size; if (truncate_seq != ci->i_truncate_seq) { dout("truncate_seq %u -> %u\n", ci->i_truncate_seq, truncate_seq); ci->i_truncate_seq = truncate_seq; /* * If we hold relevant caps, or in the case where we're * not the only client referencing this file and we * don't hold those caps, then we need to check whether * the file is either opened or mmaped */ if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_RD| CEPH_CAP_FILE_WR|CEPH_CAP_FILE_BUFFER| CEPH_CAP_FILE_EXCL| CEPH_CAP_FILE_LAZYIO)) || mapping_mapped(inode->i_mapping) || __ceph_caps_file_wanted(ci)) { ci->i_truncate_pending++; queue_trunc = 1; } } } if (ceph_seq_cmp(truncate_seq, ci->i_truncate_seq) >= 0 && ci->i_truncate_size != truncate_size) { dout("truncate_size %lld -> %llu\n", ci->i_truncate_size, truncate_size); ci->i_truncate_size = truncate_size; } return queue_trunc; } void ceph_fill_file_time(struct inode *inode, int issued, u64 time_warp_seq, struct timespec *ctime, struct timespec *mtime, struct timespec *atime) { struct ceph_inode_info *ci = ceph_inode(inode); int warn = 0; if (issued & (CEPH_CAP_FILE_EXCL| CEPH_CAP_FILE_WR| CEPH_CAP_FILE_BUFFER| CEPH_CAP_AUTH_EXCL| CEPH_CAP_XATTR_EXCL)) { if (timespec_compare(ctime, &inode->i_ctime) > 0) { dout("ctime %ld.%09ld -> %ld.%09ld inc w/ cap\n", inode->i_ctime.tv_sec, inode->i_ctime.tv_nsec, ctime->tv_sec, ctime->tv_nsec); inode->i_ctime = *ctime; }