/** * Look-up accounting object to collect space usage information for user * or group. * * \param env - is the environment passed by the caller * \param dev - is the dt_device storing the accounting object * \param type - is the quota type, either USRQUOTA or GRPQUOTA */ struct dt_object *acct_obj_lookup(const struct lu_env *env, struct dt_device *dev, int type) { struct lquota_thread_info *qti = lquota_info(env); struct dt_object *obj = NULL; ENTRY; lu_local_obj_fid(&qti->qti_fid, qtype2acct_oid(type)); /* lookup the accounting object */ obj = dt_locate(env, dev, &qti->qti_fid); if (IS_ERR(obj)) RETURN(obj); if (!dt_object_exists(obj)) { dt_object_put(env, obj); RETURN(ERR_PTR(-ENOENT)); } if (obj->do_index_ops == NULL) { int rc; /* set up indexing operations */ rc = obj->do_ops->do_index_try(env, obj, &dt_acct_features); if (rc) { CERROR("%s: failed to set up indexing operations for %s" " acct object rc:%d\n", dev->dd_lu_dev.ld_obd->obd_name, qtype_name(type), rc); dt_object_put(env, obj); RETURN(ERR_PTR(rc)); } } RETURN(obj); }
/* writes the cat list */ int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d, int idx, int count, struct llog_catid *idarray) { struct llog_thread_info *lgi = llog_info(env); struct dt_object *o = NULL; struct thandle *th; int rc, size; if (!count) RETURN(0); LASSERT(d); size = sizeof(*idarray) * count; lgi->lgi_off = idx * sizeof(*idarray); lu_local_obj_fid(&lgi->lgi_fid, LLOG_CATALOGS_OID); o = dt_locate(env, d, &lgi->lgi_fid); if (IS_ERR(o)) RETURN(PTR_ERR(o)); if (!dt_object_exists(o)) GOTO(out, rc = -ENOENT); rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA); if (rc) GOTO(out, rc); if (!S_ISREG(lgi->lgi_attr.la_mode)) { CERROR("%s: CATALOGS is not a regular file!: mode = %o\n", o->do_lu.lo_dev->ld_obd->obd_name, lgi->lgi_attr.la_mode); GOTO(out, rc = -ENOENT); } th = dt_trans_create(env, d); if (IS_ERR(th)) GOTO(out, rc = PTR_ERR(th)); rc = dt_declare_record_write(env, o, size, lgi->lgi_off, th); if (rc) GOTO(out, rc); rc = dt_trans_start_local(env, d, th); if (rc) GOTO(out_trans, rc); lgi->lgi_buf.lb_buf = idarray; lgi->lgi_buf.lb_len = size; rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th); if (rc) CDEBUG(D_INODE, "error writeing CATALOGS: rc = %d\n", rc); out_trans: dt_trans_stop(env, d, th); out: lu_object_put(env, &o->do_lu); RETURN(rc); }
int tgt_init(const struct lu_env *env, struct lu_target *lut, struct obd_device *obd, struct dt_device *dt) { struct dt_object_format dof; struct lu_attr attr; struct lu_fid fid; struct dt_object *o; int rc = 0; ENTRY; LASSERT(lut); LASSERT(obd); lut->lut_obd = obd; lut->lut_bottom = dt; lut->lut_last_rcvd = NULL; obd->u.obt.obt_lut = lut; obd->u.obt.obt_magic = OBT_MAGIC; spin_lock_init(&lut->lut_translock); OBD_ALLOC(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); if (lut->lut_client_bitmap == NULL) RETURN(-ENOMEM); memset(&attr, 0, sizeof(attr)); attr.la_valid = LA_MODE; attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; dof.dof_type = dt_mode_to_dft(S_IFREG); lu_local_obj_fid(&fid, LAST_RECV_OID); o = dt_find_or_create(env, lut->lut_bottom, &fid, &dof, &attr); if (!IS_ERR(o)) { lut->lut_last_rcvd = o; } else { OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); lut->lut_client_bitmap = NULL; rc = PTR_ERR(o); CERROR("cannot open %s: rc = %d\n", LAST_RCVD, rc); } RETURN(rc); }
/* reads the catalog list */ int llog_osd_get_cat_list(const struct lu_env *env, struct dt_device *d, int idx, int count, struct llog_catid *idarray) { struct llog_thread_info *lgi = llog_info(env); struct dt_object *o = NULL; struct thandle *th; int rc, size; ENTRY; LASSERT(d); size = sizeof(*idarray) * count; lgi->lgi_off = idx * sizeof(*idarray); lu_local_obj_fid(&lgi->lgi_fid, LLOG_CATALOGS_OID); o = dt_locate(env, d, &lgi->lgi_fid); if (IS_ERR(o)) RETURN(PTR_ERR(o)); if (!dt_object_exists(o)) { th = dt_trans_create(env, d); if (IS_ERR(th)) GOTO(out, rc = PTR_ERR(th)); lgi->lgi_attr.la_valid = LA_MODE; lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG); rc = dt_declare_create(env, o, &lgi->lgi_attr, NULL, &lgi->lgi_dof, th); if (rc) GOTO(out_trans, rc); rc = dt_trans_start_local(env, d, th); if (rc) GOTO(out_trans, rc); dt_write_lock(env, o, 0); if (!dt_object_exists(o)) rc = dt_create(env, o, &lgi->lgi_attr, NULL, &lgi->lgi_dof, th); dt_write_unlock(env, o); out_trans: dt_trans_stop(env, d, th); if (rc) GOTO(out, rc); } rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA); if (rc) GOTO(out, rc); if (!S_ISREG(lgi->lgi_attr.la_mode)) { CERROR("%s: CATALOGS is not a regular file!: mode = %o\n", o->do_lu.lo_dev->ld_obd->obd_name, lgi->lgi_attr.la_mode); GOTO(out, rc = -ENOENT); } CDEBUG(D_CONFIG, "cat list: disk size=%d, read=%d\n", (int)lgi->lgi_attr.la_size, size); /* return just number of llogs */ if (idarray == NULL) { rc = lgi->lgi_attr.la_size / sizeof(*idarray); GOTO(out, rc); } /* read for new ost index or for empty file */ memset(idarray, 0, size); if (lgi->lgi_attr.la_size < lgi->lgi_off + size) GOTO(out, rc = 0); if (lgi->lgi_attr.la_size < lgi->lgi_off + size) size = lgi->lgi_attr.la_size - lgi->lgi_off; lgi->lgi_buf.lb_buf = idarray; lgi->lgi_buf.lb_len = size; rc = dt_record_read(env, o, &lgi->lgi_buf, &lgi->lgi_off); if (rc) { CERROR("%s: error reading CATALOGS: rc = %d\n", o->do_lu.lo_dev->ld_obd->obd_name, rc); GOTO(out, rc); } EXIT; out: lu_object_put(env, &o->do_lu); RETURN(rc); }
int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld, struct dt_device *dt) { struct dt_object *dt_obj = NULL; struct lu_fid fid; struct lu_attr *attr = NULL; struct lu_seq_range *range = NULL; struct fld_thread_info *info; struct dt_object_format dof; struct dt_it *it; const struct dt_it_ops *iops; int rc; ENTRY; info = lu_context_key_get(&env->le_ctx, &fld_thread_key); LASSERT(info != NULL); lu_local_obj_fid(&fid, FLD_INDEX_OID); OBD_ALLOC_PTR(attr); if (attr == NULL) RETURN(-ENOMEM); memset(attr, 0, sizeof(attr)); attr->la_valid = LA_MODE; attr->la_mode = S_IFREG | 0666; dof.dof_type = DFT_INDEX; dof.u.dof_idx.di_feat = &fld_index_features; dt_obj = dt_find_or_create(env, dt, &fid, &dof, attr); if (IS_ERR(dt_obj)) { rc = PTR_ERR(dt_obj); CERROR("%s: Can't find \"%s\" obj %d\n", fld->lsf_name, fld_index_name, rc); dt_obj = NULL; GOTO(out, rc); } fld->lsf_obj = dt_obj; rc = dt_obj->do_ops->do_index_try(env, dt_obj, &fld_index_features); if (rc != 0) { CERROR("%s: File \"%s\" is not an index: rc = %d!\n", fld->lsf_name, fld_index_name, rc); GOTO(out, rc); } range = &info->fti_rec; /* Load fld entry to cache */ iops = &dt_obj->do_index_ops->dio_it; it = iops->init(env, dt_obj, 0, NULL); if (IS_ERR(it)) GOTO(out, rc = PTR_ERR(it)); rc = iops->load(env, it, 0); if (rc < 0) GOTO(out_it_fini, rc); if (rc > 0) { /* Load FLD entry into server cache */ do { rc = iops->rec(env, it, (struct dt_rec *)range, 0); if (rc != 0) GOTO(out_it_put, rc); LASSERT(range != NULL); range_be_to_cpu(range, range); rc = fld_cache_insert(fld->lsf_cache, range); if (rc != 0) GOTO(out_it_put, rc); rc = iops->next(env, it); } while (rc == 0); } /* Note: fld_insert_entry will detect whether these * special entries already exist inside FLDB */ mutex_lock(&fld->lsf_lock); rc = fld_insert_special_entries(env, fld); mutex_unlock(&fld->lsf_lock); if (rc != 0) { CERROR("%s: insert special entries failed!: rc = %d\n", fld->lsf_name, rc); GOTO(out_it_put, rc); } out_it_put: iops->put(env, it); out_it_fini: iops->fini(env, it); out: if (attr != NULL) OBD_FREE_PTR(attr); if (rc != 0) { if (dt_obj != NULL) lu_object_put(env, &dt_obj->do_lu); fld->lsf_obj = NULL; } RETURN(rc); }
int tgt_init(const struct lu_env *env, struct lu_target *lut, struct obd_device *obd, struct dt_device *dt, struct tgt_opc_slice *slice, int request_fail_id, int reply_fail_id) { struct dt_object_format dof; struct lu_attr attr; struct lu_fid fid; struct dt_object *o; int rc = 0; ENTRY; LASSERT(lut); LASSERT(obd); lut->lut_obd = obd; lut->lut_bottom = dt; lut->lut_last_rcvd = NULL; lut->lut_client_bitmap = NULL; obd->u.obt.obt_lut = lut; obd->u.obt.obt_magic = OBT_MAGIC; /* set request handler slice and parameters */ lut->lut_slice = slice; lut->lut_reply_fail_id = reply_fail_id; lut->lut_request_fail_id = request_fail_id; /* sptlrcp variables init */ rwlock_init(&lut->lut_sptlrpc_lock); sptlrpc_rule_set_init(&lut->lut_sptlrpc_rset); lut->lut_mds_capa = 1; lut->lut_oss_capa = 1; spin_lock_init(&lut->lut_flags_lock); lut->lut_sync_lock_cancel = NEVER_SYNC_ON_CANCEL; /* last_rcvd initialization is needed by replayable targets only */ if (!obd->obd_replayable) RETURN(0); spin_lock_init(&lut->lut_translock); OBD_ALLOC(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); if (lut->lut_client_bitmap == NULL) RETURN(-ENOMEM); memset(&attr, 0, sizeof(attr)); attr.la_valid = LA_MODE; attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; dof.dof_type = dt_mode_to_dft(S_IFREG); lu_local_obj_fid(&fid, LAST_RECV_OID); o = dt_find_or_create(env, lut->lut_bottom, &fid, &dof, &attr); if (IS_ERR(o)) { rc = PTR_ERR(o); CERROR("%s: cannot open LAST_RCVD: rc = %d\n", tgt_name(lut), rc); GOTO(out_bitmap, rc); } lut->lut_last_rcvd = o; rc = tgt_server_data_init(env, lut); if (rc < 0) GOTO(out_obj, rc); /* prepare transactions callbacks */ lut->lut_txn_cb.dtc_txn_start = tgt_txn_start_cb; lut->lut_txn_cb.dtc_txn_stop = tgt_txn_stop_cb; lut->lut_txn_cb.dtc_txn_commit = NULL; lut->lut_txn_cb.dtc_cookie = lut; lut->lut_txn_cb.dtc_tag = LCT_DT_THREAD | LCT_MD_THREAD; CFS_INIT_LIST_HEAD(&lut->lut_txn_cb.dtc_linkage); dt_txn_callback_add(lut->lut_bottom, &lut->lut_txn_cb); RETURN(0); out_obj: lu_object_put(env, &lut->lut_last_rcvd->do_lu); lut->lut_last_rcvd = NULL; out_bitmap: OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); lut->lut_client_bitmap = NULL; return rc; }
int tgt_init(const struct lu_env *env, struct lu_target *lut, struct obd_device *obd, struct dt_device *dt, struct tgt_opc_slice *slice, int request_fail_id, int reply_fail_id) { struct dt_object_format dof; struct lu_attr attr; struct lu_fid fid; struct dt_object *o; int rc = 0; ENTRY; LASSERT(lut); LASSERT(obd); lut->lut_obd = obd; lut->lut_bottom = dt; lut->lut_last_rcvd = NULL; lut->lut_client_bitmap = NULL; obd->u.obt.obt_lut = lut; obd->u.obt.obt_magic = OBT_MAGIC; /* set request handler slice and parameters */ lut->lut_slice = slice; lut->lut_reply_fail_id = reply_fail_id; lut->lut_request_fail_id = request_fail_id; /* sptlrcp variables init */ rwlock_init(&lut->lut_sptlrpc_lock); sptlrpc_rule_set_init(&lut->lut_sptlrpc_rset); lut->lut_mds_capa = 1; lut->lut_oss_capa = 1; /* last_rcvd initialization is needed by replayable targets only */ if (!obd->obd_replayable) RETURN(0); spin_lock_init(&lut->lut_translock); OBD_ALLOC(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); if (lut->lut_client_bitmap == NULL) RETURN(-ENOMEM); memset(&attr, 0, sizeof(attr)); attr.la_valid = LA_MODE; attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR; dof.dof_type = dt_mode_to_dft(S_IFREG); lu_local_obj_fid(&fid, LAST_RECV_OID); o = dt_find_or_create(env, lut->lut_bottom, &fid, &dof, &attr); if (!IS_ERR(o)) { lut->lut_last_rcvd = o; } else { OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3); lut->lut_client_bitmap = NULL; rc = PTR_ERR(o); CERROR("cannot open %s: rc = %d\n", LAST_RCVD, rc); } RETURN(rc); }