X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fosd%2Fosd_handler.c;h=5d9a1555812a3449e5011a9b93dc02a172382891;hp=c33a7a1d512979cdc75be4147a4cd477ce609a6a;hb=6b6ae6fe7cc74816c42878630d73400a072598f3;hpb=0ff852162daab6d723ba27418eba715bb484558c diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index c33a7a1..5d9a155 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -90,7 +90,7 @@ struct osd_directory { struct osd_object { struct dt_object oo_dt; - /* + /** * Inode for file system object represented by this osd_object. This * inode is pinned for the whole duration of lu_object life. * @@ -100,10 +100,11 @@ struct osd_object { struct inode *oo_inode; struct rw_semaphore oo_sem; struct osd_directory *oo_dir; - /* protects inode attributes. */ + /** protects inode attributes. */ spinlock_t oo_guard; -#if OSD_COUNTERS const struct lu_env *oo_owner; +#ifdef CONFIG_LOCKDEP + struct lockdep_map oo_dep_map; #endif }; @@ -116,7 +117,8 @@ static int osd_mod_init (void) __init; static int osd_type_init (struct lu_device_type *t); static void osd_type_fini (struct lu_device_type *t); static int osd_object_init (const struct lu_env *env, - struct lu_object *l); + struct lu_object *l, + const struct lu_object_conf *_); static void osd_object_release(const struct lu_env *env, struct lu_object *l); static int osd_object_print (const struct lu_env *env, void *cookie, @@ -214,21 +216,24 @@ static struct thandle *osd_trans_start (const struct lu_env *env, struct txn_param *p); static journal_t *osd_journal (const struct osd_device *dev); -static struct lu_device_type_operations osd_device_type_ops; +static const struct lu_device_type_operations osd_device_type_ops; static struct lu_device_type osd_device_type; -static struct lu_object_operations osd_lu_obj_ops; +static const struct lu_object_operations osd_lu_obj_ops; static struct obd_ops osd_obd_device_ops; -static struct lu_device_operations osd_lu_ops; +static const struct lu_device_operations osd_lu_ops; static struct lu_context_key osd_key; -static struct dt_object_operations osd_obj_ops; -static struct dt_body_operations osd_body_ops; -static struct dt_index_operations osd_index_ops; -static struct dt_index_operations osd_index_compat_ops; +static const struct dt_object_operations osd_obj_ops; +static const struct dt_body_operations osd_body_ops; +static const struct dt_index_operations osd_index_ops; +static const struct dt_index_operations osd_index_compat_ops; struct osd_thandle { struct thandle ot_super; handle_t *ot_handle; struct journal_callback ot_jcb; + /* Link to the device, for debugging. */ + struct lu_ref_link *ot_dev_link; + }; /* @@ -262,7 +267,6 @@ static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env) return lu_context_key_get(&env->le_ctx, &osd_key); } -#if OSD_COUNTERS /* * Concurrency: doesn't matter */ @@ -280,15 +284,6 @@ static int osd_write_locked(const struct lu_env *env, struct osd_object *o) return oti->oti_w_locks > 0 && o->oo_owner == env; } -#define OSD_COUNTERS_DO(exp) exp -#else - - -#define osd_read_locked(env, o) (1) -#define osd_write_locked(env, o) (1) -#define OSD_COUNTERS_DO(exp) ((void)0) -#endif - /* * Concurrency: doesn't access mutable data */ @@ -346,19 +341,20 @@ static void osd_object_init0(struct osd_object *obj) * Concurrency: no concurrent access is possible that early in object * life-cycle. */ -static int osd_object_init(const struct lu_env *env, struct lu_object *l) +static int osd_object_init(const struct lu_env *env, struct lu_object *l, + const struct lu_object_conf *_) { struct osd_object *obj = osd_obj(l); int result; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); result = osd_fid_lookup(env, obj, lu_object_fid(l)); if (result == 0) { if (obj->oo_inode != NULL) osd_object_init0(obj); } - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); return result; } @@ -370,7 +366,7 @@ static void osd_object_free(const struct lu_env *env, struct lu_object *l) { struct osd_object *obj = osd_obj(l); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); dt_object_fini(&obj->oo_dt); OBD_FREE_PTR(obj); @@ -460,7 +456,7 @@ static void osd_object_delete(const struct lu_env *env, struct lu_object *l) struct osd_object *obj = osd_obj(l); struct inode *inode = obj->oo_inode; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); /* * If object is unlinked remove fid->ino mapping from object index. @@ -578,6 +574,7 @@ static void osd_trans_commit_cb(struct journal_callback *jcb, int error) struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb); struct thandle *th = &oh->ot_super; struct dt_device *dev = th->th_dev; + struct lu_device *lud = &dev->dd_lu_dev; LASSERT(dev != NULL); LASSERT(oh->ot_handle == NULL); @@ -595,7 +592,8 @@ static void osd_trans_commit_cb(struct journal_callback *jcb, int error) lu_context_exit(&env->le_ctx); } - lu_device_put(&dev->dd_lu_dev); + lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th); + lu_device_put(lud); th->th_dev = NULL; lu_context_exit(&th->th_ctx); @@ -625,6 +623,8 @@ static struct thandle *osd_trans_start(const struct lu_env *env, if (osd_param_is_sane(dev, p)) { OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO); if (oh != NULL) { + struct osd_thread_info *oti = osd_oti_get(env); + /* * XXX temporary stuff. Some abstraction layer should * be used. @@ -638,22 +638,18 @@ static struct thandle *osd_trans_start(const struct lu_env *env, th->th_result = 0; jh->h_sync = p->tp_sync; lu_device_get(&d->dd_lu_dev); + oh->ot_dev_link = lu_ref_add + (&d->dd_lu_dev.ld_reference, + "osd-tx", th); /* add commit callback */ lu_context_init(&th->th_ctx, LCT_TX_HANDLE); lu_context_enter(&th->th_ctx); journal_callback_set(jh, osd_trans_commit_cb, (struct journal_callback *)&oh->ot_jcb); -#if OSD_COUNTERS - { - struct osd_thread_info *oti = - osd_oti_get(env); - LASSERT(oti->oti_txns == 0); LASSERT(oti->oti_r_locks == 0); LASSERT(oti->oti_w_locks == 0); oti->oti_txns++; - } -#endif } else { OBD_FREE_PTR(oh); th = (void *)jh; @@ -675,35 +671,25 @@ static void osd_trans_stop(const struct lu_env *env, struct thandle *th) { int result; struct osd_thandle *oh; + struct osd_thread_info *oti = osd_oti_get(env); ENTRY; oh = container_of0(th, struct osd_thandle, ot_super); if (oh->ot_handle != NULL) { handle_t *hdl = oh->ot_handle; - /* - * XXX temporary stuff. Some abstraction layer should be used. - */ + + LASSERT(oti->oti_txns == 1); + oti->oti_txns--; + LASSERT(oti->oti_r_locks == 0); + LASSERT(oti->oti_w_locks == 0); result = dt_txn_hook_stop(env, th); if (result != 0) CERROR("Failure in transaction hook: %d\n", result); - - /**/ oh->ot_handle = NULL; result = journal_stop(hdl); if (result != 0) CERROR("Failure to stop transaction: %d\n", result); - -#if OSD_COUNTERS - { - struct osd_thread_info *oti = osd_oti_get(env); - - LASSERT(oti->oti_txns == 1); - LASSERT(oti->oti_r_locks == 0); - LASSERT(oti->oti_w_locks == 0); - oti->oti_txns--; - } -#endif } EXIT; } @@ -792,7 +778,7 @@ static int osd_credit_get(const struct lu_env *env, struct dt_device *d, return osd_dto_credits[op]; } -static struct dt_device_operations osd_dt_ops = { +static const struct dt_device_operations osd_dt_ops = { .dt_root_get = osd_root_get, .dt_statfs = osd_statfs, .dt_trans_start = osd_trans_start, @@ -805,58 +791,46 @@ static struct dt_device_operations osd_dt_ops = { }; static void osd_object_read_lock(const struct lu_env *env, - struct dt_object *dt) + struct dt_object *dt, unsigned role) { struct osd_object *obj = osd_dt_obj(dt); + struct osd_thread_info *oti = osd_oti_get(env); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); - OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env)); - down_read(&obj->oo_sem); -#if OSD_COUNTERS - { - struct osd_thread_info *oti = osd_oti_get(env); + LASSERT(obj->oo_owner != env); + down_read_nested(&obj->oo_sem, role); LASSERT(obj->oo_owner == NULL); oti->oti_r_locks++; - } -#endif } static void osd_object_write_lock(const struct lu_env *env, - struct dt_object *dt) + struct dt_object *dt, unsigned role) { struct osd_object *obj = osd_dt_obj(dt); + struct osd_thread_info *oti = osd_oti_get(env); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); - OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env)); - down_write(&obj->oo_sem); -#if OSD_COUNTERS - { - struct osd_thread_info *oti = osd_oti_get(env); + LASSERT(obj->oo_owner != env); + down_write_nested(&obj->oo_sem, role); LASSERT(obj->oo_owner == NULL); obj->oo_owner = env; oti->oti_w_locks++; - } -#endif } static void osd_object_read_unlock(const struct lu_env *env, struct dt_object *dt) { struct osd_object *obj = osd_dt_obj(dt); - - LASSERT(osd_invariant(obj)); -#if OSD_COUNTERS - { struct osd_thread_info *oti = osd_oti_get(env); + LINVRNT(osd_invariant(obj)); + LASSERT(oti->oti_r_locks > 0); oti->oti_r_locks--; - } -#endif up_read(&obj->oo_sem); } @@ -864,18 +838,14 @@ static void osd_object_write_unlock(const struct lu_env *env, struct dt_object *dt) { struct osd_object *obj = osd_dt_obj(dt); - - LASSERT(osd_invariant(obj)); -#if OSD_COUNTERS - { struct osd_thread_info *oti = osd_oti_get(env); + LINVRNT(osd_invariant(obj)); + LASSERT(obj->oo_owner == env); LASSERT(oti->oti_w_locks > 0); oti->oti_w_locks--; obj->oo_owner = NULL; - } -#endif up_write(&obj->oo_sem); } @@ -973,7 +943,7 @@ static int osd_attr_get(const struct lu_env *env, struct osd_object *obj = osd_dt_obj(dt); LASSERT(dt_object_exists(dt)); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ)) return -EACCES; @@ -1095,7 +1065,7 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj, struct inode *parent; struct inode *inode; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(obj->oo_inode == NULL); LASSERT(osd->od_obj_area != NULL); @@ -1114,7 +1084,7 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj, result = 0; } else result = PTR_ERR(inode); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); return result; } @@ -1182,7 +1152,7 @@ static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj, struct inode *dir; umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(obj->oo_inode == NULL); LASSERT(osd->od_obj_area != NULL); LASSERT(S_ISCHR(mode) || S_ISBLK(mode) || @@ -1196,7 +1166,7 @@ static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj, LASSERT(obj->oo_inode != NULL); init_special_inode(obj->oo_inode, mode, attr->la_rdev); } - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); return result; } @@ -1260,7 +1230,7 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt, ENTRY; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(!dt_object_exists(dt)); LASSERT(osd_write_locked(env, obj)); LASSERT(th != NULL); @@ -1288,7 +1258,7 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt, } LASSERT(ergo(result == 0, dt_object_exists(dt))); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); RETURN(result); } @@ -1302,7 +1272,7 @@ static void osd_object_ref_add(const struct lu_env *env, struct osd_object *obj = osd_dt_obj(dt); struct inode *inode = obj->oo_inode; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); LASSERT(osd_write_locked(env, obj)); LASSERT(th != NULL); @@ -1312,7 +1282,7 @@ static void osd_object_ref_add(const struct lu_env *env, inode->i_nlink++; spin_unlock(&obj->oo_guard); mark_inode_dirty(inode); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); } /* @@ -1325,7 +1295,7 @@ static void osd_object_ref_del(const struct lu_env *env, struct osd_object *obj = osd_dt_obj(dt); struct inode *inode = obj->oo_inode; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); LASSERT(osd_write_locked(env, obj)); LASSERT(th != NULL); @@ -1335,7 +1305,7 @@ static void osd_object_ref_del(const struct lu_env *env, inode->i_nlink--; spin_unlock(&obj->oo_guard); mark_inode_dirty(inode); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); } /* @@ -1485,7 +1455,7 @@ static struct obd_capa *osd_capa_get(const struct lu_env *env, RETURN(ERR_PTR(-ENOENT)); LASSERT(dt_object_exists(dt)); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); /* renewal sanity check */ if (old && osd_object_auth(env, dt, old, opc)) @@ -1541,7 +1511,7 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt) RETURN(rc); } -static struct dt_object_operations osd_obj_ops = { +static const struct dt_object_operations osd_obj_ops = { .do_read_lock = osd_object_read_lock, .do_write_lock = osd_object_write_lock, .do_read_unlock = osd_object_read_unlock, @@ -1614,7 +1584,7 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt, return result; } -static struct dt_body_operations osd_body_ops = { +static const struct dt_body_operations osd_body_ops = { .dbo_read = osd_read, .dbo_write = osd_write }; @@ -1687,7 +1657,7 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt, int result; struct osd_object *obj = osd_dt_obj(dt); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); if (osd_object_is_root(obj)) { @@ -1731,7 +1701,7 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt, if (!osd_index_probe(env, obj, feat)) result = -ENOTDIR; } - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); return result; } @@ -1748,7 +1718,7 @@ static int osd_index_delete(const struct lu_env *env, struct dt_object *dt, ENTRY; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); LASSERT(bag->ic_object == obj->oo_inode); LASSERT(handle != NULL); @@ -1766,7 +1736,7 @@ static int osd_index_delete(const struct lu_env *env, struct dt_object *dt, rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd); osd_ipd_put(env, bag, ipd); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); RETURN(rc); } @@ -1781,7 +1751,7 @@ static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt, ENTRY; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); LASSERT(bag->ic_object == obj->oo_inode); @@ -1795,7 +1765,7 @@ static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt, rc = iam_lookup(bag, (const struct iam_key *)key, (struct iam_rec *)rec, ipd); osd_ipd_put(env, bag, ipd); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); RETURN(rc); } @@ -1812,7 +1782,7 @@ static int osd_index_insert(const struct lu_env *env, struct dt_object *dt, ENTRY; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); LASSERT(bag->ic_object == obj->oo_inode); LASSERT(th != NULL); @@ -1830,7 +1800,7 @@ static int osd_index_insert(const struct lu_env *env, struct dt_object *dt, rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key, (struct iam_rec *)rec, ipd); osd_ipd_put(env, bag, ipd); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); RETURN(rc); } @@ -1967,7 +1937,7 @@ static int osd_it_load(const struct lu_env *env, return iam_it_load(&it->oi_it, hash); } -static struct dt_index_operations osd_index_ops = { +static const struct dt_index_operations osd_index_ops = { .dio_lookup = osd_index_lookup, .dio_insert = osd_index_insert, .dio_delete = osd_index_delete, @@ -2042,7 +2012,7 @@ static int osd_index_compat_lookup(const struct lu_env *env, struct dentry *dentry; struct dentry *parent; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(S_ISDIR(obj->oo_inode->i_mode)); LASSERT(osd_has_index(obj)); @@ -2088,7 +2058,7 @@ static int osd_index_compat_lookup(const struct lu_env *env, } else result = -ENOMEM; dput(parent); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); return result; } @@ -2158,7 +2128,7 @@ static int osd_index_compat_insert(const struct lu_env *env, int result; LASSERT(S_ISDIR(obj->oo_inode->i_mode)); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(th != NULL); if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT)) @@ -2168,7 +2138,7 @@ static int osd_index_compat_insert(const struct lu_env *env, if (result != 0) return result; - luch = lu_object_find(env, ludev->ld_site, fid); + luch = lu_object_find(env, ludev, fid, NULL); if (!IS_ERR(luch)) { if (lu_object_exists(luch)) { struct osd_object *child; @@ -2183,8 +2153,8 @@ static int osd_index_compat_insert(const struct lu_env *env, CERROR("No osd slice.\n"); result = -ENOENT; } - LASSERT(osd_invariant(obj)); - LASSERT(osd_invariant(child)); + LINVRNT(osd_invariant(obj)); + LINVRNT(osd_invariant(child)); } else { CERROR("Sorry.\n"); result = -ENOENT; @@ -2192,11 +2162,11 @@ static int osd_index_compat_insert(const struct lu_env *env, lu_object_put(env, luch); } else result = PTR_ERR(luch); - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); return result; } -static struct dt_index_operations osd_index_compat_ops = { +static const struct dt_index_operations osd_index_compat_ops = { .dio_lookup = osd_index_compat_lookup, .dio_insert = osd_index_compat_insert, .dio_delete = osd_index_compat_delete @@ -2231,13 +2201,11 @@ LU_KEY_FINI(osd, struct osd_thread_info); static void osd_key_exit(const struct lu_context *ctx, struct lu_context_key *key, void *data) { -#if OSD_COUNTERS struct osd_thread_info *info = data; LASSERT(info->oti_r_locks == 0); LASSERT(info->oti_w_locks == 0); LASSERT(info->oti_txns == 0); -#endif } static int osd_device_init(const struct lu_env *env, struct lu_device *d, @@ -2444,7 +2412,7 @@ static int osd_fid_lookup(const struct lu_env *env, struct inode *inode; int result; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); LASSERT(obj->oo_inode == NULL); LASSERT(fid_is_sane(fid)); /* @@ -2482,7 +2450,7 @@ static int osd_fid_lookup(const struct lu_env *env, result = PTR_ERR(inode); } else if (result == -ENOENT) result = 0; - LASSERT(osd_invariant(obj)); + LINVRNT(osd_invariant(obj)); RETURN(result); } @@ -2570,7 +2538,7 @@ static int osd_object_invariant(const struct lu_object *l) return osd_invariant(osd_obj(l)); } -static struct lu_object_operations osd_lu_obj_ops = { +static const struct lu_object_operations osd_lu_obj_ops = { .loo_object_init = osd_object_init, .loo_object_delete = osd_object_delete, .loo_object_release = osd_object_release, @@ -2579,16 +2547,19 @@ static struct lu_object_operations osd_lu_obj_ops = { .loo_object_invariant = osd_object_invariant }; -static struct lu_device_operations osd_lu_ops = { +static const struct lu_device_operations osd_lu_ops = { .ldo_object_alloc = osd_object_alloc, .ldo_process_config = osd_process_config, .ldo_recovery_complete = osd_recovery_complete }; -static struct lu_device_type_operations osd_device_type_ops = { +static const struct lu_device_type_operations osd_device_type_ops = { .ldto_init = osd_type_init, .ldto_fini = osd_type_fini, + .ldto_start = osd_type_start, + .ldto_stop = osd_type_stop, + .ldto_device_alloc = osd_device_alloc, .ldto_device_free = osd_device_free,