int ofd_trans_start(const struct lu_env *env, struct ofd_device *ofd, struct ofd_object *obj, struct thandle *th) { struct ofd_thread_info *info = ofd_info(env); int rc; if (info->fti_exp == NULL) return 0; /* declare last_rcvd update */ rc = dt_declare_record_write(env, ofd->ofd_lut.lut_last_rcvd, sizeof(struct lsd_client_data), info->fti_exp->exp_target_data.ted_lr_off, th); if (rc) RETURN(rc); /* declare last_rcvd header update */ rc = dt_declare_record_write(env, ofd->ofd_lut.lut_last_rcvd, sizeof(ofd->ofd_lut.lut_lsd), 0, th); if (rc) RETURN(rc); /* version change is required for this object */ if (obj) { ofd_info(env)->fti_obj = obj; rc = dt_declare_version_set(env, ofd_object_child(obj), th); if (rc) RETURN(rc); } return dt_trans_start(env, ofd->ofd_osd, th); }
/** * Write fid into last_oid/last_seq file. **/ int osp_write_last_oid_seq_files(struct lu_env *env, struct osp_device *osp, struct lu_fid *fid, int sync) { struct osp_thread_info *oti = osp_env_info(env); struct lu_buf *lb_oid = &oti->osi_lb; struct lu_buf *lb_oseq = &oti->osi_lb2; loff_t oid_off; loff_t oseq_off; struct thandle *th; int rc; ENTRY; /* Note: through f_oid is only 32bits, it will also write * 64 bits for oid to keep compatiblity with the previous * version. */ lb_oid->lb_buf = &fid->f_oid; lb_oid->lb_len = sizeof(obd_id); oid_off = sizeof(obd_id) * osp->opd_index; lb_oseq->lb_buf = &fid->f_seq; lb_oseq->lb_len = sizeof(obd_id); oseq_off = sizeof(obd_id) * osp->opd_index; th = dt_trans_create(env, osp->opd_storage); if (IS_ERR(th)) RETURN(PTR_ERR(th)); th->th_sync |= sync; rc = dt_declare_record_write(env, osp->opd_last_used_oid_file, lb_oid->lb_len, oid_off, th); if (rc != 0) GOTO(out, rc); rc = dt_declare_record_write(env, osp->opd_last_used_seq_file, lb_oseq->lb_len, oseq_off, th); if (rc != 0) GOTO(out, rc); rc = dt_trans_start_local(env, osp->opd_storage, th); if (rc != 0) GOTO(out, rc); rc = dt_record_write(env, osp->opd_last_used_oid_file, lb_oid, &oid_off, th); if (rc != 0) { CERROR("%s: can not write to last seq file: rc = %d\n", osp->opd_obd->obd_name, rc); GOTO(out, rc); } rc = dt_record_write(env, osp->opd_last_used_seq_file, lb_oseq, &oseq_off, th); if (rc) { CERROR("%s: can not write to last seq file: rc = %d\n", osp->opd_obd->obd_name, rc); GOTO(out, rc); } out: dt_trans_stop(env, osp->opd_storage, th); RETURN(rc); }
/** * Write the special file which contains the list of llog catalogs IDs * * This function writes the CATALOG file which contains the array of llog * catalogs IDs. It is used mostly to store OSP llogs indexed by OST/MDT * number. * * \param[in] env execution environment * \param[in] d corresponding storage device * \param[in] idx position to start from, usually OST/MDT index * \param[in] count how many catalog IDs to write * \param[out] idarray the buffer with the data to write. * \param[in] fid LLOG_CATALOGS_OID for CATALOG object * * \retval 0 on successful write of catalog IDs * \retval negative value on error */ int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d, int idx, int count, struct llog_catid *idarray, const struct lu_fid *fid) { struct llog_thread_info *lgi = llog_info(env); struct dt_object *o = NULL; struct thandle *th; int rc, size; if (count == 0) RETURN(0); LASSERT(d); size = sizeof(*idarray) * count; lgi->lgi_off = idx * sizeof(*idarray); lgi->lgi_fid = *fid; 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)); lgi->lgi_buf.lb_len = size; lgi->lgi_buf.lb_buf = idarray; rc = dt_declare_record_write(env, o, &lgi->lgi_buf, lgi->lgi_off, th); if (rc) GOTO(out, rc); rc = dt_trans_start_local(env, d, th); if (rc) GOTO(out_trans, rc); rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th); if (rc) CDEBUG(D_INODE, "can't write CATALOGS at index %d: rc = %d\n", idx, rc); out_trans: dt_trans_stop(env, d, th); out: lu_object_put(env, &o->do_lu); RETURN(rc); }
static int __out_tx_write(const struct lu_env *env, struct dt_object *dt_obj, const struct lu_buf *buf, loff_t pos, struct thandle_exec_args *ta, struct object_update_reply *reply, int index, char *file, int line) { struct tx_arg *arg; LASSERT(ta->ta_handle != NULL); ta->ta_err = dt_declare_record_write(env, dt_obj, buf, pos, ta->ta_handle); if (ta->ta_err != 0) return ta->ta_err; arg = tx_add_exec(ta, out_tx_write_exec, NULL, file, line); LASSERT(arg); lu_object_get(&dt_obj->do_lu); arg->object = dt_obj; arg->u.write.buf = *buf; arg->u.write.pos = pos; arg->reply = reply; arg->index = index; return 0; }
static int llog_osd_declare_write_rec(const struct lu_env *env, struct llog_handle *loghandle, struct llog_rec_hdr *rec, int idx, struct thandle *th) { struct llog_thread_info *lgi = llog_info(env); struct dt_object *o; int rc; ENTRY; LASSERT(env); LASSERT(th); LASSERT(loghandle); o = loghandle->lgh_obj; LASSERT(o); /* each time we update header */ rc = dt_declare_record_write(env, o, sizeof(struct llog_log_hdr), 0, th); if (rc || idx == 0) /* if error or just header */ RETURN(rc); if (dt_object_exists(o)) { rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA); lgi->lgi_off = lgi->lgi_attr.la_size; LASSERT(ergo(rc == 0, lgi->lgi_attr.la_valid & LA_SIZE)); if (rc) RETURN(rc); rc = dt_declare_punch(env, o, lgi->lgi_off, OBD_OBJECT_EOF, th); if (rc) RETURN(rc); } else { lgi->lgi_off = 0; } /* XXX: implement declared window or multi-chunks approach */ rc = dt_declare_record_write(env, o, 32 * 1024, lgi->lgi_off, th); RETURN(rc); }
/** * Implementation of the llog_operations::lop_declare_write * * This function declares the new record write. * * \param[in] env execution environment * \param[in] loghandle llog handle of the current llog * \param[in] rec llog record header. This is a real header of the full * llog record to write. This is the beginning of buffer * to write, the length of buffer is stored in * \a rec::lrh_len * \param[in] idx index of the llog record. If \a idx == -1 then this is * append case, otherwise \a idx is the index of record * to modify * \param[in] th current transaction handle * * \retval 0 on successful declaration * \retval negative error if declaration failed */ static int llog_osd_declare_write_rec(const struct lu_env *env, struct llog_handle *loghandle, struct llog_rec_hdr *rec, int idx, struct thandle *th) { struct llog_thread_info *lgi = llog_info(env); struct dt_object *o; int rc; ENTRY; LASSERT(env); LASSERT(th); LASSERT(loghandle); LASSERT(rec); LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE); o = loghandle->lgh_obj; LASSERT(o); lgi->lgi_buf.lb_len = sizeof(struct llog_log_hdr); lgi->lgi_buf.lb_buf = NULL; /* each time we update header */ rc = dt_declare_record_write(env, o, &lgi->lgi_buf, 0, th); if (rc || idx == 0) /* if error or just header */ RETURN(rc); /** * the pad record can be inserted so take into account double * record size */ lgi->lgi_buf.lb_len = rec->lrh_len * 2; lgi->lgi_buf.lb_buf = NULL; /* XXX: implement declared window or multi-chunks approach */ rc = dt_declare_record_write(env, o, &lgi->lgi_buf, -1, th); RETURN(rc); }
int lfsck_bookmark_store(const struct lu_env *env, struct lfsck_instance *lfsck) { struct thandle *handle; struct dt_object *obj = lfsck->li_bookmark_obj; loff_t pos = 0; int len = sizeof(struct lfsck_bookmark); int rc; ENTRY; lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, &lfsck->li_bookmark_ram); handle = dt_trans_create(env, lfsck->li_bottom); if (IS_ERR(handle)) { rc = PTR_ERR(handle); CERROR("%s: fail to create trans for storing lfsck_bookmark: " "rc = %d\n", lfsck_lfsck2name(lfsck), rc); RETURN(rc); } rc = dt_declare_record_write(env, obj, lfsck_buf_get(env, &lfsck->li_bookmark_disk, len), 0, handle); if (rc != 0) { CERROR("%s: fail to declare trans for storing lfsck_bookmark: " "rc = %d\n", lfsck_lfsck2name(lfsck), rc); GOTO(out, rc); } rc = dt_trans_start_local(env, lfsck->li_bottom, handle); if (rc != 0) { CERROR("%s: fail to start trans for storing lfsck_bookmark: " "rc = %d\n", lfsck_lfsck2name(lfsck), rc); GOTO(out, rc); } rc = dt_record_write(env, obj, lfsck_buf_get(env, &lfsck->li_bookmark_disk, len), &pos, handle); if (rc != 0) CERROR("%s: fail to store lfsck_bookmark: expected = %d, " "rc = %d\n", lfsck_lfsck2name(lfsck), len, rc); GOTO(out, rc); out: dt_trans_stop(env, lfsck->li_bottom, handle); return rc; }
static int llog_osd_declare_create(const struct lu_env *env, struct llog_handle *res, struct thandle *th) { struct llog_thread_info *lgi = llog_info(env); struct local_oid_storage *los; struct dt_object *o; int rc; ENTRY; LASSERT(res->lgh_obj); LASSERT(th); /* object can be created by another thread */ o = res->lgh_obj; if (dt_object_exists(o)) RETURN(0); los = res->private_data; LASSERT(los); rc = llog_osd_declare_new_object(env, los, o, th); if (rc) RETURN(rc); rc = dt_declare_record_write(env, o, LLOG_CHUNK_SIZE, 0, th); if (rc) RETURN(rc); if (res->lgh_name) { struct dt_object *llog_dir; llog_dir = llog_osd_dir_get(env, res->lgh_ctxt); if (IS_ERR(llog_dir)) RETURN(PTR_ERR(llog_dir)); dt_declare_ref_add(env, o, th); logid_to_fid(&res->lgh_id, &lgi->lgi_fid); rc = dt_declare_insert(env, llog_dir, (struct dt_rec *)&lgi->lgi_fid, (struct dt_key *)res->lgh_name, th); lu_object_put(env, &llog_dir->do_lu); if (rc) CERROR("%s: can't declare named llog %s: rc = %d\n", o->do_lu.lo_dev->ld_obd->obd_name, res->lgh_name, rc); } RETURN(rc); }
static int write_capa_keys(const struct lu_env *env, struct mdt_device *mdt, struct lustre_capa_key *keys) { struct mdt_thread_info *mti; struct lustre_capa_key *tmp; struct thandle *th; loff_t off = 0; int i, rc; mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); th = dt_trans_create(env, mdt->mdt_bottom); if (IS_ERR(th)) RETURN(PTR_ERR(th)); rc = dt_declare_record_write(env, mdt->mdt_ck_obj, mdt_buf_const(env, NULL, sizeof(*tmp) * 3), 0, th); if (rc) goto stop; rc = dt_trans_start_local(env, mdt->mdt_bottom, th); if (rc) goto stop; tmp = &mti->mti_capa_key; for (i = 0; i < 2; i++) { lck_cpu_to_le(tmp, &keys[i]); rc = dt_record_write(env, mdt->mdt_ck_obj, mdt_buf_const(env, tmp, sizeof(*tmp)), &off, th); if (rc) break; } stop: dt_trans_stop(env, mdt->mdt_bottom, th); CDEBUG(D_INFO, "write capability keys rc = %d:\n", rc); return rc; }
int lfsck_bookmark_store(const struct lu_env *env, struct lfsck_instance *lfsck) { struct thandle *handle; struct dt_object *obj = lfsck->li_bookmark_obj; struct dt_device *dev = lfsck_obj2dev(obj); loff_t pos = 0; int len = sizeof(struct lfsck_bookmark); int rc; ENTRY; lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, &lfsck->li_bookmark_ram); handle = dt_trans_create(env, dev); if (IS_ERR(handle)) GOTO(log, rc = PTR_ERR(handle)); rc = dt_declare_record_write(env, obj, lfsck_buf_get(env, &lfsck->li_bookmark_disk, len), 0, handle); if (rc != 0) GOTO(out, rc); rc = dt_trans_start_local(env, dev, handle); if (rc != 0) GOTO(out, rc); rc = dt_record_write(env, obj, lfsck_buf_get(env, &lfsck->li_bookmark_disk, len), &pos, handle); GOTO(out, rc); out: dt_trans_stop(env, dev, handle); log: if (rc != 0) CDEBUG(D_LFSCK, "%s: fail to store lfsck_bookmark: rc = %d\n", lfsck_lfsck2name(lfsck), rc); return rc; }
int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd, obd_id id, struct ofd_seq *oseq, int nr, int sync) { struct ofd_thread_info *info = ofd_info(env); struct ofd_object *fo = NULL; struct dt_object *next; struct thandle *th; struct ofd_object **batch; struct lu_fid *fid = &info->fti_fid; obd_id tmp; int rc; int i; int objects = 0; int nr_saved = nr; ENTRY; /* Don't create objects beyond the valid range for this SEQ */ if (unlikely(fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) && (id + nr) >= IDIF_MAX_OID)) { CERROR("%s:"DOSTID" hit the IDIF_MAX_OID (1<<48)!\n", ofd_name(ofd), id, ostid_seq(&oseq->os_oi)); RETURN(rc = -ENOSPC); } else if (unlikely(!fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) && (id + nr) >= OBIF_MAX_OID)) { CERROR("%s:"DOSTID" hit the OBIF_MAX_OID (1<<32)!\n", ofd_name(ofd), id, ostid_seq(&oseq->os_oi)); RETURN(rc = -ENOSPC); } OBD_ALLOC(batch, nr_saved * sizeof(struct ofd_object *)); if (batch == NULL) RETURN(-ENOMEM); info->fti_attr.la_valid = LA_TYPE | LA_MODE; /* * We mark object SUID+SGID to flag it for accepting UID+GID from * client on first write. Currently the permission bits on the OST are * never used, so this is OK. */ info->fti_attr.la_mode = S_IFREG | S_ISUID | S_ISGID | 0666; info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG); /* Initialize a/c/m time so any client timestamp will always * be newer and update the inode. ctime = 0 is also handled * specially in osd_inode_setattr(). See LU-221, LU-1042 */ info->fti_attr.la_valid |= LA_ATIME | LA_MTIME | LA_CTIME; info->fti_attr.la_atime = 0; info->fti_attr.la_mtime = 0; info->fti_attr.la_ctime = 0; LASSERT(id != 0); /* prepare objects */ *fid = *lu_object_fid(&oseq->os_lastid_obj->do_lu); for (i = 0; i < nr; i++) { rc = fid_set_id(fid, id + i); if (rc != 0) { if (i == 0) GOTO(out, rc); nr = i; break; } fo = ofd_object_find(env, ofd, fid); if (IS_ERR(fo)) { if (i == 0) GOTO(out, rc = PTR_ERR(fo)); nr = i; break; } ofd_write_lock(env, fo); batch[i] = fo; } info->fti_buf.lb_buf = &tmp; info->fti_buf.lb_len = sizeof(tmp); info->fti_off = 0; th = ofd_trans_create(env, ofd); if (IS_ERR(th)) GOTO(out, rc = PTR_ERR(th)); th->th_sync |= sync; rc = dt_declare_record_write(env, oseq->os_lastid_obj, &info->fti_buf, info->fti_off, th); if (rc) GOTO(trans_stop, rc); for (i = 0; i < nr; i++) { fo = batch[i]; LASSERT(fo); if (unlikely(ofd_object_exists(fo))) { /* object may exist being re-created by write replay */ CDEBUG(D_INODE, "object "LPX64"/"LPX64" exists: " DFID"\n", ostid_seq(&oseq->os_oi), id, PFID(lu_object_fid(&fo->ofo_obj.do_lu))); continue; } next = ofd_object_child(fo); LASSERT(next != NULL); rc = dt_declare_create(env, next, &info->fti_attr, NULL, &info->fti_dof, th); if (rc) { nr = i; break; } } rc = dt_trans_start_local(env, ofd->ofd_osd, th); if (rc) GOTO(trans_stop, rc); CDEBUG(D_OTHER, "%s: create new object "DFID" nr %d\n", ofd_name(ofd), PFID(fid), nr); LASSERT(nr > 0); /* When the LFSCK scanning the whole device to verify the LAST_ID file * consistency, it will load the last_id into RAM firstly, and compare * the last_id with each OST-object's ID. If the later one is larger, * then it will regard the LAST_ID file crashed. But during the LFSCK * scanning, the OFD may continue to create new OST-objects. Those new * created OST-objects will have larger IDs than the LFSCK known ones. * So from the LFSCK view, it needs to re-load the last_id from disk * file, and if the latest last_id is still smaller than the object's * ID, then the LAST_ID file is real crashed. * * To make above mechanism to work, before OFD pre-create OST-objects, * it needs to update the LAST_ID file firstly, otherwise, the LFSCK * may cannot get latest last_id although new OST-object created. */ if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_SKIP_LASTID)) { tmp = cpu_to_le64(id + nr - 1); dt_write_lock(env, oseq->os_lastid_obj, 0); rc = dt_record_write(env, oseq->os_lastid_obj, &info->fti_buf, &info->fti_off, th); dt_write_unlock(env, oseq->os_lastid_obj); if (rc != 0) GOTO(trans_stop, rc); } for (i = 0; i < nr; i++) { fo = batch[i]; LASSERT(fo); /* Only the new created objects need to be recorded. */ if (ofd->ofd_osd->dd_record_fid_accessed) { lfsck_pack_rfa(&ofd_info(env)->fti_lr, lu_object_fid(&fo->ofo_obj.do_lu)); lfsck_in_notify(env, ofd->ofd_osd, &ofd_info(env)->fti_lr); } if (likely(!ofd_object_exists(fo) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING))) { next = ofd_object_child(fo); LASSERT(next != NULL); rc = dt_create(env, next, &info->fti_attr, NULL, &info->fti_dof, th); if (rc) break; LASSERT(ofd_object_exists(fo)); } ofd_seq_last_oid_set(oseq, id + i); } objects = i; /* NOT all the wanted objects have been created, * set the LAST_ID as the real created. */ if (unlikely(objects < nr)) { int rc1; info->fti_off = 0; tmp = cpu_to_le64(ofd_seq_last_oid(oseq)); dt_write_lock(env, oseq->os_lastid_obj, 0); rc1 = dt_record_write(env, oseq->os_lastid_obj, &info->fti_buf, &info->fti_off, th); dt_write_unlock(env, oseq->os_lastid_obj); if (rc1 != 0) CERROR("%s: fail to reset the LAST_ID for seq ("LPX64 ") from "LPU64" to "LPU64"\n", ofd_name(ofd), ostid_seq(&oseq->os_oi), id + nr - 1, ofd_seq_last_oid(oseq)); } trans_stop: ofd_trans_stop(env, ofd, th, rc); out: for (i = 0; i < nr_saved; i++) { fo = batch[i]; if (fo) { ofd_write_unlock(env, fo); ofd_object_put(env, fo); } } OBD_FREE(batch, nr_saved * sizeof(struct ofd_object *)); CDEBUG((objects == 0 && rc == 0) ? D_ERROR : D_OTHER, "created %d/%d objects: %d\n", objects, nr_saved, rc); LASSERT(ergo(objects == 0, rc < 0)); RETURN(objects > 0 ? objects : rc); }
int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd, obd_id id, struct ofd_seq *oseq, int nr, int sync) { struct ofd_thread_info *info = ofd_info(env); struct ofd_object *fo = NULL; struct dt_object *next; struct thandle *th; struct ofd_object **batch; obd_id tmp; int rc; int i; int objects = 0; int nr_saved = nr; ENTRY; /* Don't create objects beyond the valid range for this SEQ */ if (unlikely(fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) && (id + nr) >= IDIF_MAX_OID)) { CERROR("%s:"DOSTID" hit the IDIF_MAX_OID (1<<48)!\n", ofd_name(ofd), id, ostid_seq(&oseq->os_oi)); RETURN(rc = -ENOSPC); } else if (unlikely(!fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) && (id + nr) >= OBIF_MAX_OID)) { CERROR("%s:"DOSTID" hit the OBIF_MAX_OID (1<<32)!\n", ofd_name(ofd), id, ostid_seq(&oseq->os_oi)); RETURN(rc = -ENOSPC); } OBD_ALLOC(batch, nr_saved * sizeof(struct ofd_object *)); if (batch == NULL) RETURN(-ENOMEM); info->fti_attr.la_valid = LA_TYPE | LA_MODE; /* * We mark object SUID+SGID to flag it for accepting UID+GID from * client on first write. Currently the permission bits on the OST are * never used, so this is OK. */ info->fti_attr.la_mode = S_IFREG | S_ISUID | S_ISGID | 0666; info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG); /* Initialize a/c/m time so any client timestamp will always * be newer and update the inode. ctime = 0 is also handled * specially in osd_inode_setattr(). See LU-221, LU-1042 */ info->fti_attr.la_valid |= LA_ATIME | LA_MTIME | LA_CTIME; info->fti_attr.la_atime = 0; info->fti_attr.la_mtime = 0; info->fti_attr.la_ctime = 0; /* prepare objects */ ostid_set_seq(&info->fti_ostid, ostid_seq(&oseq->os_oi)); for (i = 0; i < nr; i++) { ostid_set_id(&info->fti_ostid, id + i); rc = ostid_to_fid(&info->fti_fid, &info->fti_ostid, 0); if (rc) { if (i == 0) GOTO(out, rc); nr = i; break; } fo = ofd_object_find(env, ofd, &info->fti_fid); if (IS_ERR(fo)) { if (i == 0) GOTO(out, rc = PTR_ERR(fo)); nr = i; break; } ofd_write_lock(env, fo); batch[i] = fo; } info->fti_buf.lb_buf = &tmp; info->fti_buf.lb_len = sizeof(tmp); info->fti_off = 0; th = ofd_trans_create(env, ofd); if (IS_ERR(th)) GOTO(out, rc = PTR_ERR(th)); th->th_sync |= sync; rc = dt_declare_record_write(env, oseq->os_lastid_obj, sizeof(tmp), info->fti_off, th); if (rc) GOTO(trans_stop, rc); for (i = 0; i < nr; i++) { fo = batch[i]; LASSERT(fo); if (unlikely(ofd_object_exists(fo))) { /* object may exist being re-created by write replay */ CDEBUG(D_INODE, "object "LPX64"/"LPX64" exists: " DFID"\n", ostid_seq(&oseq->os_oi), id, PFID(&info->fti_fid)); continue; } next = ofd_object_child(fo); LASSERT(next != NULL); rc = dt_declare_create(env, next, &info->fti_attr, NULL, &info->fti_dof, th); if (rc) { nr = i; break; } } rc = dt_trans_start_local(env, ofd->ofd_osd, th); if (rc) GOTO(trans_stop, rc); CDEBUG(D_OTHER, "%s: create new object "DFID" nr %d\n", ofd_name(ofd), PFID(&info->fti_fid), nr); for (i = 0; i < nr; i++) { fo = batch[i]; LASSERT(fo); if (likely(!ofd_object_exists(fo))) { next = ofd_object_child(fo); LASSERT(next != NULL); rc = dt_create(env, next, &info->fti_attr, NULL, &info->fti_dof, th); if (rc) break; LASSERT(ofd_object_exists(fo)); } ofd_seq_last_oid_set(oseq, id + i); } objects = i; if (objects > 0) { tmp = cpu_to_le64(ofd_seq_last_oid(oseq)); rc = dt_record_write(env, oseq->os_lastid_obj, &info->fti_buf, &info->fti_off, th); } trans_stop: ofd_trans_stop(env, ofd, th, rc); out: for (i = 0; i < nr_saved; i++) { fo = batch[i]; if (fo) { ofd_write_unlock(env, fo); ofd_object_put(env, fo); } } OBD_FREE(batch, nr_saved * sizeof(struct ofd_object *)); CDEBUG((objects == 0 && rc == 0) ? D_ERROR : D_OTHER, "created %d/%d objects: %d\n", objects, nr_saved, rc); LASSERT(ergo(objects == 0, rc < 0)); RETURN(objects > 0 ? objects : rc); }
static int osp_declare_object_create(const struct lu_env *env, struct dt_object *dt, struct lu_attr *attr, struct dt_allocation_hint *hint, struct dt_object_format *dof, struct thandle *th) { struct osp_thread_info *osi = osp_env_info(env); struct osp_device *d = lu2osp_dev(dt->do_lu.lo_dev); struct osp_object *o = dt2osp_obj(dt); const struct lu_fid *fid; int rc = 0; ENTRY; /* should happen to non-0 OSP only so that at least one object * has been already declared in the scenario and LOD should * cleanup that */ if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OSC_CREATE_FAIL) && d->opd_index == 1) RETURN(-ENOSPC); LASSERT(d->opd_last_used_oid_file); fid = lu_object_fid(&dt->do_lu); /* * There can be gaps in precreated ids and record to unlink llog * XXX: we do not handle gaps yet, implemented before solution * was found to be racy, so we disabled that. there is no * point in making useless but expensive llog declaration. */ /* rc = osp_sync_declare_add(env, o, MDS_UNLINK64_REC, th); */ if (unlikely(!fid_is_zero(fid))) { /* replay case: caller knows fid */ osi->osi_off = sizeof(osi->osi_id) * d->opd_index; rc = dt_declare_record_write(env, d->opd_last_used_oid_file, sizeof(osi->osi_id), osi->osi_off, th); RETURN(rc); } /* * in declaration we need to reserve object so that we don't block * awaiting precreation RPC to complete */ rc = osp_precreate_reserve(env, d); /* * we also need to declare update to local "last used id" file for * recovery if object isn't used for a reason, we need to release * reservation, this can be made in osd_object_release() */ if (rc == 0) { /* mark id is reserved: in create we don't want to talk * to OST */ LASSERT(o->opo_reserved == 0); o->opo_reserved = 1; /* common for all OSPs file hystorically */ osi->osi_off = sizeof(osi->osi_id) * d->opd_index; rc = dt_declare_record_write(env, d->opd_last_used_oid_file, sizeof(osi->osi_id), osi->osi_off, th); } else { /* not needed in the cache anymore */ set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags); } RETURN(rc); }