+static void ofd_seq_destroy(const struct lu_env *env,
+ struct ofd_seq *oseq)
+{
+ LASSERT(cfs_list_empty(&oseq->os_list));
+ LASSERT(oseq->os_lastid_obj != NULL);
+ lu_object_put(env, &oseq->os_lastid_obj->do_lu);
+ OBD_FREE_PTR(oseq);
+}
+
+void ofd_seq_put(const struct lu_env *env, struct ofd_seq *oseq)
+{
+ if (cfs_atomic_dec_and_test(&oseq->os_refc))
+ ofd_seq_destroy(env, oseq);
+}
+
+static void ofd_seq_delete(const struct lu_env *env, struct ofd_seq *oseq)
+{
+ cfs_list_del_init(&oseq->os_list);
+ ofd_seq_put(env, oseq);
+}
+
+/**
+ * Add a new sequence to the OFD device.
+ *
+ * \param ofd OFD device
+ * \param new_seq new sequence to be added
+ *
+ * \retval the seq to be added or the existing seq
+ **/
+static struct ofd_seq *ofd_seq_add(const struct lu_env *env,
+ struct ofd_device *ofd,
+ struct ofd_seq *new_seq)
+{
+ struct ofd_seq *os = NULL;
+
+ write_lock(&ofd->ofd_seq_list_lock);
+ cfs_list_for_each_entry(os, &ofd->ofd_seq_list, os_list) {
+ if (os->os_seq == new_seq->os_seq) {
+ cfs_atomic_inc(&os->os_refc);
+ write_unlock(&ofd->ofd_seq_list_lock);
+ /* The seq has not been added to the list */
+ ofd_seq_put(env, new_seq);
+ return os;
+ }
+ }
+ cfs_atomic_inc(&new_seq->os_refc);
+ cfs_list_add_tail(&new_seq->os_list, &ofd->ofd_seq_list);
+ ofd->ofd_seq_count++;
+ write_unlock(&ofd->ofd_seq_list_lock);
+ return new_seq;
+}
+
+obd_id ofd_seq_last_oid(struct ofd_seq *oseq)
+{
+ obd_id id;