From: Sage Weil Date: Wed, 15 Oct 2008 23:46:18 +0000 (-0700) Subject: kclient: move inode alloc/destroy into inode.c X-Git-Tag: v0.5~299 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=625e38c0e421b25d8fcf0b4e3083f15ff66e8599;p=ceph.git kclient: move inode alloc/destroy into inode.c --- diff --git a/src/kernel/caps.c b/src/kernel/caps.c index 5f75c8db53b1..9c1243964380 100644 --- a/src/kernel/caps.c +++ b/src/kernel/caps.c @@ -555,7 +555,7 @@ first: if (!is_delayed) __cap_delay_requeue(mdsc, ci); - + for (p = rb_first(&ci->i_caps); p; p = rb_next(p)) { cap = rb_entry(p, struct ceph_cap, ci_node); @@ -699,7 +699,7 @@ int ceph_get_cap_refs(struct ceph_inode_info *ci, int need, int want, int *got, } have = __ceph_caps_issued(ci, &implemented); /* HACK: force sync writes... - have &= ~CEPH_CAP_WRBUFFER; + have &= ~CEPH_CAP_WRBUFFER; implemented &= ~CEPH_CAP_WRBUFFER; */ if ((have & need) == need) { @@ -801,7 +801,7 @@ void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr, if (snapc == ci->i_snap_realm->cached_context) { ci->i_wrbuffer_ref_head -= nr; dout(30, "put_wrbuffer_cap_refs on %p head %d/%d -> %d/%d %s\n", - inode, + inode, ci->i_wrbuffer_ref+nr, ci->i_wrbuffer_ref_head+nr, ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head, last ? " LAST":""); diff --git a/src/kernel/ceph_debug.h b/src/kernel/ceph_debug.h index e8fe0e6c58d8..00a7f66d98d6 100644 --- a/src/kernel/ceph_debug.h +++ b/src/kernel/ceph_debug.h @@ -61,7 +61,7 @@ static struct _debug_mask_name _debug_mask_names[] = { {DOUT_MASK_IOCTL, "ioctl"}, {DOUT_MASK_MDSC, "mdsc"}, {DOUT_MASK_MDSMAP, "mdsmap"}, - {DOUT_MASK_MSGR, "msgr"}, + {DOUT_MASK_MSGR, "msgr"}, {DOUT_MASK_MON, "mon"}, {DOUT_MASK_OSDC, "osdc"}, {DOUT_MASK_OSDMAP, "osdmap"}, @@ -69,7 +69,7 @@ static struct _debug_mask_name _debug_mask_names[] = { {DOUT_MASK_SUPER, "super"}, {DOUT_MASK_PROTOCOL, "protocol"}, {DOUT_MASK_PROC, "proc"}, - {0, NULL} + {0, NULL} }; static inline int ceph_get_debug_mask(char *name) diff --git a/src/kernel/export.c b/src/kernel/export.c index f595ae86ea74..296d10daca95 100644 --- a/src/kernel/export.c +++ b/src/kernel/export.c @@ -17,7 +17,7 @@ int ceph_debug_export = -1; #define IPSZ (sizeof(struct ceph_inopath_item) / sizeof(u32)) -static int ceph_encode_fh(struct dentry *dentry, __u32 *rawfh, int *max_len, +static int ceph_encode_fh(struct dentry *dentry, __u32 *rawfh, int *max_len, int connectable) { int type = 1; @@ -28,7 +28,7 @@ static int ceph_encode_fh(struct dentry *dentry, __u32 *rawfh, int *max_len, dout(10, "encode_fh %p max_len %d u32s (%d inopath items)%s\n", dentry, *max_len, max, connectable ? " connectable":""); - + if (max < 1 || (connectable && max < 2)) return -ENOSPC; @@ -72,7 +72,7 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, if (!inode) { struct ceph_mds_request *req; derr(10, "__fh_to_dentry %llx.%x -- no inode\n", vino.ino,hash); - + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_FINDINODE, len, (char *)fh, 0, NULL, @@ -81,7 +81,7 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, return ERR_PTR(PTR_ERR(req)); err = ceph_mdsc_do_request(mdsc, req); ceph_mdsc_put_request(req); - + inode = ceph_find_inode(sb, vino); if (!inode) return ERR_PTR(err ? err : -ESTALE); @@ -97,7 +97,7 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, } dout(10, "__fh_to_dentry %llx.%x -- inode %p dentry %p\n", vino.ino, hash, inode, dentry); - return dentry; + return dentry; } diff --git a/src/kernel/file.c b/src/kernel/file.c index b56f08c1914e..b92e27ba047c 100644 --- a/src/kernel/file.c +++ b/src/kernel/file.c @@ -328,7 +328,7 @@ static void check_max_size(struct inode *inode, loff_t endoff) { struct ceph_inode_info *ci = ceph_inode(inode); int check = 0; - + /* do we need to explicitly request a larger max_size? */ spin_lock(&inode->i_lock); if ((endoff >= ci->i_max_size || @@ -393,7 +393,7 @@ retry_snap: &iocb->ki_pos); else ret = generic_file_aio_write(iocb, iov, nr_segs, pos); - + out: dout(10, "aio_write %p %llu~%u dropping cap refs on %d\n", inode, pos, (unsigned)iov->iov_len, got); diff --git a/src/kernel/inode.c b/src/kernel/inode.c index 66c907279f58..00ede8545c27 100644 --- a/src/kernel/inode.c +++ b/src/kernel/inode.c @@ -20,6 +20,7 @@ int ceph_debug_inode = -1; static const struct inode_operations ceph_symlink_iops; + /* * find or create an inode, given the ceph ino number */ @@ -230,6 +231,86 @@ out: 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(10, "alloc_inode %p\n", &ci->vfs_inode); + + ci->i_version = 0; + ci->i_truncate_seq = 0; + ci->i_time_warp_seq = 0; + ci->i_symlink = NULL; + + ci->i_lease_session = NULL; + ci->i_lease_mask = 0; + ci->i_lease_ttl = 0; + INIT_LIST_HEAD(&ci->i_lease_item); + + ci->i_fragtree = RB_ROOT; + mutex_init(&ci->i_fragtree_mutex); + + ci->i_xattr_len = 0; + ci->i_xattr_data = NULL; + + ci->i_caps = RB_ROOT; + for (i = 0; i < CEPH_FILE_MODE_NUM; i++) + ci->i_nr_by_mode[i] = 0; + init_waitqueue_head(&ci->i_cap_wq); + INIT_LIST_HEAD(&ci->i_cap_snaps); + ci->i_snap_caps = 0; + + ci->i_wanted_max_size = 0; + ci->i_requested_max_size = 0; + + ci->i_cap_exporting_mds = 0; + ci->i_cap_exporting_mseq = 0; + ci->i_cap_exporting_issued = 0; + + ci->i_rd_ref = ci->i_rdcache_ref = 0; + ci->i_wr_ref = 0; + ci->i_wrbuffer_ref = 0; + ci->i_wrbuffer_ref_head = 0; + ci->i_hold_caps_until = 0; + INIT_LIST_HEAD(&ci->i_cap_delay_list); + + ci->i_snap_realm = NULL; + + INIT_WORK(&ci->i_wb_work, ceph_inode_writeback); + + ci->i_vmtruncate_to = -1; + INIT_WORK(&ci->i_vmtruncate_work, ceph_vmtruncate_work); + + return &ci->vfs_inode; +} + +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(30, "destroy_inode %p ino %llx.%llx\n", inode, ceph_vinop(inode)); + 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); + } + kfree(ci->i_xattr_data); + kmem_cache_free(ceph_inode_cachep, ci); +} + + /* * Helper 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 @@ -450,6 +531,8 @@ out: return err; } + + /* * caller must hold session s_mutex. */ @@ -1134,7 +1217,7 @@ out: if (snapdir) { iput(snapdir); dput(parent); - } + } dout(10, "readdir_prepopulate done\n"); return err; } @@ -1629,7 +1712,7 @@ static size_t _ceph_vir_xattrcb_rctime(struct ceph_inode_info *ci, char *val, size_t size) { return snprintf(val, size, "%ld.%ld", (long)ci->i_rctime.tv_sec, - (long)ci->i_rctime.tv_nsec); + (long)ci->i_rctime.tv_nsec); } static struct _ceph_vir_xattr_cb _ceph_vir_xattr_recs[] = { diff --git a/src/kernel/mds_client.c b/src/kernel/mds_client.c index 7dc9f3504e5d..9eda153943e2 100644 --- a/src/kernel/mds_client.c +++ b/src/kernel/mds_client.c @@ -2025,7 +2025,7 @@ void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc, struct ceph_msg *msg) mdsc->mdsmap = newmap; check_new_map(mdsc, newmap, oldmap); ceph_mdsmap_destroy(oldmap); - + /* reconnect? */ if (from < newmap->m_max_mds) { newstate = ceph_mdsmap_get_state(newmap, from); diff --git a/src/kernel/mds_client.h b/src/kernel/mds_client.h index 4d1097e9e048..a7004653568a 100644 --- a/src/kernel/mds_client.h +++ b/src/kernel/mds_client.h @@ -131,7 +131,7 @@ struct ceph_mds_client { int max_sessions; /* len of s_mds_sessions */ int stopping; /* true if shutting down */ - /* + /* * snap_rwsem will cover cap linkage into snaprealms, and realm * snap contexts. (later, we can do per-realm snap contexts locks..) */ diff --git a/src/kernel/mon_client.c b/src/kernel/mon_client.c index 1abd2f943dd0..f599d6879449 100644 --- a/src/kernel/mon_client.c +++ b/src/kernel/mon_client.c @@ -87,7 +87,7 @@ static void delayed_work(struct delayed_work *dwork, unsigned long *delay) /* - * mds map + * mds map */ static void do_request_mdsmap(struct work_struct *work) { @@ -139,7 +139,7 @@ int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, __u32 got) dout(5, "got_mdsmap got %u > wanted %u\n", got, monc->want_mdsmap); monc->want_mdsmap = 0; - + /* we got map so take map request out of queue */ cancel_delayed_work_sync(&monc->mds_delayed_work); monc->mds_delay = BASE_DELAY_INTERVAL; diff --git a/src/kernel/mon_client.h b/src/kernel/mon_client.h index 3d3f84916604..b32f27abde3e 100644 --- a/src/kernel/mon_client.h +++ b/src/kernel/mon_client.h @@ -45,7 +45,7 @@ struct ceph_mon_client { }; extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end); -extern int ceph_monmap_contains(struct ceph_monmap *m, +extern int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr); extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl); @@ -58,16 +58,16 @@ extern void ceph_monc_request_osdmap(struct ceph_mon_client *monc, __u32 have); extern int ceph_monc_got_osdmap(struct ceph_mon_client *monc, __u32 have); extern void ceph_monc_request_umount(struct ceph_mon_client *monc); -extern void ceph_monc_report_failure(struct ceph_mon_client *monc, +extern void ceph_monc_report_failure(struct ceph_mon_client *monc, struct ceph_entity_inst *who); -extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, +extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf); -extern void ceph_monc_handle_statfs_reply(struct ceph_mon_client *monc, +extern void ceph_monc_handle_statfs_reply(struct ceph_mon_client *monc, struct ceph_msg *msg); extern void ceph_monc_request_umount(struct ceph_mon_client *monc); -extern void ceph_monc_handle_umount(struct ceph_mon_client *monc, +extern void ceph_monc_handle_umount(struct ceph_mon_client *monc, struct ceph_msg *msg); #endif diff --git a/src/kernel/osdmap.c b/src/kernel/osdmap.c index ec616f777b32..b37f771b057a 100644 --- a/src/kernel/osdmap.c +++ b/src/kernel/osdmap.c @@ -542,7 +542,7 @@ struct ceph_osdmap *apply_incremental(void **p, void *end, /* skip new_max_snap, removed_snaps */ *p += sizeof(__u64); ceph_decode_32_safe(p, end, len, bad); - *p += len * 2 * sizeof(__u64); + *p += len * 2 * sizeof(__u64); if (*p != end) { derr(10, "osdmap incremental has trailing gunk?\n"); @@ -593,7 +593,7 @@ void calc_file_object_mapping(struct ceph_file_layout *layout, do_div(t, su); bl = t; dout(80, "off %llu / su %u = bl %u\n", off, su, bl); - + stripeno = bl / sc; stripepos = bl % sc; objsetno = stripeno / su_per_object; diff --git a/src/kernel/osdmap.h b/src/kernel/osdmap.h index 41c5b0523ce9..45bad6ac400a 100644 --- a/src/kernel/osdmap.h +++ b/src/kernel/osdmap.h @@ -37,7 +37,7 @@ static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd) } static inline struct ceph_entity_addr * -ceph_osd_addr(struct ceph_osdmap *map, int osd) +ceph_osd_addr(struct ceph_osdmap *map, int osd) { if (osd >= map->max_osd) return 0; diff --git a/src/kernel/proc.c b/src/kernel/proc.c index f9a26ecfc8ed..217d44c07a77 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -131,7 +131,7 @@ static int ceph_debug_mask_write(struct file *file, const char __user *buffer, *debug &= ~mask; else *debug |= mask; - + } } while (mask_str); diff --git a/src/kernel/snap.c b/src/kernel/snap.c index c022fe196f90..a6776f89175e 100644 --- a/src/kernel/snap.c +++ b/src/kernel/snap.c @@ -105,7 +105,7 @@ static int build_snap_context(struct ceph_snap_realm *realm) realm->cached_context->seq <= parent->cached_context->seq)) { dout(10, "build_snap_context %llx %p: %p seq %lld (%d snaps)" " (unchanged)\n", - realm->ino, realm, realm->cached_context, + realm->ino, realm, realm->cached_context, realm->cached_context->seq, realm->cached_context->num_snaps); return 0; @@ -241,7 +241,7 @@ void ceph_queue_cap_snap(struct ceph_inode_info *ci, if (used & CEPH_CAP_WR) { dout(10, "queue_cap_snap %p cap_snap %p snapc %p" - " seq %llu used WR, now pending\n", inode, + " seq %llu used WR, now pending\n", inode, capsnap, snapc, snapc->seq); capsnap->writing = 1; } else { @@ -287,7 +287,7 @@ more: struct list_head *pi; dout(10, "update_snap_trace updating %llx %p %lld -> %lld\n", realm->ino, realm, realm->seq, le64_to_cpu(ri->seq)); - + list_for_each(pi, &realm->inodes_with_caps) { struct ceph_inode_info *ci = list_entry(pi, struct ceph_inode_info, @@ -302,7 +302,7 @@ more: invalidate += adjust_snap_realm_parent(mdsc, realm, le64_to_cpu(ri->parent)); - + if (le64_to_cpu(ri->seq) > realm->seq) { realm->seq = le64_to_cpu(ri->seq); realm->created = le64_to_cpu(ri->created); @@ -311,7 +311,7 @@ more: realm->num_snaps = le32_to_cpu(ri->num_snaps); if (dup_array(&realm->snaps, snaps, realm->num_snaps) < 0) goto fail; - + realm->num_prior_parent_snaps = le32_to_cpu(ri->num_prior_parent_snaps); if (dup_array(&realm->prior_parent_snaps, prior_parent_snaps, @@ -337,7 +337,7 @@ bad: err = -EINVAL; fail: derr(10, "update_snap_trace error %d\n", err); - return ERR_PTR(err); + return ERR_PTR(err); } diff --git a/src/kernel/super.c b/src/kernel/super.c index 5e8e2805e92b..f1b8f43daed7 100644 --- a/src/kernel/super.c +++ b/src/kernel/super.c @@ -153,84 +153,9 @@ static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt) /* * inode cache */ -static struct kmem_cache *ceph_inode_cachep; +struct kmem_cache *ceph_inode_cachep; -static 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(10, "alloc_inode %p vfsi %p\n", ci, &ci->vfs_inode); - - ci->i_version = 0; - ci->i_truncate_seq = 0; - ci->i_time_warp_seq = 0; - ci->i_symlink = NULL; - - ci->i_lease_session = NULL; - ci->i_lease_mask = 0; - ci->i_lease_ttl = 0; - INIT_LIST_HEAD(&ci->i_lease_item); - - ci->i_fragtree = RB_ROOT; - mutex_init(&ci->i_fragtree_mutex); - - ci->i_xattr_len = 0; - ci->i_xattr_data = NULL; - - ci->i_caps = RB_ROOT; - for (i = 0; i < CEPH_FILE_MODE_NUM; i++) - ci->i_nr_by_mode[i] = 0; - init_waitqueue_head(&ci->i_cap_wq); - INIT_LIST_HEAD(&ci->i_cap_snaps); - ci->i_snap_caps = 0; - - ci->i_wanted_max_size = 0; - ci->i_requested_max_size = 0; - - ci->i_cap_exporting_mds = 0; - ci->i_cap_exporting_mseq = 0; - ci->i_cap_exporting_issued = 0; - - ci->i_rd_ref = ci->i_rdcache_ref = 0; - ci->i_wr_ref = 0; - ci->i_wrbuffer_ref = 0; - ci->i_wrbuffer_ref_head = 0; - ci->i_hold_caps_until = 0; - INIT_LIST_HEAD(&ci->i_cap_delay_list); - - ci->i_snap_realm = NULL; - - INIT_WORK(&ci->i_wb_work, ceph_inode_writeback); - - ci->i_vmtruncate_to = -1; - INIT_WORK(&ci->i_vmtruncate_work, ceph_vmtruncate_work); - - return &ci->vfs_inode; -} - -static 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(30, "destroy_inode %p ino %llx.%llx\n", inode, ceph_vinop(inode)); - 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); - } - kfree(ci->i_xattr_data); - kmem_cache_free(ceph_inode_cachep, ci); -} - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) static void init_once(void *foo) #else static void init_once(struct kmem_cache *cachep, void *foo) @@ -331,14 +256,12 @@ static void handle_monmap(struct ceph_client *client, struct ceph_msg *msg) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) client->client_kobj = kobject_create_and_add(name, ceph_kobj); - //client->fsid_kobj = kobject_create_and_add("fsid", + //client->fsid_kobj = kobject_create_and_add("fsid", //client->client_kobj); #endif } } - - const char *ceph_msg_type_name(int type) { switch (type) { @@ -391,7 +314,6 @@ void ceph_peer_reset(void *p, struct ceph_entity_addr *peer_addr, /* * mount options */ - enum { Opt_fsidmajor, Opt_fsidminor, @@ -821,7 +743,7 @@ static int ceph_mount(struct ceph_client *client, struct vfsmount *mnt, client->msgr->prepare_pages = ceph_osdc_prepare_pages; client->msgr->peer_reset = ceph_peer_reset; } - + while (!have_all_maps(client)) { err = -EIO; if (timeout && time_after_eq(jiffies, started + timeout)) @@ -1151,7 +1073,7 @@ static int __init init_ceph(void) return 0; out_icache: - destroy_inodecache(); + destroy_inodecache(); out_msgr: ceph_msgr_exit(); out_proc: diff --git a/src/kernel/super.h b/src/kernel/super.h index 6b49ec4b816b..53603819ecbd 100644 --- a/src/kernel/super.h +++ b/src/kernel/super.h @@ -143,7 +143,7 @@ struct ceph_client { struct super_block *sb; - unsigned long mount_state; + unsigned long mount_state; wait_queue_head_t mount_wq; struct ceph_messenger *msgr; /* messenger instance */ @@ -269,7 +269,7 @@ struct ceph_inode_info { unsigned i_cap_exporting_issued; struct list_head i_cap_snaps; /* snapped state pending flush to mds */ unsigned i_snap_caps; /* cap bits for snapped files */ - + int i_nr_by_mode[CEPH_FILE_MODE_NUM]; /* open file counts */ loff_t i_max_size; /* max file size authorized by mds */ @@ -539,7 +539,7 @@ static inline void ceph_put_snap_context(struct ceph_snap_context *sc) * are organized into a hierarchy, such that children inherit (some of) * the snapshots of their parents. * - * All inodes within the realm that have capabilities are linked into a + * All inodes within the realm that have capabilities are linked into a * per-realm list. */ struct ceph_snap_realm { @@ -553,7 +553,7 @@ struct ceph_snap_realm { int num_prior_parent_snaps; /* had prior to parent_since */ u64 *snaps; /* snaps specific to this realm */ int num_snaps; - + struct ceph_snap_realm *parent; struct list_head children; /* list of child realms */ struct list_head child_item; @@ -608,6 +608,10 @@ extern const char *ceph_msg_type_name(int type); /* inode.c */ extern const struct inode_operations ceph_file_iops; +extern struct kmem_cache *ceph_inode_cachep; + +extern struct inode *ceph_alloc_inode(struct super_block *sb); +extern void ceph_destroy_inode(struct inode *inode); extern struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino); @@ -685,8 +689,8 @@ extern struct dentry_operations ceph_dentry_ops, ceph_snap_dentry_ops, ceph_snapdir_dentry_ops; extern char *ceph_build_path(struct dentry *dn, int *len, __u64 *base, int min); -extern struct dentry *ceph_do_lookup(struct super_block *sb, - struct dentry *dentry, +extern struct dentry *ceph_do_lookup(struct super_block *sb, + struct dentry *dentry, int mask, int on_inode, int locked_dir); extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, struct dentry *dentry, int err);