4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2012, 2014, Intel Corporation.
26 * lustre/obdclass/local_storage.c
28 * Local storage for file/objects with fid generation. Works on top of OSD.
30 * Author: Mikhail Pershin <mike.pershin@intel.com>
33 #define DEBUG_SUBSYSTEM S_CLASS
35 #include "local_storage.h"
37 /* all initialized local storages on this node are linked on this */
38 static struct list_head ls_list_head = LIST_HEAD_INIT(ls_list_head);
39 static DEFINE_MUTEX(ls_list_mutex);
41 static int ls_object_init(const struct lu_env *env, struct lu_object *o,
42 const struct lu_object_conf *unused)
45 struct lu_object *below;
46 struct lu_device *under;
50 ls = container_of0(o->lo_dev, struct ls_device, ls_top_dev.dd_lu_dev);
51 under = &ls->ls_osd->dd_lu_dev;
52 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
56 lu_object_add(o, below);
61 static void ls_object_free(const struct lu_env *env, struct lu_object *o)
63 struct ls_object *obj = lu2ls_obj(o);
64 struct lu_object_header *h = o->lo_header;
66 dt_object_fini(&obj->ls_obj);
67 lu_object_header_fini(h);
71 static struct lu_object_operations ls_lu_obj_ops = {
72 .loo_object_init = ls_object_init,
73 .loo_object_free = ls_object_free,
76 static struct lu_object *ls_object_alloc(const struct lu_env *env,
77 const struct lu_object_header *_h,
80 struct lu_object_header *h;
91 lu_object_header_init(h);
92 dt_object_init(&o->ls_obj, h, d);
93 lu_object_add_top(h, l);
95 l->lo_ops = &ls_lu_obj_ops;
103 static struct lu_device_operations ls_lu_dev_ops = {
104 .ldo_object_alloc = ls_object_alloc
107 static struct ls_device *__ls_find_dev(struct dt_device *dev)
109 struct ls_device *ls, *ret = NULL;
111 list_for_each_entry(ls, &ls_list_head, ls_linkage) {
112 if (ls->ls_osd == dev) {
113 atomic_inc(&ls->ls_refcount);
121 struct ls_device *ls_find_dev(struct dt_device *dev)
123 struct ls_device *ls;
125 mutex_lock(&ls_list_mutex);
126 ls = __ls_find_dev(dev);
127 mutex_unlock(&ls_list_mutex);
132 static struct lu_device_type_operations ls_device_type_ops = {
137 static struct lu_device_type ls_lu_type = {
138 .ldt_name = "local_storage",
139 .ldt_ops = &ls_device_type_ops,
142 struct ls_device *ls_device_get(struct dt_device *dev)
144 struct ls_device *ls;
148 mutex_lock(&ls_list_mutex);
149 ls = __ls_find_dev(dev);
153 /* not found, then create */
156 GOTO(out_ls, ls = ERR_PTR(-ENOMEM));
158 atomic_set(&ls->ls_refcount, 1);
159 INIT_LIST_HEAD(&ls->ls_los_list);
160 mutex_init(&ls->ls_los_mutex);
164 LASSERT(dev->dd_lu_dev.ld_site);
165 lu_device_init(&ls->ls_top_dev.dd_lu_dev, &ls_lu_type);
166 ls->ls_top_dev.dd_lu_dev.ld_ops = &ls_lu_dev_ops;
167 ls->ls_top_dev.dd_lu_dev.ld_site = dev->dd_lu_dev.ld_site;
169 /* finally add ls to the list */
170 list_add(&ls->ls_linkage, &ls_list_head);
172 mutex_unlock(&ls_list_mutex);
176 void ls_device_put(const struct lu_env *env, struct ls_device *ls)
179 if (!atomic_dec_and_test(&ls->ls_refcount))
182 mutex_lock(&ls_list_mutex);
183 if (atomic_read(&ls->ls_refcount) == 0) {
184 LASSERT(list_empty(&ls->ls_los_list));
185 list_del(&ls->ls_linkage);
186 lu_site_purge(env, ls->ls_top_dev.dd_lu_dev.ld_site, ~0);
187 lu_device_fini(&ls->ls_top_dev.dd_lu_dev);
190 mutex_unlock(&ls_list_mutex);
194 * local file fid generation
196 int local_object_fid_generate(const struct lu_env *env,
197 struct local_oid_storage *los,
200 LASSERT(los->los_dev);
201 LASSERT(los->los_obj);
205 /* to make it unique after reboot we store
206 * the latest generated fid atomically with
207 * object creation see local_object_create() */
209 mutex_lock(&los->los_id_lock);
210 fid->f_seq = los->los_seq;
211 fid->f_oid = ++los->los_last_oid;
213 mutex_unlock(&los->los_id_lock);
218 int local_object_declare_create(const struct lu_env *env,
219 struct local_oid_storage *los,
220 struct dt_object *o, struct lu_attr *attr,
221 struct dt_object_format *dof,
224 struct dt_thread_info *dti = dt_info(env);
229 /* update fid generation file */
231 LASSERT(dt_object_exists(los->los_obj));
232 dti->dti_lb.lb_buf = NULL;
233 dti->dti_lb.lb_len = sizeof(struct los_ondisk);
234 rc = dt_declare_record_write(env, los->los_obj,
235 &dti->dti_lb, 0, th);
240 rc = dt_declare_create(env, o, attr, NULL, dof, th);
244 dti->dti_lb.lb_buf = NULL;
245 dti->dti_lb.lb_len = sizeof(dti->dti_lma);
246 rc = dt_declare_xattr_set(env, o, &dti->dti_lb, XATTR_NAME_LMA, 0, th);
251 int local_object_create(const struct lu_env *env,
252 struct local_oid_storage *los,
253 struct dt_object *o, struct lu_attr *attr,
254 struct dt_object_format *dof, struct thandle *th)
256 struct dt_thread_info *dti = dt_info(env);
262 rc = dt_create(env, o, attr, NULL, dof, th);
269 LASSERT(los->los_obj);
270 LASSERT(dt_object_exists(los->los_obj));
272 /* many threads can be updated this, serialize
273 * them here to avoid the race where one thread
274 * takes the value first, but writes it last */
275 mutex_lock(&los->los_id_lock);
277 /* update local oid number on disk so that
278 * we know the last one used after reboot */
279 lastid = cpu_to_le64(los->los_last_oid);
282 dti->dti_lb.lb_buf = &lastid;
283 dti->dti_lb.lb_len = sizeof(lastid);
284 rc = dt_record_write(env, los->los_obj, &dti->dti_lb, &dti->dti_off,
286 mutex_unlock(&los->los_id_lock);
292 * Create local named object (file, directory or index) in parent directory.
294 static struct dt_object *__local_file_create(const struct lu_env *env,
295 const struct lu_fid *fid,
296 struct local_oid_storage *los,
297 struct ls_device *ls,
298 struct dt_object *parent,
300 struct lu_attr *attr,
301 struct dt_object_format *dof)
303 struct dt_thread_info *dti = dt_info(env);
304 struct lu_object_conf *conf = &dti->dti_conf;
305 struct dt_insert_rec *rec = &dti->dti_dt_rec;
306 struct dt_object *dto;
310 /* We know that the target object does not exist, to be created,
311 * then give some hints - LOC_F_NEW to help low layer to handle
312 * that efficiently and properly. */
313 memset(conf, 0, sizeof(*conf));
314 conf->loc_flags = LOC_F_NEW;
315 dto = ls_locate(env, ls, fid, conf);
316 if (unlikely(IS_ERR(dto)))
319 LASSERT(dto != NULL);
320 if (dt_object_exists(dto))
321 GOTO(out, rc = -EEXIST);
323 th = dt_trans_create(env, ls->ls_osd);
325 GOTO(out, rc = PTR_ERR(th));
327 rc = local_object_declare_create(env, los, dto, attr, dof, th);
329 GOTO(trans_stop, rc);
331 if (dti->dti_dof.dof_type == DFT_DIR) {
332 rc = dt_declare_ref_add(env, dto, th);
334 GOTO(trans_stop, rc);
336 rc = dt_declare_ref_add(env, parent, th);
338 GOTO(trans_stop, rc);
342 rec->rec_type = dto->do_lu.lo_header->loh_attr;
343 rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
344 (const struct dt_key *)name, th);
346 GOTO(trans_stop, rc);
348 if (dti->dti_dof.dof_type == DFT_DIR) {
349 if (!dt_try_as_dir(env, dto))
350 GOTO(trans_stop, rc = -ENOTDIR);
352 rc = dt_declare_insert(env, dto, (const struct dt_rec *)rec,
353 (const struct dt_key *)".", th);
355 GOTO(trans_stop, rc);
357 rc = dt_declare_insert(env, dto, (const struct dt_rec *)rec,
358 (const struct dt_key *)"..", th);
360 GOTO(trans_stop, rc);
362 rc = dt_declare_ref_add(env, dto, th);
364 GOTO(trans_stop, rc);
367 rc = dt_trans_start_local(env, ls->ls_osd, th);
369 GOTO(trans_stop, rc);
371 dt_write_lock(env, dto, 0);
372 if (dt_object_exists(dto))
373 GOTO(unlock, rc = 0);
375 CDEBUG(D_OTHER, "create new object "DFID"\n",
376 PFID(lu_object_fid(&dto->do_lu)));
377 rc = local_object_create(env, los, dto, attr, dof, th);
380 LASSERT(dt_object_exists(dto));
382 if (dti->dti_dof.dof_type == DFT_DIR) {
384 rec->rec_type = S_IFDIR;
386 /* Add "." and ".." for newly created dir */
387 rc = dt_insert(env, dto, (const struct dt_rec *)rec,
388 (const struct dt_key *)".", th, 1);
392 dt_ref_add(env, dto, th);
393 rec->rec_fid = lu_object_fid(&parent->do_lu);
394 rc = dt_insert(env, dto, (const struct dt_rec *)rec,
395 (const struct dt_key *)"..", th, 1);
401 rec->rec_type = dto->do_lu.lo_header->loh_attr;
402 dt_write_lock(env, parent, 0);
403 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
404 (const struct dt_key *)name, th, 1);
405 if (dti->dti_dof.dof_type == DFT_DIR)
406 dt_ref_add(env, parent, th);
407 dt_write_unlock(env, parent);
412 dt_destroy(env, dto, th);
414 dt_write_unlock(env, dto);
416 dt_trans_stop(env, ls->ls_osd, th);
419 lu_object_put_nocache(env, &dto->do_lu);
426 * Look up and create (if it does not exist) a local named file or directory in
429 struct dt_object *local_file_find_or_create(const struct lu_env *env,
430 struct local_oid_storage *los,
431 struct dt_object *parent,
432 const char *name, __u32 mode)
434 struct dt_thread_info *dti = dt_info(env);
435 struct dt_object *dto;
440 rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
442 /* name is found, get the object */
443 dto = ls_locate(env, dt2ls_dev(los->los_dev),
444 &dti->dti_fid, NULL);
445 else if (rc != -ENOENT)
448 rc = local_object_fid_generate(env, los, &dti->dti_fid);
452 /* create the object */
453 dti->dti_attr.la_valid = LA_MODE;
454 dti->dti_attr.la_mode = mode;
455 dti->dti_dof.dof_type = dt_mode_to_dft(mode & S_IFMT);
456 dto = __local_file_create(env, &dti->dti_fid, los,
457 dt2ls_dev(los->los_dev),
458 parent, name, &dti->dti_attr,
464 EXPORT_SYMBOL(local_file_find_or_create);
466 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
467 struct dt_device *dt,
468 const struct lu_fid *fid,
469 struct dt_object *parent,
473 struct dt_thread_info *dti = dt_info(env);
474 struct dt_object *dto;
479 rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
481 dto = dt_locate(env, dt, &dti->dti_fid);
482 } else if (rc != -ENOENT) {
485 struct ls_device *ls;
487 ls = ls_device_get(dt);
489 dto = ERR_PTR(PTR_ERR(ls));
491 /* create the object */
492 dti->dti_attr.la_valid = LA_MODE;
493 dti->dti_attr.la_mode = mode;
494 dti->dti_dof.dof_type = dt_mode_to_dft(mode & S_IFMT);
495 dto = __local_file_create(env, fid, NULL, ls, parent,
496 name, &dti->dti_attr,
498 /* ls_device_put() will finalize the ls device, we
499 * have to open the object in other device stack */
501 dti->dti_fid = dto->do_lu.lo_header->loh_fid;
502 lu_object_put_nocache(env, &dto->do_lu);
503 dto = dt_locate(env, dt, &dti->dti_fid);
505 ls_device_put(env, ls);
510 EXPORT_SYMBOL(local_file_find_or_create_with_fid);
513 * Look up and create (if it does not exist) a local named index file in parent
516 struct dt_object *local_index_find_or_create(const struct lu_env *env,
517 struct local_oid_storage *los,
518 struct dt_object *parent,
519 const char *name, __u32 mode,
520 const struct dt_index_features *ft)
522 struct dt_thread_info *dti = dt_info(env);
523 struct dt_object *dto;
528 rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
530 /* name is found, get the object */
531 dto = ls_locate(env, dt2ls_dev(los->los_dev),
532 &dti->dti_fid, NULL);
533 } else if (rc != -ENOENT) {
536 rc = local_object_fid_generate(env, los, &dti->dti_fid);
540 /* create the object */
541 dti->dti_attr.la_valid = LA_MODE;
542 dti->dti_attr.la_mode = mode;
543 dti->dti_dof.dof_type = DFT_INDEX;
544 dti->dti_dof.u.dof_idx.di_feat = ft;
545 dto = __local_file_create(env, &dti->dti_fid, los,
546 dt2ls_dev(los->los_dev),
547 parent, name, &dti->dti_attr,
554 EXPORT_SYMBOL(local_index_find_or_create);
557 local_index_find_or_create_with_fid(const struct lu_env *env,
558 struct dt_device *dt,
559 const struct lu_fid *fid,
560 struct dt_object *parent,
561 const char *name, __u32 mode,
562 const struct dt_index_features *ft)
564 struct dt_thread_info *dti = dt_info(env);
565 struct dt_object *dto;
570 rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
572 /* name is found, get the object */
573 if (!lu_fid_eq(fid, &dti->dti_fid))
574 dto = ERR_PTR(-EINVAL);
576 dto = dt_locate(env, dt, fid);
577 } else if (rc != -ENOENT) {
580 struct ls_device *ls;
582 ls = ls_device_get(dt);
584 dto = ERR_PTR(PTR_ERR(ls));
586 /* create the object */
587 dti->dti_attr.la_valid = LA_MODE;
588 dti->dti_attr.la_mode = mode;
589 dti->dti_dof.dof_type = DFT_INDEX;
590 dti->dti_dof.u.dof_idx.di_feat = ft;
591 dto = __local_file_create(env, fid, NULL, ls, parent,
592 name, &dti->dti_attr,
594 /* ls_device_put() will finalize the ls device, we
595 * have to open the object in other device stack */
597 dti->dti_fid = dto->do_lu.lo_header->loh_fid;
598 lu_object_put_nocache(env, &dto->do_lu);
599 dto = dt_locate(env, dt, &dti->dti_fid);
601 ls_device_put(env, ls);
606 EXPORT_SYMBOL(local_index_find_or_create_with_fid);
608 static int local_object_declare_unlink(const struct lu_env *env,
609 struct dt_device *dt,
611 struct dt_object *c, const char *name,
616 rc = dt_declare_delete(env, p, (const struct dt_key *)name, th);
620 rc = dt_declare_ref_del(env, c, th);
624 return dt_declare_destroy(env, c, th);
627 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
628 struct dt_object *parent, const char *name)
630 struct dt_thread_info *dti = dt_info(env);
631 struct dt_object *dto;
637 rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
643 dto = dt_locate(env, dt, &dti->dti_fid);
644 if (unlikely(IS_ERR(dto)))
645 RETURN(PTR_ERR(dto));
647 th = dt_trans_create(env, dt);
649 GOTO(out, rc = PTR_ERR(th));
651 rc = local_object_declare_unlink(env, dt, parent, dto, name, th);
655 rc = dt_trans_start_local(env, dt, th);
659 dt_write_lock(env, dto, 0);
660 rc = dt_delete(env, parent, (struct dt_key *)name, th);
664 rc = dt_ref_del(env, dto, th);
666 struct dt_insert_rec *rec = &dti->dti_dt_rec;
668 rec->rec_fid = &dti->dti_fid;
669 rec->rec_type = dto->do_lu.lo_header->loh_attr;
670 rc = dt_insert(env, parent, (const struct dt_rec *)rec,
671 (const struct dt_key *)name, th, 1);
675 rc = dt_destroy(env, dto, th);
677 dt_write_unlock(env, dto);
679 dt_trans_stop(env, dt, th);
681 lu_object_put_nocache(env, &dto->do_lu);
684 EXPORT_SYMBOL(local_object_unlink);
686 struct local_oid_storage *dt_los_find(struct ls_device *ls, __u64 seq)
688 struct local_oid_storage *los, *ret = NULL;
690 list_for_each_entry(los, &ls->ls_los_list, los_list) {
691 if (los->los_seq == seq) {
692 atomic_inc(&los->los_refcount);
700 void dt_los_put(struct local_oid_storage *los)
702 if (atomic_dec_and_test(&los->los_refcount))
703 /* should never happen, only local_oid_storage_fini should
704 * drop refcount to zero */
709 /* after Lustre 2.3 release there may be old file to store last generated FID
710 * If such file exists then we have to read its content
712 static int lastid_compat_check(const struct lu_env *env, struct dt_device *dev,
713 __u64 lastid_seq, __u32 *first_oid,
714 struct ls_device *ls)
716 struct dt_thread_info *dti = dt_info(env);
717 struct dt_object *root = NULL;
718 struct los_ondisk losd;
719 struct dt_object *o = NULL;
722 rc = dt_root_get(env, dev, &dti->dti_fid);
726 root = ls_locate(env, ls, &dti->dti_fid, NULL);
728 return PTR_ERR(root);
730 /* find old last_id file */
731 snprintf(dti->dti_buf, sizeof(dti->dti_buf), "seq-"LPX64"-lastid",
733 rc = dt_lookup_dir(env, root, dti->dti_buf, &dti->dti_fid);
734 lu_object_put_nocache(env, &root->do_lu);
736 /* old llog lastid accessed by FID only */
737 if (lastid_seq != FID_SEQ_LLOG)
739 dti->dti_fid.f_seq = FID_SEQ_LLOG;
740 dti->dti_fid.f_oid = 1;
741 dti->dti_fid.f_ver = 0;
742 o = ls_locate(env, ls, &dti->dti_fid, NULL);
746 if (!dt_object_exists(o)) {
747 lu_object_put_nocache(env, &o->do_lu);
750 CDEBUG(D_INFO, "Found old llog lastid file\n");
754 CDEBUG(D_INFO, "Found old lastid file for sequence "LPX64"\n",
756 o = ls_locate(env, ls, &dti->dti_fid, NULL);
760 /* let's read seq-NNNNNN-lastid file value */
761 LASSERT(dt_object_exists(o));
763 dti->dti_lb.lb_buf = &losd;
764 dti->dti_lb.lb_len = sizeof(losd);
765 dt_read_lock(env, o, 0);
766 rc = dt_record_read(env, o, &dti->dti_lb, &dti->dti_off);
767 dt_read_unlock(env, o);
768 if (rc == 0 && le32_to_cpu(losd.lso_magic) != LOS_MAGIC) {
769 CERROR("%s: wrong content of seq-"LPX64"-lastid file, magic %x\n",
770 o->do_lu.lo_dev->ld_obd->obd_name, lastid_seq,
771 le32_to_cpu(losd.lso_magic));
774 CERROR("%s: failed to read seq-"LPX64"-lastid: rc = %d\n",
775 o->do_lu.lo_dev->ld_obd->obd_name, lastid_seq, rc);
777 lu_object_put_nocache(env, &o->do_lu);
779 *first_oid = le32_to_cpu(losd.lso_next_oid);
784 * Initialize local OID storage for required sequence.
785 * That may be needed for services that uses local files and requires
786 * dynamic OID allocation for them.
788 * Per each sequence we have an object with 'first_fid' identificator
789 * containing the counter for OIDs of locally created files with that
792 * It is used now by llog subsystem and MGS for NID tables
794 * Function gets first_fid to create counter object.
795 * All dynamic fids will be generated with the same sequence and incremented
798 * Returned local_oid_storage is in-memory representaion of OID storage
800 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
801 const struct lu_fid *first_fid,
802 struct local_oid_storage **los)
804 struct dt_thread_info *dti = dt_info(env);
805 struct ls_device *ls;
807 struct dt_object *o = NULL;
809 __u32 first_oid = fid_oid(first_fid);
814 ls = ls_device_get(dev);
818 mutex_lock(&ls->ls_los_mutex);
819 *los = dt_los_find(ls, fid_seq(first_fid));
823 /* not found, then create */
826 GOTO(out, rc = -ENOMEM);
828 atomic_set(&(*los)->los_refcount, 1);
829 mutex_init(&(*los)->los_id_lock);
830 (*los)->los_dev = &ls->ls_top_dev;
831 atomic_inc(&ls->ls_refcount);
832 list_add(&(*los)->los_list, &ls->ls_los_list);
834 /* Use {seq, 0, 0} to create the LAST_ID file for every
835 * sequence. OIDs start at LUSTRE_FID_INIT_OID.
837 dti->dti_fid.f_seq = fid_seq(first_fid);
838 dti->dti_fid.f_oid = LUSTRE_FID_LASTID_OID;
839 dti->dti_fid.f_ver = 0;
840 o = ls_locate(env, ls, &dti->dti_fid, NULL);
842 GOTO(out_los, rc = PTR_ERR(o));
844 if (!dt_object_exists(o)) {
845 rc = lastid_compat_check(env, dev, fid_seq(first_fid),
850 th = dt_trans_create(env, dev);
852 GOTO(out_los, rc = PTR_ERR(th));
854 dti->dti_attr.la_valid = LA_MODE | LA_TYPE;
855 dti->dti_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
856 dti->dti_dof.dof_type = dt_mode_to_dft(S_IFREG);
858 rc = dt_declare_create(env, o, &dti->dti_attr, NULL,
863 lastid = cpu_to_le64(first_oid);
866 dti->dti_lb.lb_buf = &lastid;
867 dti->dti_lb.lb_len = sizeof(lastid);
868 rc = dt_declare_record_write(env, o, &dti->dti_lb, dti->dti_off,
873 rc = dt_trans_start_local(env, dev, th);
877 dt_write_lock(env, o, 0);
878 if (dt_object_exists(o))
879 GOTO(out_lock, rc = 0);
881 rc = dt_create(env, o, &dti->dti_attr, NULL, &dti->dti_dof,
886 rc = dt_record_write(env, o, &dti->dti_lb, &dti->dti_off, th);
890 dt_write_unlock(env, o);
892 dt_trans_stop(env, dev, th);
895 dti->dti_lb.lb_buf = &lastid;
896 dti->dti_lb.lb_len = sizeof(lastid);
897 dt_read_lock(env, o, 0);
898 rc = dt_record_read(env, o, &dti->dti_lb, &dti->dti_off);
899 dt_read_unlock(env, o);
900 if (rc == 0 && le64_to_cpu(lastid) > OBIF_MAX_OID) {
901 CERROR("%s: bad oid "LPU64" is read from LAST_ID\n",
902 o->do_lu.lo_dev->ld_obd->obd_name,
903 le64_to_cpu(lastid));
909 list_del(&(*los)->los_list);
910 atomic_dec(&ls->ls_refcount);
913 if (o != NULL && !IS_ERR(o))
914 lu_object_put_nocache(env, &o->do_lu);
916 (*los)->los_seq = fid_seq(first_fid);
917 (*los)->los_last_oid = le64_to_cpu(lastid);
919 /* Read value should not be less than initial one
920 * but possible after upgrade from older fs.
921 * In this case just switch to the first_oid in memory and
922 * it will be updated on disk with first object generated */
923 if ((*los)->los_last_oid < first_oid)
924 (*los)->los_last_oid = first_oid;
927 mutex_unlock(&ls->ls_los_mutex);
928 ls_device_put(env, ls);
931 EXPORT_SYMBOL(local_oid_storage_init);
933 void local_oid_storage_fini(const struct lu_env *env,
934 struct local_oid_storage *los)
936 struct ls_device *ls;
939 LASSERT(los->los_dev);
940 ls = dt2ls_dev(los->los_dev);
942 /* Take the mutex before decreasing the reference to avoid race
943 * conditions as described in LU-4721. */
944 mutex_lock(&ls->ls_los_mutex);
945 if (!atomic_dec_and_test(&los->los_refcount)) {
946 mutex_unlock(&ls->ls_los_mutex);
951 lu_object_put_nocache(env, &los->los_obj->do_lu);
952 list_del(&los->los_list);
954 mutex_unlock(&ls->ls_los_mutex);
955 ls_device_put(env, ls);
957 EXPORT_SYMBOL(local_oid_storage_fini);