+ struct lu_fid *fid = &osp_env_info(env)->osi_fid;
+ struct lu_fid *last_fid = &osp->opd_last_used_fid;
+ int rc;
+ ENTRY;
+
+ rc = seq_client_get_seq(env, osp->opd_obd->u.cli.cl_seq, &fid->f_seq);
+ if (rc != 0) {
+ CERROR("%s: alloc fid error: rc = %d\n",
+ osp->opd_obd->obd_name, rc);
+ RETURN(rc);
+ }
+
+ fid->f_oid = 1;
+ fid->f_ver = 0;
+ LASSERTF(fid_seq(fid) != fid_seq(last_fid),
+ "fid "DFID", last_fid "DFID"\n", PFID(fid),
+ PFID(last_fid));
+
+ rc = osp_write_last_oid_seq_files(env, osp, fid, 1);
+ if (rc != 0) {
+ CERROR("%s: Can not update oid/seq file: rc = %d\n",
+ osp->opd_obd->obd_name, rc);
+ RETURN(rc);
+ }
+
+ LCONSOLE_INFO("%s: update sequence from "LPX64" to "LPX64"\n",
+ osp->opd_obd->obd_name, fid_seq(last_fid),
+ fid_seq(fid));
+ /* Update last_xxx to the new seq */
+ spin_lock(&osp->opd_pre_lock);
+ osp->opd_last_used_fid = *fid;
+ osp->opd_gap_start_fid = *fid;
+ osp->opd_pre_used_fid = *fid;
+ osp->opd_pre_last_created_fid = *fid;
+ spin_unlock(&osp->opd_pre_lock);
+
+ RETURN(rc);
+}
+
+/**
+ * alloc fids for precreation.
+ * rc = 0 Success, @grow is the count of real allocation.
+ * rc = 1 Current seq is used up.
+ * rc < 0 Other error.
+ **/
+static int osp_precreate_fids(const struct lu_env *env, struct osp_device *osp,
+ struct lu_fid *fid, int *grow)
+{
+ struct osp_thread_info *osi = osp_env_info(env);
+ __u64 end;
+ int i = 0;
+
+ if (fid_is_idif(fid)) {
+ struct lu_fid *last_fid;
+ struct ost_id *oi = &osi->osi_oi;
+
+ spin_lock(&osp->opd_pre_lock);
+ last_fid = &osp->opd_pre_last_created_fid;
+ fid_to_ostid(last_fid, oi);
+ end = min(ostid_id(oi) + *grow, IDIF_MAX_OID);
+ *grow = end - ostid_id(oi);
+ ostid_set_id(oi, ostid_id(oi) + *grow);
+ spin_unlock(&osp->opd_pre_lock);
+
+ if (*grow == 0)
+ return 1;
+
+ ostid_to_fid(fid, oi, osp->opd_index);
+ return 0;
+ }
+
+ spin_lock(&osp->opd_pre_lock);
+ *fid = osp->opd_pre_last_created_fid;
+ end = fid->f_oid;
+ end = min((end + *grow), (__u64)LUSTRE_DATA_SEQ_MAX_WIDTH);
+ *grow = end - fid->f_oid;
+ fid->f_oid += end - fid->f_oid;
+ spin_unlock(&osp->opd_pre_lock);
+
+ CDEBUG(D_INFO, "Expect %d, actual %d ["DFID" -- "DFID"]\n",
+ *grow, i, PFID(fid), PFID(&osp->opd_pre_last_created_fid));
+
+ return *grow > 0 ? 0 : 1;
+}
+
+static int osp_precreate_send(const struct lu_env *env, struct osp_device *d)
+{
+ struct osp_thread_info *oti = osp_env_info(env);