+/* after Lustre 2.3 release there may be old file to store last generated FID
+ * If such file exists then we have to read its content
+ */
+static int lastid_compat_check(const struct lu_env *env, struct dt_device *dev,
+ __u64 lastid_seq, __u32 *first_oid,
+ struct ls_device *ls)
+{
+ struct dt_thread_info *dti = dt_info(env);
+ struct dt_object *root = NULL;
+ struct los_ondisk losd;
+ struct dt_object *o = NULL;
+ int rc = 0;
+
+ rc = dt_root_get(env, dev, &dti->dti_fid);
+ if (rc)
+ return rc;
+
+ root = ls_locate(env, ls, &dti->dti_fid, NULL);
+ if (IS_ERR(root))
+ return PTR_ERR(root);
+
+ /* find old last_id file */
+ snprintf(dti->dti_buf, sizeof(dti->dti_buf), "seq-"LPX64"-lastid",
+ lastid_seq);
+ rc = dt_lookup_dir(env, root, dti->dti_buf, &dti->dti_fid);
+ lu_object_put_nocache(env, &root->do_lu);
+ if (rc == -ENOENT) {
+ /* old llog lastid accessed by FID only */
+ if (lastid_seq != FID_SEQ_LLOG)
+ return 0;
+ dti->dti_fid.f_seq = FID_SEQ_LLOG;
+ dti->dti_fid.f_oid = 1;
+ dti->dti_fid.f_ver = 0;
+ o = ls_locate(env, ls, &dti->dti_fid, NULL);
+ if (IS_ERR(o))
+ return PTR_ERR(o);
+
+ if (!dt_object_exists(o)) {
+ lu_object_put_nocache(env, &o->do_lu);
+ return 0;
+ }
+ CDEBUG(D_INFO, "Found old llog lastid file\n");
+ } else if (rc < 0) {
+ return rc;
+ } else {
+ CDEBUG(D_INFO, "Found old lastid file for sequence "LPX64"\n",
+ lastid_seq);
+ o = ls_locate(env, ls, &dti->dti_fid, NULL);
+ if (IS_ERR(o))
+ return PTR_ERR(o);
+ }
+ /* let's read seq-NNNNNN-lastid file value */
+ LASSERT(dt_object_exists(o));
+ dti->dti_off = 0;
+ dti->dti_lb.lb_buf = &losd;
+ dti->dti_lb.lb_len = sizeof(losd);
+ dt_read_lock(env, o, 0);
+ rc = dt_record_read(env, o, &dti->dti_lb, &dti->dti_off);
+ dt_read_unlock(env, o);
+ if (rc == 0 && le32_to_cpu(losd.lso_magic) != LOS_MAGIC) {
+ CERROR("%s: wrong content of seq-"LPX64"-lastid file, magic %x\n",
+ o->do_lu.lo_dev->ld_obd->obd_name, lastid_seq,
+ le32_to_cpu(losd.lso_magic));
+ rc = -EINVAL;
+ } else if (rc < 0) {
+ CERROR("%s: failed to read seq-"LPX64"-lastid: rc = %d\n",
+ o->do_lu.lo_dev->ld_obd->obd_name, lastid_seq, rc);
+ }
+ lu_object_put_nocache(env, &o->do_lu);
+ if (rc == 0)
+ *first_oid = le32_to_cpu(losd.lso_next_oid);
+ return rc;
+}
+