+/**
+ * Allocate a specific striping layout on a user defined set of OSTs.
+ *
+ * Allocates new striping using the OST index range provided by the data from
+ * the lmm_obejcts contained in the lov_user_md passed to this method. Full
+ * OSTs are not considered. The exact order of OSTs requested by the user
+ * is respected as much as possible depending on OST status. The number of
+ * stripes needed and stripe offset are taken from the object. If that number
+ * can not be met, then the function returns a failure and then it's the
+ * caller's responsibility to release the stripes allocated. All the internal
+ * structures are protected, but no concurrent allocation is allowed on the
+ * same objects.
+ *
+ * \param[in] env execution environment for this thread
+ * \param[in] lo LOD object
+ * \param[out] stripe striping created
+ * \param[in] lum stripe md to specify list of OSTs
+ * \param[in] th transaction handle
+ *
+ * \retval 0 on success
+ * \retval -ENODEV OST index does not exist on file system
+ * \retval -EINVAL requested OST index is invalid
+ * \retval negative negated errno on error
+ */
+static int lod_alloc_ost_list(const struct lu_env *env,
+ struct lod_object *lo, struct dt_object **stripe,
+ struct lov_user_md *lum, struct thandle *th)
+{
+ struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
+ struct obd_statfs *sfs = &lod_env_info(env)->lti_osfs;
+ struct dt_object *o;
+ struct lov_user_md_v3 *v3;
+ unsigned int array_idx = 0;
+ int stripe_count = 0;
+ int i;
+ int rc;
+ ENTRY;
+
+ /* for specific OSTs layout */
+ LASSERT(lum != NULL && lum->lmm_magic == LOV_USER_MAGIC_SPECIFIC);
+ lustre_print_user_md(D_OTHER, lum, __func__);
+
+ rc = lod_qos_ost_in_use_clear(env, lo->ldo_stripenr);
+ if (rc < 0)
+ RETURN(rc);
+
+ v3 = (struct lov_user_md_v3 *)lum;
+ for (i = 0; i < lo->ldo_stripenr; i++) {
+ if (v3->lmm_objects[i].l_ost_idx == lo->ldo_stripe_offset) {
+ array_idx = i;
+ break;
+ }
+ }
+ if (i == lo->ldo_stripenr) {
+ CDEBUG(D_OTHER,
+ "%s: start index %d not in the specified list of OSTs\n",
+ lod2obd(m)->obd_name, lo->ldo_stripe_offset);
+ RETURN(-EINVAL);
+ }
+
+ for (i = 0; i < lo->ldo_stripenr;
+ i++, array_idx = (array_idx + 1) % lo->ldo_stripenr) {
+ __u32 ost_idx = v3->lmm_objects[array_idx].l_ost_idx;
+
+ if (!cfs_bitmap_check(m->lod_ost_bitmap, ost_idx)) {
+ rc = -ENODEV;
+ break;
+ }
+
+ /*
+ * do not put >1 objects on a single OST
+ */
+ if (lod_qos_is_ost_used(env, ost_idx, stripe_count)) {
+ rc = -EINVAL;
+ break;
+ }
+
+ rc = lod_statfs_and_check(env, m, ost_idx, sfs);
+ if (rc < 0) /* this OSP doesn't feel well */
+ break;
+
+ o = lod_qos_declare_object_on(env, m, ost_idx, th);
+ if (IS_ERR(o)) {
+ rc = PTR_ERR(o);
+ CDEBUG(D_OTHER,
+ "%s: can't declare new object on #%u: %d\n",
+ lod2obd(m)->obd_name, ost_idx, rc);
+ break;
+ }
+
+ /*
+ * We've successfully declared (reserved) an object
+ */
+ lod_qos_ost_in_use(env, stripe_count, ost_idx);
+ stripe[stripe_count] = o;
+ stripe_count++;
+ }
+
+ RETURN(rc);
+}
+
+/**
+ * Allocate a striping on a predefined set of OSTs.
+ *
+ * Allocates new layout starting from OST index in lo->ldo_stripe_offset.
+ * Full OSTs are not considered. The exact order of OSTs is not important and
+ * varies depending on OST status. The allocation procedure prefers the targets
+ * with precreated objects ready. The number of stripes needed and stripe
+ * offset are taken from the object. If that number cannot be met, then the
+ * function returns an error and then it's the caller's responsibility to
+ * release the stripes allocated. All the internal structures are protected,
+ * but no concurrent allocation is allowed on the same objects.
+ *
+ * \param[in] env execution environment for this thread
+ * \param[in] lo LOD object
+ * \param[out] stripe striping created
+ * \param[in] flags not used
+ * \param[in] th transaction handle
+ *
+ * \retval 0 on success
+ * \retval -ENOSPC if no OST objects are available at all
+ * \retval -EFBIG if not enough OST objects are found
+ * \retval -EINVAL requested offset is invalid
+ * \retval negative errno on failure
+ */