- /* Recreate a specific object id at the given OST index */
- if (src_oa->o_valid & OBD_MD_FLFLAGS && src_oa->o_flags &
- OBD_FL_RECREATE_OBJS) {
- struct lov_stripe_md obj_md;
- struct lov_stripe_md *obj_mdp = &obj_md;
-
- ost_idx = src_oa->o_nlink;
- lsm = *ea;
- if (lsm == NULL)
- RETURN(-EINVAL);
- if (ost_idx >= lov->desc.ld_tgt_count)
- RETURN(-EINVAL);
- for (i = 0; i < lsm->lsm_stripe_count; i++) {
- if (lsm->lsm_oinfo[i].loi_ost_idx == ost_idx) {
- if (lsm->lsm_oinfo[i].loi_id != src_oa->o_id)
- RETURN(-EINVAL);
- break;
- }
- }
- if (i == lsm->lsm_stripe_count)
- RETURN(-EINVAL);
-
- rc = obd_create(lov->tgts[ost_idx].ltd_exp, src_oa,
- &obj_mdp, oti);
- RETURN(rc);
- }
-
- ret_oa = obdo_alloc();
- if (!ret_oa)
- RETURN(-ENOMEM);
-
- tmp_oa = obdo_alloc();
- if (!tmp_oa)
- GOTO(out_oa, rc = -ENOMEM);
-
- lsm = *ea;
- if (lsm == NULL) {
- int stripes;
- ost_count = lov_get_stripecnt(lov, 0);
-
- /* If the MDS file was truncated up to some size, stripe over
- * enough OSTs to allow the file to be created at that size. */
- if (src_oa->o_valid & OBD_MD_FLSIZE) {
- stripes=((src_oa->o_size+LUSTRE_STRIPE_MAXBYTES)>>12)-1;
- do_div(stripes, (__u32)(LUSTRE_STRIPE_MAXBYTES >> 12));
-
- if (stripes > lov->desc.ld_active_tgt_count)
- RETURN(-EFBIG);
- if (stripes < ost_count)
- stripes = ost_count;
- } else {
- stripes = ost_count;
- }
-
- rc = lov_alloc_memmd(&lsm, stripes, lov->desc.ld_pattern ?
- lov->desc.ld_pattern : LOV_PATTERN_RAID0);
- if (rc < 0)
- GOTO(out_tmp, rc);
-
- rc = 0;
- }
-
- ost_count = lov->desc.ld_tgt_count;
-
- LASSERT(src_oa->o_valid & OBD_MD_FLID);
- lsm->lsm_object_id = src_oa->o_id;
- if (!lsm->lsm_stripe_size)
- lsm->lsm_stripe_size = lov->desc.ld_default_stripe_size;
- if (!lsm->lsm_pattern) {
- lsm->lsm_pattern = lov->desc.ld_pattern ?
- lov->desc.ld_pattern : LOV_PATTERN_RAID0;
- }
-
- if (*ea == NULL || lsm->lsm_oinfo[0].loi_ost_idx >= ost_count) {
- if (--ost_start_count <= 0) {
- ost_start_idx = ll_insecure_random_int();
- ost_start_count = LOV_CREATE_RESEED_INTERVAL;
- } else if (lsm->lsm_stripe_count >=
- lov->desc.ld_active_tgt_count) {
- /* If we allocate from all of the stripes, make the
- * next file start on the next OST. */
- ++ost_start_idx;
- }
- ost_idx = ost_start_idx % ost_count;
- } else {
- ost_idx = lsm->lsm_oinfo[0].loi_ost_idx;
- }
-
- CDEBUG(D_INODE, "allocating %d subobjs for objid "LPX64" at idx %d\n",
- lsm->lsm_stripe_count, lsm->lsm_object_id, ost_idx);
-
- /* XXX LOV STACKING: need to figure out how many real OSCs */
- if (oti && (src_oa->o_valid & OBD_MD_FLCOOKIE)) {
- oti_alloc_cookies(oti, lsm->lsm_stripe_count);
- if (!oti->oti_logcookies)
- GOTO(out_cleanup, rc = -ENOMEM);
- cookies = oti->oti_logcookies;
- }
-
- loi = lsm->lsm_oinfo;
- for (i = 0; i < ost_count; i++, ost_idx = (ost_idx + 1) % ost_count) {
- struct lov_stripe_md obj_md;
- struct lov_stripe_md *obj_mdp = &obj_md;
- int err;
-
- ++ost_start_idx;
- if (lov->tgts[ost_idx].active == 0) {
- CDEBUG(D_HA, "lov idx %d inactive\n", ost_idx);
- continue;
- }
-
- /* create data objects with "parent" OA */
- memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
-
- /* XXX When we start creating objects on demand, we need to
- * make sure that we always create the object on the
- * stripe which holds the existing file size.
- */
- if (src_oa->o_valid & OBD_MD_FLSIZE) {
- if (lov_stripe_offset(lsm, src_oa->o_size, i,
- &tmp_oa->o_size) < 0 &&
- tmp_oa->o_size)
- tmp_oa->o_size--;
-
- CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
- i, tmp_oa->o_size, src_oa->o_size);
- }