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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ofd/ofd_dev.c
34 * This file contains OSD API methods for OBD Filter Device (OFD),
35 * request handlers and supplemental functions to set OFD up and clean it up.
37 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
38 * Author: Mike Pershin <mike.pershin@intel.com>
39 * Author: Johann Lombardi <johann.lombardi@intel.com>
42 * The OBD Filter Device (OFD) module belongs to the Object Storage
43 * Server stack and connects the RPC oriented Unified Target (TGT)
44 * layer (see lustre/include/lu_target.h) to the storage oriented OSD
45 * layer (see Documentation/osd-api.txt).
53 * OFD implements the LU and OBD device APIs and is responsible for:
55 * - Handling client requests (create, destroy, bulk IO, setattr,
56 * get_info, set_info, statfs) for the objects belonging to the OST
57 * (together with TGT).
59 * - Providing grant space management which allows clients to reserve
60 * disk space for data writeback. OFD tracks grants on global and
63 * - Handling object precreation requests from MDTs.
65 * - Operating the LDLM service that allows clients to maintain object
66 * data cache coherence.
69 #define DEBUG_SUBSYSTEM S_FILTER
71 #include <obd_class.h>
72 #include <lustre_param.h>
73 #include <lustre_fid.h>
74 #include <lustre_lfsck.h>
75 #include <lustre/lustre_idl.h>
76 #include <lustre_dlm.h>
77 #include <lustre_quota.h>
78 #include <lustre_nodemap.h>
80 #include "ofd_internal.h"
82 /* Slab for OFD object allocation */
83 static struct kmem_cache *ofd_object_kmem;
85 static struct lu_kmem_descr ofd_caches[] = {
87 .ckd_cache = &ofd_object_kmem,
88 .ckd_name = "ofd_obj",
89 .ckd_size = sizeof(struct ofd_object)
97 * Connect OFD to the next device in the stack.
99 * This function is used for device stack configuration and links OFD
100 * device with bottom OSD device.
102 * \param[in] env execution environment
103 * \param[in] m OFD device
104 * \param[in] next name of next device in the stack
105 * \param[out] exp export to return
107 * \retval 0 and export in \a exp if successful
108 * \retval negative value on error
110 static int ofd_connect_to_next(const struct lu_env *env, struct ofd_device *m,
111 const char *next, struct obd_export **exp)
113 struct obd_connect_data *data = NULL;
114 struct obd_device *obd;
120 GOTO(out, rc = -ENOMEM);
122 obd = class_name2obd(next);
124 CERROR("%s: can't locate next device: %s\n",
126 GOTO(out, rc = -ENOTCONN);
129 data->ocd_connect_flags = OBD_CONNECT_VERSION;
130 data->ocd_version = LUSTRE_VERSION_CODE;
132 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
134 CERROR("%s: cannot connect to next dev %s: rc = %d\n",
135 ofd_name(m), next, rc);
139 m->ofd_dt_dev.dd_lu_dev.ld_site =
140 m->ofd_osd_exp->exp_obd->obd_lu_dev->ld_site;
141 LASSERT(m->ofd_dt_dev.dd_lu_dev.ld_site);
142 m->ofd_osd = lu2dt_dev(m->ofd_osd_exp->exp_obd->obd_lu_dev);
143 m->ofd_dt_dev.dd_lu_dev.ld_site->ls_top_dev = &m->ofd_dt_dev.dd_lu_dev;
152 * Initialize stack of devices.
154 * This function initializes OFD-OSD device stack to serve OST requests
156 * \param[in] env execution environment
157 * \param[in] m OFD device
158 * \param[in] cfg Lustre config for this server
160 * \retval 0 if successful
161 * \retval negative value on error
163 static int ofd_stack_init(const struct lu_env *env,
164 struct ofd_device *m, struct lustre_cfg *cfg)
166 const char *dev = lustre_cfg_string(cfg, 0);
168 struct ofd_thread_info *info = ofd_info(env);
169 struct lustre_mount_info *lmi;
170 struct lustre_mount_data *lmd;
176 lmi = server_get_mount(dev);
178 CERROR("Cannot get mount info for %s!\n", dev);
182 lmd = s2lsi(lmi->lmi_sb)->lsi_lmd;
183 if (lmd != NULL && lmd->lmd_flags & LMD_FLG_SKIP_LFSCK)
184 m->ofd_skip_lfsck = 1;
186 /* find bottom osd */
187 OBD_ALLOC(osdname, MTI_NAME_MAXLEN);
191 snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", dev);
192 rc = ofd_connect_to_next(env, m, osdname, &m->ofd_osd_exp);
193 OBD_FREE(osdname, MTI_NAME_MAXLEN);
197 d = m->ofd_osd_exp->exp_obd->obd_lu_dev;
199 m->ofd_osd = lu2dt_dev(d);
201 snprintf(info->fti_u.name, sizeof(info->fti_u.name),
202 "%s-osd", lustre_cfg_string(cfg, 0));
208 * Finalize the device stack OFD-OSD.
210 * This function cleans OFD-OSD device stack and
211 * disconnects OFD from the OSD.
213 * \param[in] env execution environment
214 * \param[in] m OFD device
215 * \param[in] top top device of stack
217 * \retval 0 if successful
218 * \retval negative value on error
220 static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m,
221 struct lu_device *top)
223 struct obd_device *obd = ofd_obd(m);
224 struct lustre_cfg_bufs bufs;
225 struct lustre_cfg *lcfg;
230 lu_site_purge(env, top->ld_site, ~0);
231 /* process cleanup, pass mdt obd name to get obd umount flags */
232 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
237 lustre_cfg_bufs_set_string(&bufs, 1, flags);
238 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
243 top->ld_ops->ldo_process_config(env, top, lcfg);
244 lustre_cfg_free(lcfg);
246 lu_site_purge(env, top->ld_site, ~0);
247 if (!cfs_hash_is_empty(top->ld_site->ls_obj_hash)) {
248 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
249 lu_site_print(env, top->ld_site, &msgdata, lu_cdebug_printer);
252 LASSERT(m->ofd_osd_exp);
253 obd_disconnect(m->ofd_osd_exp);
258 /* For interoperability, see mdt_interop_param[]. */
259 static struct cfg_interop_param ofd_interop_param[] = {
260 { "ost.quota_type", NULL },
265 * Check if parameters are symlinks to the OSD.
267 * Some parameters were moved from ofd to osd and only their
268 * symlinks were kept in ofd by LU-3106. They are:
269 * -writehthrough_cache_enable
270 * -readcache_max_filesize
274 * Since they are not included by the static lprocfs var list, a pre-check
275 * is added for them to avoid "unknown param" errors. If they are matched
276 * in this check, they will be passed to the OSD directly.
278 * \param[in] param parameters to check
280 * \retval true if param is symlink to OSD param
283 static bool match_symlink_param(char *param)
288 if (class_match_param(param, PARAM_OST, ¶m) == 0) {
289 sval = strchr(param, '=');
291 paramlen = sval - param;
292 if (strncmp(param, "writethrough_cache_enable",
294 strncmp(param, "readcache_max_filesize",
296 strncmp(param, "read_cache_enable",
298 strncmp(param, "brw_stats", paramlen) == 0)
307 * Process various configuration parameters.
309 * This function is used by MGS to process specific configurations and
310 * pass them through to the next device in server stack, i.e. the OSD.
312 * \param[in] env execution environment
313 * \param[in] d LU device of OFD
314 * \param[in] cfg parameters to process
316 * \retval 0 if successful
317 * \retval negative value on error
319 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
320 struct lustre_cfg *cfg)
322 struct ofd_device *m = ofd_dev(d);
323 struct dt_device *dt_next = m->ofd_osd;
324 struct lu_device *next = &dt_next->dd_lu_dev;
329 switch (cfg->lcfg_command) {
331 struct obd_device *obd = ofd_obd(m);
332 /* For interoperability */
333 struct cfg_interop_param *ptr = NULL;
334 struct lustre_cfg *old_cfg = NULL;
337 param = lustre_cfg_string(cfg, 1);
339 CERROR("param is empty\n");
344 ptr = class_find_old_param(param, ofd_interop_param);
346 if (ptr->new_param == NULL) {
348 CWARN("For interoperability, skip this %s."
349 " It is obsolete.\n", ptr->old_param);
353 CWARN("Found old param %s, changed it to %s.\n",
354 ptr->old_param, ptr->new_param);
357 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
364 if (match_symlink_param(param)) {
365 rc = next->ld_ops->ldo_process_config(env, next, cfg);
369 rc = class_process_proc_param(PARAM_OST, obd->obd_vars, cfg,
371 if (rc > 0 || rc == -ENOSYS) {
372 CDEBUG(D_CONFIG, "pass param %s down the stack.\n",
374 /* we don't understand; pass it on */
375 rc = next->ld_ops->ldo_process_config(env, next, cfg);
379 case LCFG_SPTLRPC_CONF: {
384 /* others are passed further */
385 rc = next->ld_ops->ldo_process_config(env, next, cfg);
392 * Implementation of lu_object_operations::loo_object_init for OFD
394 * Allocate just the next object (OSD) in stack.
396 * \param[in] env execution environment
397 * \param[in] o lu_object of OFD object
398 * \param[in] conf additional configuration parameters, not used here
400 * \retval 0 if successful
401 * \retval negative value on error
403 static int ofd_object_init(const struct lu_env *env, struct lu_object *o,
404 const struct lu_object_conf *conf)
406 struct ofd_device *d = ofd_dev(o->lo_dev);
407 struct lu_device *under;
408 struct lu_object *below;
413 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
414 PFID(lu_object_fid(o)));
416 under = &d->ofd_osd->dd_lu_dev;
417 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
419 lu_object_add(o, below);
427 * Implementation of lu_object_operations::loo_object_free.
429 * Finish OFD object lifecycle and free its memory.
431 * \param[in] env execution environment
432 * \param[in] o LU object of OFD object
434 static void ofd_object_free(const struct lu_env *env, struct lu_object *o)
436 struct ofd_object *of = ofd_obj(o);
437 struct lu_object_header *h;
442 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
443 PFID(lu_object_fid(o)));
446 lu_object_header_fini(h);
447 OBD_SLAB_FREE_PTR(of, ofd_object_kmem);
452 * Implementation of lu_object_operations::loo_object_print.
454 * Print OFD part of compound OFD-OSD object. See lu_object_print() and
455 * LU_OBJECT_DEBUG() for more details about the compound object printing.
457 * \param[in] env execution environment
458 * \param[in] cookie opaque data passed to the printer function
459 * \param[in] p printer function to use
460 * \param[in] o LU object of OFD object
462 * \retval 0 if successful
463 * \retval negative value on error
465 static int ofd_object_print(const struct lu_env *env, void *cookie,
466 lu_printer_t p, const struct lu_object *o)
468 return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
471 static struct lu_object_operations ofd_obj_ops = {
472 .loo_object_init = ofd_object_init,
473 .loo_object_free = ofd_object_free,
474 .loo_object_print = ofd_object_print
478 * Implementation of lu_device_operations::lod_object_alloc.
480 * This function allocates OFD part of compound OFD-OSD object and
481 * initializes its header, because OFD is the top device in stack
483 * \param[in] env execution environment
484 * \param[in] hdr object header, NULL for OFD
485 * \param[in] d lu_device
487 * \retval allocated object if successful
488 * \retval NULL value on failed allocation
490 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
491 const struct lu_object_header *hdr,
494 struct ofd_object *of;
498 OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, GFP_NOFS);
501 struct lu_object_header *h;
503 o = &of->ofo_obj.do_lu;
505 lu_object_header_init(h);
506 lu_object_init(o, h, d);
507 lu_object_add_top(h, o);
508 o->lo_ops = &ofd_obj_ops;
516 * Return the result of LFSCK run to the OFD.
518 * Notify OFD about result of LFSCK run. That may block the new object
519 * creation until problem is fixed by LFSCK.
521 * \param[in] env execution environment
522 * \param[in] data pointer to the OFD device
523 * \param[in] event LFSCK event type
525 * \retval 0 if successful
526 * \retval negative value on unknown event
528 static int ofd_lfsck_out_notify(const struct lu_env *env, void *data,
529 enum lfsck_events event)
531 struct ofd_device *ofd = data;
532 struct obd_device *obd = ofd_obd(ofd);
535 case LE_LASTID_REBUILDING:
536 CWARN("%s: Found crashed LAST_ID, deny creating new OST-object "
537 "on the device until the LAST_ID rebuilt successfully.\n",
539 down_write(&ofd->ofd_lastid_rwsem);
540 ofd->ofd_lastid_rebuilding = 1;
541 up_write(&ofd->ofd_lastid_rwsem);
543 case LE_LASTID_REBUILT: {
544 down_write(&ofd->ofd_lastid_rwsem);
545 ofd_seqs_free(env, ofd);
546 ofd->ofd_lastid_rebuilding = 0;
547 ofd->ofd_lastid_gen++;
548 up_write(&ofd->ofd_lastid_rwsem);
549 CWARN("%s: Rebuilt crashed LAST_ID files successfully.\n",
554 CERROR("%s: unknown lfsck event: rc = %d\n",
555 ofd_name(ofd), event);
563 * Implementation of lu_device_operations::ldo_prepare.
565 * This method is called after layer has been initialized and before it starts
566 * serving user requests. In OFD it starts lfsk check routines and initializes
569 * \param[in] env execution environment
570 * \param[in] pdev higher device in stack, NULL for OFD
571 * \param[in] dev lu_device of OFD device
573 * \retval 0 if successful
574 * \retval negative value on error
576 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
577 struct lu_device *dev)
579 struct ofd_thread_info *info;
580 struct ofd_device *ofd = ofd_dev(dev);
581 struct obd_device *obd = ofd_obd(ofd);
582 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
587 info = ofd_info_init(env, NULL);
591 /* initialize lower device */
592 rc = next->ld_ops->ldo_prepare(env, dev, next);
596 rc = lfsck_register(env, ofd->ofd_osd, ofd->ofd_osd, obd,
597 ofd_lfsck_out_notify, ofd, false);
599 CERROR("%s: failed to initialize lfsck: rc = %d\n",
604 rc = lfsck_register_namespace(env, ofd->ofd_osd, ofd->ofd_namespace);
605 /* The LFSCK instance is registered just now, so it must be there when
606 * register the namespace to such instance. */
607 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", rc);
609 target_recovery_init(&ofd->ofd_lut, tgt_request_handle);
610 LASSERT(obd->obd_no_conn);
611 spin_lock(&obd->obd_dev_lock);
612 obd->obd_no_conn = 0;
613 spin_unlock(&obd->obd_dev_lock);
615 if (obd->obd_recovering == 0)
616 ofd_postrecov(env, ofd);
622 * Implementation of lu_device_operations::ldo_recovery_complete.
624 * This method notifies all layers about 'recovery complete' event. That means
625 * device is in full state and consistent. An OFD calculates available grant
626 * space upon this event.
628 * \param[in] env execution environment
629 * \param[in] dev lu_device of OFD device
631 * \retval 0 if successful
632 * \retval negative value on error
634 static int ofd_recovery_complete(const struct lu_env *env,
635 struct lu_device *dev)
637 struct ofd_thread_info *oti = ofd_info(env);
638 struct ofd_device *ofd = ofd_dev(dev);
639 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
645 * Grant space for object precreation on the self export.
646 * The initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
647 * is enough to create 10k objects. More space is then acquired for
648 * precreation in ofd_grant_create().
650 memset(&oti->fti_ocd, 0, sizeof(oti->fti_ocd));
651 oti->fti_ocd.ocd_grant = OST_MAX_PRECREATE / 2;
652 oti->fti_ocd.ocd_grant *= ofd->ofd_dt_conf.ddp_inodespace;
653 oti->fti_ocd.ocd_connect_flags = OBD_CONNECT_GRANT |
654 OBD_CONNECT_GRANT_PARAM;
655 ofd_grant_connect(env, dev->ld_obd->obd_self_export, &oti->fti_ocd,
657 rc = next->ld_ops->ldo_recovery_complete(env, next);
662 * lu_device_operations matrix for OFD device.
664 static struct lu_device_operations ofd_lu_ops = {
665 .ldo_object_alloc = ofd_object_alloc,
666 .ldo_process_config = ofd_process_config,
667 .ldo_recovery_complete = ofd_recovery_complete,
668 .ldo_prepare = ofd_prepare,
671 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
674 * Initialize all needed procfs entries for OFD device.
676 * \param[in] ofd OFD device
678 * \retval 0 if successful
679 * \retval negative value on error
681 static int ofd_procfs_init(struct ofd_device *ofd)
683 struct obd_device *obd = ofd_obd(ofd);
684 struct proc_dir_entry *entry;
689 /* lprocfs must be setup before the ofd so state can be safely added
690 * to /proc incrementally as the ofd is setup */
691 obd->obd_vars = lprocfs_ofd_obd_vars;
692 rc = lprocfs_obd_setup(obd);
694 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
699 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
701 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
703 GOTO(obd_cleanup, rc);
706 obd->obd_uses_nid_stats = 1;
708 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
711 CERROR("%s: error %d setting up lprocfs for %s\n",
712 obd->obd_name, rc, "exports");
713 GOTO(obd_cleanup, rc);
715 obd->obd_proc_exports_entry = entry;
717 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
718 obd, &lprocfs_nid_stats_clear_fops);
721 CERROR("%s: add proc entry 'clear' failed: %d.\n",
723 GOTO(obd_cleanup, rc);
726 ofd_stats_counter_init(obd->obd_stats);
728 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
729 ofd_stats_counter_init);
731 GOTO(obd_cleanup, rc);
734 lprocfs_obd_cleanup(obd);
735 lprocfs_free_obd_stats(obd);
741 * Expose OSD statistics to OFD layer.
743 * The osd interfaces to the backend file system exposes useful data
744 * such as brw_stats and read or write cache states. This same data
745 * needs to be exposed into the obdfilter (ofd) layer to maintain
746 * backwards compatibility. This function creates the symlinks in the
747 * proc layer to enable this.
749 * \param[in] ofd OFD device
751 static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd)
753 struct obd_device *obd = ofd_obd(ofd);
754 struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd;
756 if (obd->obd_proc_entry == NULL)
759 lprocfs_add_symlink("brw_stats", obd->obd_proc_entry,
760 "../../%s/%s/brw_stats",
761 osd_obd->obd_type->typ_name, obd->obd_name);
763 lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry,
764 "../../%s/%s/read_cache_enable",
765 osd_obd->obd_type->typ_name, obd->obd_name);
767 lprocfs_add_symlink("readcache_max_filesize",
769 "../../%s/%s/readcache_max_filesize",
770 osd_obd->obd_type->typ_name, obd->obd_name);
772 lprocfs_add_symlink("writethrough_cache_enable",
774 "../../%s/%s/writethrough_cache_enable",
775 osd_obd->obd_type->typ_name, obd->obd_name);
779 * Cleanup all procfs entries in OFD.
781 * \param[in] ofd OFD device
783 static void ofd_procfs_fini(struct ofd_device *ofd)
785 struct obd_device *obd = ofd_obd(ofd);
787 lprocfs_free_per_client_stats(obd);
788 lprocfs_obd_cleanup(obd);
789 lprocfs_free_obd_stats(obd);
790 lprocfs_job_stats_fini(obd);
794 * Stop SEQ/FID server on OFD.
796 * \param[in] env execution environment
797 * \param[in] ofd OFD device
799 * \retval 0 if successful
800 * \retval negative value on error
802 int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd)
804 return seq_site_fini(env, &ofd->ofd_seq_site);
808 * Start SEQ/FID server on OFD.
810 * The SEQ/FID server on OFD is needed to allocate FIDs for new objects.
811 * It also connects to the master server to get own FID sequence (SEQ) range
812 * to this particular OFD. Typically that happens when the OST is first
813 * formatted or in the rare case that it exhausts the local sequence range.
815 * The sequence range is allocated out to the MDTs for OST object allocations,
816 * and not directly to the clients.
818 * \param[in] env execution environment
819 * \param[in] ofd OFD device
821 * \retval 0 if successful
822 * \retval negative value on error
824 int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
826 struct seq_server_site *ss = &ofd->ofd_seq_site;
827 struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev;
828 char *obd_name = ofd_name(ofd);
832 ss = &ofd->ofd_seq_site;
833 lu->ld_site->ld_seq_site = ss;
834 ss->ss_lu = lu->ld_site;
835 ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index;
837 OBD_ALLOC_PTR(ss->ss_server_seq);
838 if (ss->ss_server_seq == NULL)
839 GOTO(out_free, rc = -ENOMEM);
841 OBD_ALLOC(name, strlen(obd_name) + 10);
843 OBD_FREE_PTR(ss->ss_server_seq);
844 ss->ss_server_seq = NULL;
845 GOTO(out_free, rc = -ENOMEM);
848 rc = seq_server_init(env, ss->ss_server_seq, ofd->ofd_osd, obd_name,
849 LUSTRE_SEQ_SERVER, ss);
851 CERROR("%s : seq server init error %d\n", obd_name, rc);
854 ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id;
856 OBD_ALLOC_PTR(ss->ss_client_seq);
857 if (ss->ss_client_seq == NULL)
858 GOTO(out_free, rc = -ENOMEM);
860 snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
861 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
864 CERROR("%s : seq client init error %d\n", obd_name, rc);
867 OBD_FREE(name, strlen(obd_name) + 10);
870 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
874 if (ss->ss_server_seq) {
875 seq_server_fini(ss->ss_server_seq, env);
876 OBD_FREE_PTR(ss->ss_server_seq);
877 ss->ss_server_seq = NULL;
880 if (ss->ss_client_seq) {
881 seq_client_fini(ss->ss_client_seq);
882 OBD_FREE_PTR(ss->ss_client_seq);
883 ss->ss_client_seq = NULL;
887 OBD_FREE(name, strlen(obd_name) + 10);
896 * OFD request handler for OST_SET_INFO RPC.
898 * This is OFD-specific part of request handling
900 * \param[in] tsi target session environment for this request
902 * \retval 0 if successful
903 * \retval negative value on error
905 static int ofd_set_info_hdl(struct tgt_session_info *tsi)
907 struct ptlrpc_request *req = tgt_ses_req(tsi);
908 struct ost_body *body = NULL, *repbody;
909 void *key, *val = NULL;
910 int keylen, vallen, rc = 0;
911 bool is_grant_shrink;
915 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
917 DEBUG_REQ(D_HA, req, "no set_info key");
918 RETURN(err_serious(-EFAULT));
920 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
923 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
925 DEBUG_REQ(D_HA, req, "no set_info val");
926 RETURN(err_serious(-EFAULT));
928 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
931 is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK);
933 /* In this case the value is actually an RMF_OST_BODY, so we
934 * transmutate the type of this PTLRPC */
935 req_capsule_extend(tsi->tsi_pill, &RQF_OST_SET_GRANT_INFO);
937 rc = req_capsule_server_pack(tsi->tsi_pill);
941 if (is_grant_shrink) {
942 body = req_capsule_client_get(tsi->tsi_pill, &RMF_OST_BODY);
944 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
947 /** handle grant shrink, similar to a read request */
948 ofd_grant_prepare_read(tsi->tsi_env, tsi->tsi_exp,
950 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
952 obd_export_evict_by_nid(tsi->tsi_exp->exp_obd, val);
954 } else if (KEY_IS(KEY_SPTLRPC_CONF)) {
955 rc = tgt_adapt_sptlrpc_conf(tsi->tsi_tgt, 0);
957 CERROR("%s: Unsupported key %s\n",
958 tgt_name(tsi->tsi_tgt), (char *)key);
961 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SET_INFO,
968 * Get FIEMAP (FIle Extent MAPping) for object with the given FID.
970 * This function returns a list of extents which describes how a file's
971 * blocks are laid out on the disk.
973 * \param[in] env execution environment
974 * \param[in] ofd OFD device
975 * \param[in] fid FID of object
976 * \param[in] fiemap fiemap structure to fill with data
978 * \retval 0 if \a fiemap is filled with data successfully
979 * \retval negative value on error
981 int ofd_fiemap_get(const struct lu_env *env, struct ofd_device *ofd,
982 struct lu_fid *fid, struct fiemap *fiemap)
984 struct ofd_object *fo;
987 fo = ofd_object_find(env, ofd, fid);
989 CERROR("%s: error finding object "DFID"\n",
990 ofd_name(ofd), PFID(fid));
994 ofd_read_lock(env, fo);
995 if (ofd_object_exists(fo))
996 rc = dt_fiemap_get(env, ofd_object_child(fo), fiemap);
999 ofd_read_unlock(env, fo);
1000 ofd_object_put(env, fo);
1004 struct locked_region {
1005 struct list_head list;
1006 struct lustre_handle lh;
1010 * Lock single extent and save lock handle in the list.
1012 * This is supplemental function for lock_zero_regions(). It allocates
1013 * new locked_region structure and locks it with extent lock, then adds
1014 * it to the list of all such regions.
1016 * \param[in] ns LDLM namespace
1017 * \param[in] res_id resource ID
1018 * \param[in] begin start of region
1019 * \param[in] end end of region
1020 * \param[in] locked list head of regions list
1022 * \retval 0 if successful locking
1023 * \retval negative value on error
1025 static int lock_region(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
1026 unsigned long long begin, unsigned long long end,
1027 struct list_head *locked)
1029 struct locked_region *region = NULL;
1033 LASSERT(begin <= end);
1034 OBD_ALLOC_PTR(region);
1038 rc = tgt_extent_lock(ns, res_id, begin, end, ®ion->lh,
1043 CDEBUG(D_OTHER, "ost lock [%llu,%llu], lh=%p\n", begin, end,
1045 list_add(®ion->list, locked);
1051 * Lock the sparse areas of given resource.
1053 * The locking of sparse areas will cause dirty data to be flushed back from
1054 * clients. This is used when getting the FIEMAP of an object to make sure
1055 * there is no unaccounted cached data on clients.
1057 * This function goes through \a fiemap list of extents and locks only sparse
1058 * areas between extents.
1060 * \param[in] ns LDLM namespace
1061 * \param[in] res_id resource ID
1062 * \param[in] fiemap file extents mapping on disk
1063 * \param[in] locked list head of regions list
1065 * \retval 0 if successful
1066 * \retval negative value on error
1068 static int lock_zero_regions(struct ldlm_namespace *ns,
1069 struct ldlm_res_id *res_id,
1070 struct fiemap *fiemap,
1071 struct list_head *locked)
1073 __u64 begin = fiemap->fm_start;
1076 struct fiemap_extent *fiemap_start = fiemap->fm_extents;
1080 CDEBUG(D_OTHER, "extents count %u\n", fiemap->fm_mapped_extents);
1081 for (i = 0; i < fiemap->fm_mapped_extents; i++) {
1082 if (fiemap_start[i].fe_logical > begin) {
1083 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
1084 begin, fiemap_start[i].fe_logical);
1085 rc = lock_region(ns, res_id, begin,
1086 fiemap_start[i].fe_logical, locked);
1091 begin = fiemap_start[i].fe_logical + fiemap_start[i].fe_length;
1094 if (begin < (fiemap->fm_start + fiemap->fm_length)) {
1095 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
1096 begin, fiemap->fm_start + fiemap->fm_length);
1097 rc = lock_region(ns, res_id, begin,
1098 fiemap->fm_start + fiemap->fm_length, locked);
1105 * Unlock all previously locked sparse areas for given resource.
1107 * This function goes through list of locked regions, unlocking and freeing
1110 * \param[in] ns LDLM namespace
1111 * \param[in] locked list head of regions list
1114 unlock_zero_regions(struct ldlm_namespace *ns, struct list_head *locked)
1116 struct locked_region *entry, *temp;
1118 list_for_each_entry_safe(entry, temp, locked, list) {
1119 CDEBUG(D_OTHER, "ost unlock lh=%p\n", &entry->lh);
1120 tgt_extent_unlock(&entry->lh, LCK_PR);
1121 list_del(&entry->list);
1122 OBD_FREE_PTR(entry);
1127 * OFD request handler for OST_GET_INFO RPC.
1129 * This is OFD-specific part of request handling. The OFD-specific keys are:
1130 * - KEY_LAST_ID (obsolete)
1134 * This function reads needed data from storage and fills reply with it.
1136 * Note: the KEY_LAST_ID is obsolete, replaced by KEY_LAST_FID on newer MDTs,
1137 * and is kept for compatibility.
1139 * \param[in] tsi target session environment for this request
1141 * \retval 0 if successful
1142 * \retval negative value on error
1144 static int ofd_get_info_hdl(struct tgt_session_info *tsi)
1146 struct obd_export *exp = tsi->tsi_exp;
1147 struct ofd_device *ofd = ofd_exp(exp);
1148 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1151 int replylen, rc = 0;
1155 /* this common part for get_info rpc */
1156 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
1158 DEBUG_REQ(D_HA, tgt_ses_req(tsi), "no get_info key");
1159 RETURN(err_serious(-EPROTO));
1161 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
1164 if (KEY_IS(KEY_LAST_ID)) {
1166 struct ofd_seq *oseq;
1168 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_ID);
1169 rc = req_capsule_server_pack(tsi->tsi_pill);
1171 RETURN(err_serious(rc));
1173 last_id = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_ID);
1175 oseq = ofd_seq_load(tsi->tsi_env, ofd,
1176 (u64)exp->exp_filter_data.fed_group);
1180 *last_id = ofd_seq_last_oid(oseq);
1181 ofd_seq_put(tsi->tsi_env, oseq);
1182 } else if (KEY_IS(KEY_FIEMAP)) {
1183 struct ll_fiemap_info_key *fm_key;
1184 struct fiemap *fiemap;
1187 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_FIEMAP);
1189 fm_key = req_capsule_client_get(tsi->tsi_pill, &RMF_FIEMAP_KEY);
1190 rc = tgt_validate_obdo(tsi, &fm_key->lfik_oa);
1192 RETURN(err_serious(rc));
1194 fid = &fm_key->lfik_oa.o_oi.oi_fid;
1196 CDEBUG(D_INODE, "get FIEMAP of object "DFID"\n", PFID(fid));
1198 replylen = fiemap_count_to_size(
1199 fm_key->lfik_fiemap.fm_extent_count);
1200 req_capsule_set_size(tsi->tsi_pill, &RMF_FIEMAP_VAL,
1201 RCL_SERVER, replylen);
1203 rc = req_capsule_server_pack(tsi->tsi_pill);
1205 RETURN(err_serious(rc));
1207 fiemap = req_capsule_server_get(tsi->tsi_pill, &RMF_FIEMAP_VAL);
1211 *fiemap = fm_key->lfik_fiemap;
1212 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid, fiemap);
1214 /* LU-3219: Lock the sparse areas to make sure dirty
1215 * flushed back from client, then call fiemap again. */
1216 if (fm_key->lfik_oa.o_valid & OBD_MD_FLFLAGS &&
1217 fm_key->lfik_oa.o_flags & OBD_FL_SRVLOCK) {
1218 struct list_head locked;
1220 INIT_LIST_HEAD(&locked);
1221 ost_fid_build_resid(fid, &fti->fti_resid);
1222 rc = lock_zero_regions(ofd->ofd_namespace,
1223 &fti->fti_resid, fiemap,
1225 if (rc == 0 && !list_empty(&locked)) {
1226 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid,
1228 unlock_zero_regions(ofd->ofd_namespace,
1232 } else if (KEY_IS(KEY_LAST_FID)) {
1233 struct ofd_device *ofd = ofd_exp(exp);
1234 struct ofd_seq *oseq;
1238 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_FID);
1239 rc = req_capsule_server_pack(tsi->tsi_pill);
1241 RETURN(err_serious(rc));
1243 fid = req_capsule_client_get(tsi->tsi_pill, &RMF_FID);
1245 RETURN(err_serious(-EPROTO));
1247 fid_le_to_cpu(&fti->fti_ostid.oi_fid, fid);
1249 fid = req_capsule_server_get(tsi->tsi_pill, &RMF_FID);
1253 oseq = ofd_seq_load(tsi->tsi_env, ofd,
1254 ostid_seq(&fti->fti_ostid));
1256 RETURN(PTR_ERR(oseq));
1258 rc = ostid_to_fid(fid, &oseq->os_oi,
1259 ofd->ofd_lut.lut_lsd.lsd_osd_index);
1263 CDEBUG(D_HA, "%s: LAST FID is "DFID"\n", ofd_name(ofd),
1266 ofd_seq_put(tsi->tsi_env, oseq);
1268 CERROR("%s: not supported key %s\n", tgt_name(tsi->tsi_tgt),
1272 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GET_INFO,
1279 * OFD request handler for OST_GETATTR RPC.
1281 * This is OFD-specific part of request handling. It finds the OFD object
1282 * by its FID, gets attributes from storage and packs result to the reply.
1284 * \param[in] tsi target session environment for this request
1286 * \retval 0 if successful
1287 * \retval negative value on error
1289 static int ofd_getattr_hdl(struct tgt_session_info *tsi)
1291 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1292 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1293 struct ost_body *repbody;
1294 struct lustre_handle lh = { 0 };
1295 struct ofd_object *fo;
1297 enum ldlm_mode lock_mode = LCK_PR;
1302 LASSERT(tsi->tsi_ost_body != NULL);
1304 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1305 if (repbody == NULL)
1308 repbody->oa.o_oi = tsi->tsi_ost_body->oa.o_oi;
1309 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1311 srvlock = tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
1312 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK;
1315 if (unlikely(tsi->tsi_ost_body->oa.o_flags & OBD_FL_FLUSH))
1318 rc = tgt_extent_lock(tsi->tsi_tgt->lut_obd->obd_namespace,
1319 &tsi->tsi_resid, 0, OBD_OBJECT_EOF, &lh,
1325 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1327 GOTO(out, rc = PTR_ERR(fo));
1329 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1333 obdo_from_la(&repbody->oa, &fti->fti_attr,
1334 OFD_VALID_FLAGS | LA_UID | LA_GID);
1335 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1337 /* Store object version in reply */
1338 curr_version = dt_version_get(tsi->tsi_env,
1339 ofd_object_child(fo));
1340 if ((__s64)curr_version != -EOPNOTSUPP) {
1341 repbody->oa.o_valid |= OBD_MD_FLDATAVERSION;
1342 repbody->oa.o_data_version = curr_version;
1346 ofd_object_put(tsi->tsi_env, fo);
1349 tgt_extent_unlock(&lh, lock_mode);
1351 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GETATTR,
1354 repbody->oa.o_valid |= OBD_MD_FLFLAGS;
1355 repbody->oa.o_flags = OBD_FL_FLUSH;
1361 * OFD request handler for OST_SETATTR RPC.
1363 * This is OFD-specific part of request handling. It finds the OFD object
1364 * by its FID, sets attributes from request and packs result to the reply.
1366 * \param[in] tsi target session environment for this request
1368 * \retval 0 if successful
1369 * \retval negative value on error
1371 static int ofd_setattr_hdl(struct tgt_session_info *tsi)
1373 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1374 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1375 struct ost_body *body = tsi->tsi_ost_body;
1376 struct ost_body *repbody;
1377 struct ldlm_resource *res;
1378 struct ofd_object *fo;
1379 struct filter_fid *ff = NULL;
1384 LASSERT(body != NULL);
1386 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1387 if (repbody == NULL)
1390 repbody->oa.o_oi = body->oa.o_oi;
1391 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1393 /* This would be very bad - accidentally truncating a file when
1394 * changing the time or similar - bug 12203. */
1395 if (body->oa.o_valid & OBD_MD_FLSIZE &&
1396 body->oa.o_size != OBD_OBJECT_EOF) {
1397 static char mdsinum[48];
1399 if (body->oa.o_valid & OBD_MD_FLFID)
1400 snprintf(mdsinum, sizeof(mdsinum) - 1,
1401 "of parent "DFID, body->oa.o_parent_seq,
1402 body->oa.o_parent_oid, 0);
1406 CERROR("%s: setattr from %s is trying to truncate object "DFID
1407 " %s\n", ofd_name(ofd), obd_export_nid2str(tsi->tsi_exp),
1408 PFID(&tsi->tsi_fid), mdsinum);
1412 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1414 GOTO(out, rc = PTR_ERR(fo));
1416 la_from_obdo(&fti->fti_attr, &body->oa, body->oa.o_valid);
1417 fti->fti_attr.la_valid &= ~LA_TYPE;
1419 if (body->oa.o_valid & OBD_MD_FLFID) {
1420 ff = &fti->fti_mds_fid;
1421 ofd_prepare_fidea(ff, &body->oa);
1424 /* setting objects attributes (including owner/group) */
1425 rc = ofd_attr_set(tsi->tsi_env, fo, &fti->fti_attr, ff);
1429 obdo_from_la(&repbody->oa, &fti->fti_attr,
1430 OFD_VALID_FLAGS | LA_UID | LA_GID);
1431 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1433 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SETATTR,
1437 ofd_object_put(tsi->tsi_env, fo);
1440 /* we do not call this before to avoid lu_object_find() in
1441 * ->lvbo_update() holding another reference on the object.
1442 * otherwise concurrent destroy can make the object unavailable
1443 * for 2nd lu_object_find() waiting for the first reference
1444 * to go... deadlock! */
1445 res = ldlm_resource_get(ofd->ofd_namespace, NULL,
1446 &tsi->tsi_resid, LDLM_EXTENT, 0);
1448 ldlm_res_lvbo_update(res, NULL, 0);
1449 ldlm_resource_putref(res);
1456 * Destroy OST orphans.
1458 * This is part of OST_CREATE RPC handling. If there is flag OBD_FL_DELORPHAN
1459 * set then we must destroy possible orphaned objects.
1461 * \param[in] env execution environment
1462 * \param[in] exp OBD export
1463 * \param[in] ofd OFD device
1464 * \param[in] oa obdo structure for reply
1466 * \retval 0 if successful
1467 * \retval negative value on error
1469 static int ofd_orphans_destroy(const struct lu_env *env,
1470 struct obd_export *exp,
1471 struct ofd_device *ofd, struct obdo *oa)
1473 struct ofd_thread_info *info = ofd_info(env);
1474 struct lu_fid *fid = &info->fti_fid;
1475 struct ost_id *oi = &oa->o_oi;
1476 struct ofd_seq *oseq;
1477 u64 seq = ostid_seq(oi);
1478 u64 end_id = ostid_id(oi);
1486 oseq = ofd_seq_get(ofd, seq);
1488 CERROR("%s: Can not find seq for "DOSTID"\n",
1489 ofd_name(ofd), POSTID(oi));
1494 last = ofd_seq_last_oid(oseq);
1497 LASSERT(exp != NULL);
1498 skip_orphan = !!(exp_connect_flags(exp) & OBD_CONNECT_SKIP_ORPHAN);
1500 if (OBD_FAIL_CHECK(OBD_FAIL_OST_NODESTROY))
1503 LCONSOLE(D_INFO, "%s: deleting orphan objects from "DOSTID
1504 " to "DOSTID"\n", ofd_name(ofd), seq, end_id + 1, seq, last);
1506 while (oid > end_id) {
1507 rc = fid_set_id(fid, oid);
1508 if (unlikely(rc != 0))
1511 rc = ofd_destroy_by_fid(env, ofd, fid, 1);
1512 if (rc != 0 && rc != -ENOENT && rc != -ESTALE &&
1513 likely(rc != -EREMCHG && rc != -EINPROGRESS))
1514 /* this is pretty fatal... */
1515 CEMERG("%s: error destroying precreated id "
1517 ofd_name(ofd), PFID(fid), rc);
1521 ofd_seq_last_oid_set(oseq, oid);
1522 /* update last_id on disk periodically so that if we
1523 * restart * we don't need to re-scan all of the just
1524 * deleted objects. */
1525 if ((oid & 511) == 0)
1526 ofd_seq_last_oid_write(env, ofd, oseq);
1530 CDEBUG(D_HA, "%s: after destroy: set last_id to "DOSTID"\n",
1531 ofd_name(ofd), seq, oid);
1535 ofd_seq_last_oid_set(oseq, oid);
1536 rc = ofd_seq_last_oid_write(env, ofd, oseq);
1538 /* don't reuse orphan object, return last used objid */
1539 ostid_set_id(oi, last);
1546 ofd_seq_put(env, oseq);
1551 * OFD request handler for OST_CREATE RPC.
1553 * This is OFD-specific part of request handling. Its main purpose is to
1554 * create new data objects on OST, but it also used to destroy orphans.
1556 * \param[in] tsi target session environment for this request
1558 * \retval 0 if successful
1559 * \retval negative value on error
1561 static int ofd_create_hdl(struct tgt_session_info *tsi)
1563 struct ptlrpc_request *req = tgt_ses_req(tsi);
1564 struct ost_body *repbody;
1565 const struct obdo *oa = &tsi->tsi_ost_body->oa;
1566 struct obdo *rep_oa;
1567 struct obd_export *exp = tsi->tsi_exp;
1568 struct ofd_device *ofd = ofd_exp(exp);
1569 u64 seq = ostid_seq(&oa->o_oi);
1570 u64 oid = ostid_id(&oa->o_oi);
1571 struct ofd_seq *oseq;
1578 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1581 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1582 if (repbody == NULL)
1585 down_read(&ofd->ofd_lastid_rwsem);
1586 /* Currently, for safe, we do not distinguish which LAST_ID is broken,
1587 * we may do that in the future.
1588 * Return -ENOSPC until the LAST_ID rebuilt. */
1589 if (unlikely(ofd->ofd_lastid_rebuilding))
1590 GOTO(out_sem, rc = -ENOSPC);
1592 rep_oa = &repbody->oa;
1593 rep_oa->o_oi = oa->o_oi;
1595 LASSERT(seq >= FID_SEQ_OST_MDT0);
1596 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
1598 CDEBUG(D_INFO, "ofd_create("DOSTID")\n", POSTID(&oa->o_oi));
1600 oseq = ofd_seq_load(tsi->tsi_env, ofd, seq);
1602 CERROR("%s: Can't find FID Sequence "LPX64": rc = %ld\n",
1603 ofd_name(ofd), seq, PTR_ERR(oseq));
1604 GOTO(out_sem, rc = -EINVAL);
1607 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1608 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1609 if (!ofd_obd(ofd)->obd_recovering ||
1610 oid > ofd_seq_last_oid(oseq)) {
1611 CERROR("%s: recreate objid "DOSTID" > last id "LPU64
1612 "\n", ofd_name(ofd), POSTID(&oa->o_oi),
1613 ofd_seq_last_oid(oseq));
1614 GOTO(out_nolock, rc = -EINVAL);
1616 /* Do nothing here, we re-create objects during recovery
1617 * upon write replay, see ofd_preprw_write() */
1618 GOTO(out_nolock, rc = 0);
1620 /* former ofd_handle_precreate */
1621 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1622 (oa->o_flags & OBD_FL_DELORPHAN)) {
1623 exp->exp_filter_data.fed_lastid_gen = ofd->ofd_lastid_gen;
1625 /* destroy orphans */
1626 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1627 exp->exp_conn_cnt) {
1628 CERROR("%s: dropping old orphan cleanup request\n",
1630 GOTO(out_nolock, rc = 0);
1632 /* This causes inflight precreates to abort and drop lock */
1633 oseq->os_destroys_in_progress = 1;
1634 mutex_lock(&oseq->os_create_lock);
1635 if (!oseq->os_destroys_in_progress) {
1636 CERROR("%s:["LPU64"] destroys_in_progress already"
1637 " cleared\n", ofd_name(ofd), seq);
1638 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1641 diff = oid - ofd_seq_last_oid(oseq);
1642 CDEBUG(D_HA, "ofd_last_id() = "LPU64" -> diff = %d\n",
1643 ofd_seq_last_oid(oseq), diff);
1644 if (-diff > OST_MAX_PRECREATE) {
1645 /* Let MDS know that we are so far ahead. */
1646 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq) + 1);
1648 } else if (diff < 0) {
1649 rc = ofd_orphans_destroy(tsi->tsi_env, exp,
1651 oseq->os_destroys_in_progress = 0;
1653 /* XXX: Used by MDS for the first time! */
1654 oseq->os_destroys_in_progress = 0;
1657 if (unlikely(exp->exp_filter_data.fed_lastid_gen !=
1658 ofd->ofd_lastid_gen)) {
1659 /* Keep the export ref so we can send the reply. */
1660 ofd_obd_disconnect(class_export_get(exp));
1661 GOTO(out_nolock, rc = -ENOTCONN);
1664 mutex_lock(&oseq->os_create_lock);
1665 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1666 exp->exp_conn_cnt) {
1667 CERROR("%s: dropping old precreate request\n",
1671 /* only precreate if seq is 0, IDIF or normal and also o_id
1672 * must be specfied */
1673 if ((!fid_seq_is_mdt(seq) && !fid_seq_is_norm(seq) &&
1674 !fid_seq_is_idif(seq)) || oid == 0) {
1675 diff = 1; /* shouldn't we create this right now? */
1677 diff = oid - ofd_seq_last_oid(oseq);
1678 /* Do sync create if the seq is about to used up */
1679 if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) {
1680 if (unlikely(oid >= IDIF_MAX_OID - 1))
1682 } else if (fid_seq_is_norm(seq)) {
1684 LUSTRE_DATA_SEQ_MAX_WIDTH - 1))
1687 CERROR("%s : invalid o_seq "DOSTID"\n",
1688 ofd_name(ofd), POSTID(&oa->o_oi));
1689 GOTO(out, rc = -EINVAL);
1694 CERROR("%s: invalid precreate request for "
1695 DOSTID", last_id " LPU64 ". "
1696 "Likely MDS last_id corruption\n",
1697 ofd_name(ofd), POSTID(&oa->o_oi),
1698 ofd_seq_last_oid(oseq));
1699 GOTO(out, rc = -EINVAL);
1704 cfs_time_t enough_time = cfs_time_shift(DISK_TIMEOUT);
1709 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1710 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1711 /* don't enforce grant during orphan recovery */
1712 granted = ofd_grant_create(tsi->tsi_env,
1713 ofd_obd(ofd)->obd_self_export,
1718 CDEBUG(D_HA, "%s: failed to acquire grant "
1719 "space for precreate (%d): rc = %d\n",
1720 ofd_name(ofd), diff, rc);
1725 /* This can happen if a new OST is formatted and installed
1726 * in place of an old one at the same index. Instead of
1727 * precreating potentially millions of deleted old objects
1728 * (possibly filling the OST), only precreate the last batch.
1729 * LFSCK will eventually clean up any orphans. LU-14 */
1730 if (diff > 5 * OST_MAX_PRECREATE) {
1731 diff = OST_MAX_PRECREATE / 2;
1732 LCONSOLE_WARN("%s: Too many FIDs to precreate "
1733 "OST replaced or reformatted: "
1734 "LFSCK will clean up",
1737 CDEBUG(D_HA, "%s: precreate FID "DOSTID" is over "
1738 "%u larger than the LAST_ID "DOSTID", only "
1739 "precreating the last %u objects.\n",
1740 ofd_name(ofd), POSTID(&oa->o_oi),
1741 5 * OST_MAX_PRECREATE,
1742 POSTID(&oseq->os_oi), diff);
1743 ofd_seq_last_oid_set(oseq, ostid_id(&oa->o_oi) - diff);
1747 next_id = ofd_seq_last_oid(oseq) + 1;
1748 count = ofd_precreate_batch(ofd, diff);
1750 CDEBUG(D_HA, "%s: reserve %d objects in group "LPX64
1751 " at "LPU64"\n", ofd_name(ofd),
1752 count, seq, next_id);
1754 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1755 && cfs_time_after(jiffies, enough_time)) {
1756 CDEBUG(D_HA, "%s: Slow creates, %d/%d objects"
1757 " created at a rate of %d/s\n",
1758 ofd_name(ofd), created, diff + created,
1759 created / DISK_TIMEOUT);
1763 rc = ofd_precreate_objects(tsi->tsi_env, ofd, next_id,
1764 oseq, count, sync_trans);
1768 } else if (rc < 0) {
1774 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1775 LCONSOLE_WARN("%s: can't create the same count of"
1776 " objects when replaying the request"
1777 " (diff is %d). see LU-4621\n",
1778 ofd_name(ofd), diff);
1781 /* some objects got created, we can return
1782 * them, even if last creation failed */
1785 CERROR("%s: unable to precreate: rc = %d\n",
1788 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1789 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1790 ofd_grant_commit(ofd_obd(ofd)->obd_self_export, granted,
1795 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1798 ofd_counter_incr(exp, LPROC_OFD_STATS_CREATE,
1801 mutex_unlock(&oseq->os_create_lock);
1804 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
1805 struct ofd_thread_info *info = ofd_info(tsi->tsi_env);
1806 struct lu_fid *fid = &info->fti_fid;
1808 /* For compatible purpose, it needs to convert back to
1809 * OST ID before put it on wire. */
1810 *fid = rep_oa->o_oi.oi_fid;
1811 fid_to_ostid(fid, &rep_oa->o_oi);
1813 rep_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
1815 ofd_seq_put(tsi->tsi_env, oseq);
1818 up_read(&ofd->ofd_lastid_rwsem);
1823 * OFD request handler for OST_DESTROY RPC.
1825 * This is OFD-specific part of request handling. It destroys data objects
1826 * related to destroyed object on MDT.
1828 * \param[in] tsi target session environment for this request
1830 * \retval 0 if successful
1831 * \retval negative value on error
1833 static int ofd_destroy_hdl(struct tgt_session_info *tsi)
1835 const struct ost_body *body = tsi->tsi_ost_body;
1836 struct ost_body *repbody;
1837 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1838 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1839 struct lu_fid *fid = &fti->fti_fid;
1846 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1849 /* This is old case for clients before Lustre 2.4 */
1850 /* If there's a DLM request, cancel the locks mentioned in it */
1851 if (req_capsule_field_present(tsi->tsi_pill, &RMF_DLM_REQ,
1853 struct ldlm_request *dlm;
1855 dlm = req_capsule_client_get(tsi->tsi_pill, &RMF_DLM_REQ);
1858 ldlm_request_cancel(tgt_ses_req(tsi), dlm, 0, LATF_SKIP);
1861 *fid = body->oa.o_oi.oi_fid;
1862 oid = ostid_id(&body->oa.o_oi);
1865 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1867 /* check that o_misc makes sense */
1868 if (body->oa.o_valid & OBD_MD_FLOBJCOUNT)
1869 count = body->oa.o_misc;
1871 count = 1; /* default case - single destroy */
1873 CDEBUG(D_HA, "%s: Destroy object "DOSTID" count %d\n", ofd_name(ofd),
1874 POSTID(&body->oa.o_oi), count);
1879 lrc = ofd_destroy_by_fid(tsi->tsi_env, ofd, fid, 0);
1880 if (lrc == -ENOENT) {
1882 "%s: destroying non-existent object "DFID"\n",
1883 ofd_name(ofd), PFID(fid));
1884 /* rewrite rc with -ENOENT only if it is 0 */
1887 } else if (lrc != 0) {
1888 CERROR("%s: error destroying object "DFID": %d\n",
1889 ofd_name(ofd), PFID(fid), lrc);
1895 lrc = fid_set_id(fid, oid);
1896 if (unlikely(lrc != 0 && count > 0))
1897 GOTO(out, rc = lrc);
1900 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_DESTROY,
1906 fid_to_ostid(fid, &repbody->oa.o_oi);
1911 * OFD request handler for OST_STATFS RPC.
1913 * This function gets statfs data from storage as part of request
1916 * \param[in] tsi target session environment for this request
1918 * \retval 0 if successful
1919 * \retval negative value on error
1921 static int ofd_statfs_hdl(struct tgt_session_info *tsi)
1923 struct obd_statfs *osfs;
1928 osfs = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_STATFS);
1930 rc = ofd_statfs(tsi->tsi_env, tsi->tsi_exp, osfs,
1931 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 0);
1933 CERROR("%s: statfs failed: rc = %d\n",
1934 tgt_name(tsi->tsi_tgt), rc);
1936 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
1939 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_STATFS,
1946 * OFD request handler for OST_SYNC RPC.
1948 * Sync object data or all filesystem data to the disk and pack the
1951 * \param[in] tsi target session environment for this request
1953 * \retval 0 if successful
1954 * \retval negative value on error
1956 static int ofd_sync_hdl(struct tgt_session_info *tsi)
1958 struct ost_body *body = tsi->tsi_ost_body;
1959 struct ost_body *repbody;
1960 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1961 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1962 struct ofd_object *fo = NULL;
1967 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1969 /* if no objid is specified, it means "sync whole filesystem" */
1970 if (!fid_is_zero(&tsi->tsi_fid)) {
1971 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1973 RETURN(PTR_ERR(fo));
1976 rc = tgt_sync(tsi->tsi_env, tsi->tsi_tgt,
1977 fo != NULL ? ofd_object_child(fo) : NULL,
1978 repbody->oa.o_size, repbody->oa.o_blocks);
1982 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SYNC,
1987 repbody->oa.o_oi = body->oa.o_oi;
1988 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1990 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1992 obdo_from_la(&repbody->oa, &fti->fti_attr,
1995 /* don't return rc from getattr */
2000 ofd_object_put(tsi->tsi_env, fo);
2005 * OFD request handler for OST_PUNCH RPC.
2007 * This is part of request processing. Validate request fields,
2008 * punch (truncate) the given OFD object and pack reply.
2010 * \param[in] tsi target session environment for this request
2012 * \retval 0 if successful
2013 * \retval negative value on error
2015 static int ofd_punch_hdl(struct tgt_session_info *tsi)
2017 const struct obdo *oa = &tsi->tsi_ost_body->oa;
2018 struct ost_body *repbody;
2019 struct ofd_thread_info *info = tsi2ofd_info(tsi);
2020 struct ldlm_namespace *ns = tsi->tsi_tgt->lut_obd->obd_namespace;
2021 struct ldlm_resource *res;
2022 struct ofd_object *fo;
2023 struct filter_fid *ff = NULL;
2025 struct lustre_handle lh = { 0, };
2032 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
2033 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
2035 if ((oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
2036 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
2037 RETURN(err_serious(-EPROTO));
2039 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
2040 if (repbody == NULL)
2041 RETURN(err_serious(-ENOMEM));
2043 /* punch start,end are passed in o_size,o_blocks throught wire */
2047 if (end != OBD_OBJECT_EOF) /* Only truncate is supported */
2050 /* standard truncate optimization: if file body is completely
2051 * destroyed, don't send data back to the server. */
2053 flags |= LDLM_FL_AST_DISCARD_DATA;
2055 repbody->oa.o_oi = oa->o_oi;
2056 repbody->oa.o_valid = OBD_MD_FLID;
2058 srvlock = oa->o_valid & OBD_MD_FLFLAGS &&
2059 oa->o_flags & OBD_FL_SRVLOCK;
2062 rc = tgt_extent_lock(ns, &tsi->tsi_resid, start, end, &lh,
2068 CDEBUG(D_INODE, "calling punch for object "DFID", valid = "LPX64
2069 ", start = "LPD64", end = "LPD64"\n", PFID(&tsi->tsi_fid),
2070 oa->o_valid, start, end);
2072 fo = ofd_object_find_exists(tsi->tsi_env, ofd_exp(tsi->tsi_exp),
2075 GOTO(out, rc = PTR_ERR(fo));
2077 la_from_obdo(&info->fti_attr, oa,
2078 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME);
2079 info->fti_attr.la_size = start;
2080 info->fti_attr.la_valid |= LA_SIZE;
2082 if (oa->o_valid & OBD_MD_FLFID) {
2083 ff = &info->fti_mds_fid;
2084 ofd_prepare_fidea(ff, oa);
2087 rc = ofd_object_punch(tsi->tsi_env, fo, start, end, &info->fti_attr,
2088 ff, (struct obdo *)oa);
2092 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_PUNCH,
2096 ofd_object_put(tsi->tsi_env, fo);
2099 tgt_extent_unlock(&lh, LCK_PW);
2101 /* we do not call this before to avoid lu_object_find() in
2102 * ->lvbo_update() holding another reference on the object.
2103 * otherwise concurrent destroy can make the object unavailable
2104 * for 2nd lu_object_find() waiting for the first reference
2105 * to go... deadlock! */
2106 res = ldlm_resource_get(ns, NULL, &tsi->tsi_resid,
2109 ldlm_res_lvbo_update(res, NULL, 0);
2110 ldlm_resource_putref(res);
2117 * OFD request handler for OST_QUOTACTL RPC.
2119 * This is part of request processing to validate incoming request fields,
2120 * get the requested data from OSD and pack reply.
2122 * \param[in] tsi target session environment for this request
2124 * \retval 0 if successful
2125 * \retval negative value on error
2127 static int ofd_quotactl(struct tgt_session_info *tsi)
2129 struct obd_quotactl *oqctl, *repoqc;
2130 struct lu_nodemap *nodemap =
2131 tsi->tsi_exp->exp_target_data.ted_nodemap;
2137 oqctl = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
2139 RETURN(err_serious(-EPROTO));
2141 repoqc = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
2143 RETURN(err_serious(-ENOMEM));
2148 if (oqctl->qc_type == USRQUOTA)
2149 id = nodemap_map_id(nodemap, NODEMAP_UID,
2150 NODEMAP_CLIENT_TO_FS,
2152 else if (oqctl->qc_type == GRPQUOTA)
2153 id = nodemap_map_id(nodemap, NODEMAP_GID,
2154 NODEMAP_CLIENT_TO_FS,
2157 if (repoqc->qc_id != id)
2158 swap(repoqc->qc_id, id);
2160 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom, repoqc);
2162 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_QUOTACTL,
2165 if (repoqc->qc_id != id)
2166 swap(repoqc->qc_id, id);
2172 * Calculate the amount of time for lock prolongation.
2174 * This is helper for ofd_prolong_extent_locks() function to get
2175 * the timeout extra time.
2177 * \param[in] req current request
2179 * \retval amount of time to extend the timeout with
2181 static inline int prolong_timeout(struct ptlrpc_request *req,
2182 struct ldlm_lock *lock)
2184 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
2187 return obd_timeout / 2;
2189 /* We are in the middle of the process - BL AST is sent, CANCEL
2190 is ahead. Take half of AT + IO process time. */
2191 return at_est2timeout(at_get(&svcpt->scp_at_estimate)) +
2192 (ldlm_bl_timeout(lock) >> 1);
2196 * Prolong single lock timeout.
2198 * This is supplemental function to the ofd_prolong_locks(). It prolongs
2201 * \param[in] tsi target session environment for this request
2202 * \param[in] lock LDLM lock to prolong
2203 * \param[in] extent related extent
2204 * \param[in] timeout timeout value to add
2206 * \retval 0 if lock is not suitable for prolongation
2207 * \retval 1 if lock was prolonged successfully
2209 static int ofd_prolong_one_lock(struct tgt_session_info *tsi,
2210 struct ldlm_lock *lock,
2211 struct ldlm_extent *extent)
2213 int timeout = prolong_timeout(tgt_ses_req(tsi), lock);
2215 if (lock->l_flags & LDLM_FL_DESTROYED) /* lock already cancelled */
2218 /* XXX: never try to grab resource lock here because we're inside
2219 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
2220 * res lock and then exp_bl_list_lock. */
2222 if (!(lock->l_flags & LDLM_FL_AST_SENT))
2223 /* ignore locks not being cancelled */
2226 LDLM_DEBUG(lock, "refreshed for req x"LPU64" ext("LPU64"->"LPU64") "
2227 "to %ds.\n", tgt_ses_req(tsi)->rq_xid, extent->start,
2228 extent->end, timeout);
2230 /* OK. this is a possible lock the user holds doing I/O
2231 * let's refresh eviction timer for it */
2232 ldlm_refresh_waiting_lock(lock, timeout);
2237 * Prolong lock timeout for the given extent.
2239 * This function finds all locks related with incoming request and
2240 * prolongs their timeout.
2242 * If a client is holding a lock for a long time while it sends
2243 * read or write RPCs to the OST for the object under this lock,
2244 * then we don't want the OST to evict the client. Otherwise,
2245 * if the network or disk is very busy then the client may not
2246 * be able to make any progress to clear out dirty pages under
2247 * the lock and the application will fail.
2249 * Every time a Bulk Read/Write (BRW) request arrives for the object
2250 * covered by the lock, extend the timeout on that lock. The RPC should
2251 * contain a lock handle for the lock it is using, but this
2252 * isn't handled correctly by all client versions, and the
2253 * request may cover multiple locks.
2255 * \param[in] tsi target session environment for this request
2256 * \param[in] start start of extent
2257 * \param[in] end end of extent
2259 * \retval number of prolonged locks
2261 static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
2262 __u64 start, __u64 end)
2264 struct obd_export *exp = tsi->tsi_exp;
2265 struct obdo *oa = &tsi->tsi_ost_body->oa;
2266 struct ldlm_extent extent = {
2270 struct ldlm_lock *lock;
2275 if (oa->o_valid & OBD_MD_FLHANDLE) {
2276 /* mostly a request should be covered by only one lock, try
2278 lock = ldlm_handle2lock(&oa->o_handle);
2280 /* Fast path to check if the lock covers the whole IO
2281 * region exclusively. */
2282 if (lock->l_granted_mode == LCK_PW &&
2283 ldlm_extent_contain(&lock->l_policy_data.l_extent,
2286 LASSERT(lock->l_export == exp);
2287 lock_count = ofd_prolong_one_lock(tsi, lock,
2289 LDLM_LOCK_PUT(lock);
2292 lock->l_last_used = cfs_time_current();
2293 LDLM_LOCK_PUT(lock);
2297 spin_lock_bh(&exp->exp_bl_list_lock);
2298 list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
2299 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
2300 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
2302 /* ignore waiting locks, no more granted locks in the list */
2303 if (lock->l_granted_mode != lock->l_req_mode)
2306 if (!ldlm_res_eq(&tsi->tsi_resid, &lock->l_resource->lr_name))
2309 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
2313 lock_count += ofd_prolong_one_lock(tsi, lock, &extent);
2315 spin_unlock_bh(&exp->exp_bl_list_lock);
2321 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_match for OFD RW requests.
2323 * Determine if \a lock and the lock from request \a req are equivalent
2324 * by comparing their resource names, modes, and extents.
2326 * It is used to give priority to read and write RPCs being done
2327 * under this lock so that the client can drop the contended
2328 * lock more quickly and let other clients use it. This improves
2329 * overall performance in the case where the first client gets a
2330 * very large lock extent that prevents other clients from
2331 * submitting their writes.
2333 * \param[in] req ptlrpc_request being processed
2334 * \param[in] lock contended lock to match
2336 * \retval 1 if lock is matched
2337 * \retval 0 otherwise
2339 static int ofd_rw_hpreq_lock_match(struct ptlrpc_request *req,
2340 struct ldlm_lock *lock)
2342 struct niobuf_remote *rnb;
2343 struct obd_ioobj *ioo;
2344 enum ldlm_mode mode;
2345 struct ldlm_extent ext;
2346 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
2350 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
2351 LASSERT(ioo != NULL);
2353 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
2354 LASSERT(rnb != NULL);
2356 ext.start = rnb->rnb_offset;
2357 rnb += ioo->ioo_bufcnt - 1;
2358 ext.end = rnb->rnb_offset + rnb->rnb_len - 1;
2360 LASSERT(lock->l_resource != NULL);
2361 if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name))
2364 /* a bulk write can only hold a reference on a PW extent lock */
2366 if (opc == OST_READ)
2367 /* whereas a bulk read can be protected by either a PR or PW
2371 if (!(lock->l_granted_mode & mode))
2374 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
2378 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_check for OFD RW requests.
2380 * Check for whether the given PTLRPC request (\a req) is blocking
2381 * an LDLM lock cancel.
2383 * \param[in] req the incoming request
2385 * \retval 1 if \a req is blocking an LDLM lock cancel
2386 * \retval 0 if it is not
2388 static int ofd_rw_hpreq_check(struct ptlrpc_request *req)
2390 struct tgt_session_info *tsi;
2391 struct obd_ioobj *ioo;
2392 struct niobuf_remote *rnb;
2398 /* Don't use tgt_ses_info() to get session info, because lock_match()
2399 * can be called while request has no processing thread yet. */
2400 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
2403 * Use LASSERT below because malformed RPCs should have
2404 * been filtered out in tgt_hpreq_handler().
2406 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
2407 LASSERT(ioo != NULL);
2409 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
2410 LASSERT(rnb != NULL);
2411 LASSERT(!(rnb->rnb_flags & OBD_BRW_SRVLOCK));
2413 start = rnb->rnb_offset;
2414 rnb += ioo->ioo_bufcnt - 1;
2415 end = rnb->rnb_offset + rnb->rnb_len - 1;
2417 DEBUG_REQ(D_RPCTRACE, req, "%s %s: refresh rw locks: "DFID
2418 " ("LPU64"->"LPU64")\n",
2419 tgt_name(tsi->tsi_tgt), current->comm,
2420 PFID(&tsi->tsi_fid), start, end);
2422 lock_count = ofd_prolong_extent_locks(tsi, start, end);
2424 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2425 tgt_name(tsi->tsi_tgt), lock_count, req);
2427 RETURN(lock_count > 0);
2431 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_fini for OFD RW requests.
2433 * Called after the request has been handled. It refreshes lock timeout again
2434 * so that client has more time to send lock cancel RPC.
2436 * \param[in] req request which is being processed.
2438 static void ofd_rw_hpreq_fini(struct ptlrpc_request *req)
2440 ofd_rw_hpreq_check(req);
2444 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_match for OST_PUNCH request.
2446 * This function checks if the given lock is the same by its resname, mode
2447 * and extent as one taken from the request.
2448 * It is used to give priority to punch/truncate RPCs that might lead to
2449 * the fastest release of that lock when a lock is contended.
2451 * \param[in] req ptlrpc_request being processed
2452 * \param[in] lock contended lock to match
2454 * \retval 1 if lock is matched
2455 * \retval 0 otherwise
2457 static int ofd_punch_hpreq_lock_match(struct ptlrpc_request *req,
2458 struct ldlm_lock *lock)
2460 struct tgt_session_info *tsi;
2462 /* Don't use tgt_ses_info() to get session info, because lock_match()
2463 * can be called while request has no processing thread yet. */
2464 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
2467 * Use LASSERT below because malformed RPCs should have
2468 * been filtered out in tgt_hpreq_handler().
2470 LASSERT(tsi->tsi_ost_body != NULL);
2471 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLHANDLE &&
2472 tsi->tsi_ost_body->oa.o_handle.cookie == lock->l_handle.h_cookie)
2479 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_check for OST_PUNCH request.
2481 * High-priority queue request check for whether the given punch request
2482 * (\a req) is blocking an LDLM lock cancel.
2484 * \param[in] req the incoming request
2486 * \retval 1 if \a req is blocking an LDLM lock cancel
2487 * \retval 0 if it is not
2489 static int ofd_punch_hpreq_check(struct ptlrpc_request *req)
2491 struct tgt_session_info *tsi;
2497 /* Don't use tgt_ses_info() to get session info, because lock_match()
2498 * can be called while request has no processing thread yet. */
2499 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
2500 LASSERT(tsi != NULL);
2501 oa = &tsi->tsi_ost_body->oa;
2503 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS &&
2504 oa->o_flags & OBD_FL_SRVLOCK));
2507 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
2508 tgt_name(tsi->tsi_tgt), tsi->tsi_resid.name[0],
2509 tsi->tsi_resid.name[1], oa->o_size, oa->o_blocks);
2511 lock_count = ofd_prolong_extent_locks(tsi, oa->o_size, oa->o_blocks);
2513 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2514 tgt_name(tsi->tsi_tgt), lock_count, req);
2516 RETURN(lock_count > 0);
2520 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_fini for OST_PUNCH request.
2522 * Called after the request has been handled. It refreshes lock timeout again
2523 * so that client has more time to send lock cancel RPC.
2525 * \param[in] req request which is being processed.
2527 static void ofd_punch_hpreq_fini(struct ptlrpc_request *req)
2529 ofd_punch_hpreq_check(req);
2532 static struct ptlrpc_hpreq_ops ofd_hpreq_rw = {
2533 .hpreq_lock_match = ofd_rw_hpreq_lock_match,
2534 .hpreq_check = ofd_rw_hpreq_check,
2535 .hpreq_fini = ofd_rw_hpreq_fini
2538 static struct ptlrpc_hpreq_ops ofd_hpreq_punch = {
2539 .hpreq_lock_match = ofd_punch_hpreq_lock_match,
2540 .hpreq_check = ofd_punch_hpreq_check,
2541 .hpreq_fini = ofd_punch_hpreq_fini
2545 * Assign high priority operations to an IO request.
2547 * Check if the incoming request is a candidate for
2548 * high-priority processing. If it is, assign it a high
2549 * priority operations table.
2551 * \param[in] tsi target session environment for this request
2553 static void ofd_hp_brw(struct tgt_session_info *tsi)
2555 struct niobuf_remote *rnb;
2556 struct obd_ioobj *ioo;
2560 ioo = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_IOOBJ);
2561 LASSERT(ioo != NULL); /* must exist after request preprocessing */
2562 if (ioo->ioo_bufcnt > 0) {
2563 rnb = req_capsule_client_get(tsi->tsi_pill, &RMF_NIOBUF_REMOTE);
2564 LASSERT(rnb != NULL); /* must exist after request preprocessing */
2566 /* no high priority if server lock is needed */
2567 if (rnb->rnb_flags & OBD_BRW_SRVLOCK)
2570 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_rw;
2574 * Assign high priority operations to an punch request.
2576 * Check if the incoming request is a candidate for
2577 * high-priority processing. If it is, assign it a high
2578 * priority operations table.
2580 * \param[in] tsi target session environment for this request
2582 static void ofd_hp_punch(struct tgt_session_info *tsi)
2584 LASSERT(tsi->tsi_ost_body != NULL); /* must exists if we are here */
2585 /* no high-priority if server lock is needed */
2586 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
2587 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK)
2589 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_punch;
2592 #define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
2593 #define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
2594 #define OST_BRW_READ OST_READ
2595 #define OST_BRW_WRITE OST_WRITE
2598 * Table of OFD-specific request handlers
2600 * This table contains all opcodes accepted by OFD and
2601 * specifies handlers for them. The tgt_request_handler()
2602 * uses such table from each target to process incoming
2605 static struct tgt_handler ofd_tgt_handlers[] = {
2606 TGT_RPC_HANDLER(OST_FIRST_OPC,
2607 0, OST_CONNECT, tgt_connect,
2608 &RQF_CONNECT, LUSTRE_OBD_VERSION),
2609 TGT_RPC_HANDLER(OST_FIRST_OPC,
2610 0, OST_DISCONNECT, tgt_disconnect,
2611 &RQF_OST_DISCONNECT, LUSTRE_OBD_VERSION),
2612 TGT_RPC_HANDLER(OST_FIRST_OPC,
2613 0, OST_SET_INFO, ofd_set_info_hdl,
2614 &RQF_OBD_SET_INFO, LUSTRE_OST_VERSION),
2615 TGT_OST_HDL(0, OST_GET_INFO, ofd_get_info_hdl),
2616 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_GETATTR, ofd_getattr_hdl),
2617 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2618 OST_SETATTR, ofd_setattr_hdl),
2619 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2620 OST_CREATE, ofd_create_hdl),
2621 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2622 OST_DESTROY, ofd_destroy_hdl),
2623 TGT_OST_HDL(0 | HABEO_REFERO, OST_STATFS, ofd_statfs_hdl),
2624 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO,
2625 OST_BRW_READ, tgt_brw_read,
2627 /* don't set CORPUS flag for brw_write because -ENOENT may be valid case */
2628 TGT_OST_HDL_HP(HABEO_CORPUS| MUTABOR, OST_BRW_WRITE, tgt_brw_write,
2630 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2631 OST_PUNCH, ofd_punch_hdl,
2633 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_SYNC, ofd_sync_hdl),
2634 TGT_OST_HDL(0 | HABEO_REFERO, OST_QUOTACTL, ofd_quotactl),
2637 static struct tgt_opc_slice ofd_common_slice[] = {
2639 .tos_opc_start = OST_FIRST_OPC,
2640 .tos_opc_end = OST_LAST_OPC,
2641 .tos_hs = ofd_tgt_handlers
2644 .tos_opc_start = OBD_FIRST_OPC,
2645 .tos_opc_end = OBD_LAST_OPC,
2646 .tos_hs = tgt_obd_handlers
2649 .tos_opc_start = LDLM_FIRST_OPC,
2650 .tos_opc_end = LDLM_LAST_OPC,
2651 .tos_hs = tgt_dlm_handlers
2654 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
2655 .tos_opc_end = OUT_UPDATE_LAST_OPC,
2656 .tos_hs = tgt_out_handlers
2659 .tos_opc_start = SEQ_FIRST_OPC,
2660 .tos_opc_end = SEQ_LAST_OPC,
2661 .tos_hs = seq_handlers
2664 .tos_opc_start = LFSCK_FIRST_OPC,
2665 .tos_opc_end = LFSCK_LAST_OPC,
2666 .tos_hs = tgt_lfsck_handlers
2669 .tos_opc_start = SEC_FIRST_OPC,
2670 .tos_opc_end = SEC_LAST_OPC,
2671 .tos_hs = tgt_sec_ctx_handlers
2678 /* context key constructor/destructor: ofd_key_init(), ofd_key_fini() */
2679 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
2682 * Implementation of lu_context_key::lct_key_exit.
2684 * Optional method called on lu_context_exit() for all allocated
2686 * It is used in OFD to sanitize context values which may be re-used
2687 * during another request processing by the same thread.
2689 * \param[in] ctx execution context
2690 * \param[in] key context key
2691 * \param[in] data ofd_thread_info
2693 static void ofd_key_exit(const struct lu_context *ctx,
2694 struct lu_context_key *key, void *data)
2696 struct ofd_thread_info *info = data;
2698 info->fti_env = NULL;
2699 info->fti_exp = NULL;
2702 info->fti_pre_version = 0;
2705 memset(&info->fti_attr, 0, sizeof info->fti_attr);
2708 struct lu_context_key ofd_thread_key = {
2709 .lct_tags = LCT_DT_THREAD,
2710 .lct_init = ofd_key_init,
2711 .lct_fini = ofd_key_fini,
2712 .lct_exit = ofd_key_exit
2716 * Initialize OFD device according to parameters in the config log \a cfg.
2718 * This is the main starting point of OFD initialization. It fills all OFD
2719 * parameters with their initial values and calls other initializing functions
2720 * to set up all OFD subsystems.
2722 * \param[in] env execution environment
2723 * \param[in] m OFD device
2724 * \param[in] ldt LU device type of OFD
2725 * \param[in] cfg configuration log
2727 * \retval 0 if successful
2728 * \retval negative value on error
2730 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
2731 struct lu_device_type *ldt, struct lustre_cfg *cfg)
2733 const char *dev = lustre_cfg_string(cfg, 0);
2734 struct ofd_thread_info *info = NULL;
2735 struct obd_device *obd;
2736 struct obd_statfs *osfs;
2741 obd = class_name2obd(dev);
2743 CERROR("Cannot find obd with name %s\n", dev);
2747 rc = lu_env_refill((struct lu_env *)env);
2751 obd->u.obt.obt_magic = OBT_MAGIC;
2753 m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
2754 m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
2756 spin_lock_init(&m->ofd_flags_lock);
2757 m->ofd_raid_degraded = 0;
2758 m->ofd_syncjournal = 0;
2760 m->ofd_grant_compat_disable = 0;
2761 m->ofd_soft_sync_limit = OFD_SOFT_SYNC_LIMIT_DEFAULT;
2764 spin_lock_init(&m->ofd_osfs_lock);
2765 m->ofd_osfs_age = cfs_time_shift_64(-1000);
2766 m->ofd_osfs_unstable = 0;
2767 m->ofd_statfs_inflight = 0;
2768 m->ofd_osfs_inflight = 0;
2771 spin_lock_init(&m->ofd_grant_lock);
2772 m->ofd_tot_dirty = 0;
2773 m->ofd_tot_granted = 0;
2774 m->ofd_tot_pending = 0;
2775 m->ofd_seq_count = 0;
2776 init_waitqueue_head(&m->ofd_inconsistency_thread.t_ctl_waitq);
2777 INIT_LIST_HEAD(&m->ofd_inconsistency_list);
2778 spin_lock_init(&m->ofd_inconsistency_lock);
2780 spin_lock_init(&m->ofd_batch_lock);
2781 init_rwsem(&m->ofd_lastid_rwsem);
2783 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
2784 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
2785 /* set this lu_device to obd, because error handling need it */
2786 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
2788 rc = ofd_procfs_init(m);
2790 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
2794 /* No connection accepted until configurations will finish */
2795 spin_lock(&obd->obd_dev_lock);
2796 obd->obd_no_conn = 1;
2797 spin_unlock(&obd->obd_dev_lock);
2798 obd->obd_replayable = 1;
2799 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
2800 char *str = lustre_cfg_string(cfg, 4);
2802 if (strchr(str, 'n')) {
2803 CWARN("%s: recovery disabled\n", obd->obd_name);
2804 obd->obd_replayable = 0;
2808 info = ofd_info_init(env, NULL);
2810 GOTO(err_fini_proc, rc = -EFAULT);
2812 rc = ofd_stack_init(env, m, cfg);
2814 CERROR("Can't init device stack, rc %d\n", rc);
2815 GOTO(err_fini_proc, rc);
2818 ofd_procfs_add_brw_stats_symlink(m);
2820 /* populate cached statfs data */
2821 osfs = &ofd_info(env)->fti_u.osfs;
2822 rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
2824 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
2825 GOTO(err_fini_stack, rc);
2827 if (!IS_PO2(osfs->os_bsize)) {
2828 CERROR("%s: blocksize (%d) is not a power of 2\n",
2829 obd->obd_name, osfs->os_bsize);
2830 GOTO(err_fini_stack, rc = -EPROTO);
2832 m->ofd_blockbits = fls(osfs->os_bsize) - 1;
2834 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT;
2835 if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS)
2836 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL;
2838 snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s",
2839 "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid);
2840 m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
2841 LDLM_NAMESPACE_SERVER,
2842 LDLM_NAMESPACE_GREEDY,
2844 if (m->ofd_namespace == NULL)
2845 GOTO(err_fini_stack, rc = -ENOMEM);
2846 /* set obd_namespace for compatibility with old code */
2847 obd->obd_namespace = m->ofd_namespace;
2848 ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);
2849 m->ofd_namespace->ns_lvbo = &ofd_lvbo;
2850 m->ofd_namespace->ns_lvbp = m;
2852 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
2853 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
2855 dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
2857 rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
2858 OBD_FAIL_OST_ALL_REQUEST_NET,
2859 OBD_FAIL_OST_ALL_REPLY_NET);
2861 GOTO(err_free_ns, rc);
2863 rc = ofd_fs_setup(env, m, obd);
2865 GOTO(err_fini_lut, rc);
2867 rc = ofd_start_inconsistency_verification_thread(m);
2869 GOTO(err_fini_fs, rc);
2871 tgt_adapt_sptlrpc_conf(&m->ofd_lut, 1);
2876 ofd_fs_cleanup(env, m);
2878 tgt_fini(env, &m->ofd_lut);
2880 ldlm_namespace_free(m->ofd_namespace, NULL, obd->obd_force);
2881 obd->obd_namespace = m->ofd_namespace = NULL;
2883 ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
2890 * Stop the OFD device
2892 * This function stops the OFD device and all its subsystems.
2893 * This is the end of OFD lifecycle.
2895 * \param[in] env execution environment
2896 * \param[in] m OFD device
2898 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
2900 struct obd_device *obd = ofd_obd(m);
2901 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
2902 struct lfsck_stop stop;
2904 stop.ls_status = LS_PAUSED;
2906 lfsck_stop(env, m->ofd_osd, &stop);
2907 target_recovery_fini(obd);
2908 if (m->ofd_namespace != NULL)
2909 ldlm_namespace_free_prior(m->ofd_namespace, NULL,
2910 d->ld_obd->obd_force);
2912 obd_exports_barrier(obd);
2913 obd_zombie_barrier();
2915 tgt_fini(env, &m->ofd_lut);
2916 ofd_stop_inconsistency_verification_thread(m);
2917 lfsck_degister(env, m->ofd_osd);
2918 ofd_fs_cleanup(env, m);
2920 if (m->ofd_namespace != NULL) {
2921 ldlm_namespace_free_post(m->ofd_namespace);
2922 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
2925 ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev);
2927 LASSERT(atomic_read(&d->ld_ref) == 0);
2928 server_put_mount(obd->obd_name, true);
2933 * Implementation of lu_device_type_operations::ldto_device_fini.
2935 * Finalize device. Dual to ofd_device_init(). It is called from
2936 * obd_precleanup() and stops the current device.
2938 * \param[in] env execution environment
2939 * \param[in] d LU device of OFD
2943 static struct lu_device *ofd_device_fini(const struct lu_env *env,
2944 struct lu_device *d)
2947 ofd_fini(env, ofd_dev(d));
2952 * Implementation of lu_device_type_operations::ldto_device_free.
2954 * Free OFD device. Dual to ofd_device_alloc().
2956 * \param[in] env execution environment
2957 * \param[in] d LU device of OFD
2961 static struct lu_device *ofd_device_free(const struct lu_env *env,
2962 struct lu_device *d)
2964 struct ofd_device *m = ofd_dev(d);
2966 dt_device_fini(&m->ofd_dt_dev);
2972 * Implementation of lu_device_type_operations::ldto_device_alloc.
2974 * This function allocates the new OFD device. It is called from
2975 * obd_setup() if OBD device had lu_device_type defined.
2977 * \param[in] env execution environment
2978 * \param[in] t lu_device_type of OFD device
2979 * \param[in] cfg configuration log
2981 * \retval pointer to the lu_device of just allocated OFD
2982 * \retval ERR_PTR of return value on error
2984 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
2985 struct lu_device_type *t,
2986 struct lustre_cfg *cfg)
2988 struct ofd_device *m;
2989 struct lu_device *l;
2994 return ERR_PTR(-ENOMEM);
2996 l = &m->ofd_dt_dev.dd_lu_dev;
2997 dt_device_init(&m->ofd_dt_dev, t);
2998 rc = ofd_init0(env, m, t, cfg);
3000 ofd_device_free(env, l);
3007 /* type constructor/destructor: ofd_type_init(), ofd_type_fini() */
3008 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
3010 static struct lu_device_type_operations ofd_device_type_ops = {
3011 .ldto_init = ofd_type_init,
3012 .ldto_fini = ofd_type_fini,
3014 .ldto_start = ofd_type_start,
3015 .ldto_stop = ofd_type_stop,
3017 .ldto_device_alloc = ofd_device_alloc,
3018 .ldto_device_free = ofd_device_free,
3019 .ldto_device_fini = ofd_device_fini
3022 static struct lu_device_type ofd_device_type = {
3023 .ldt_tags = LU_DEVICE_DT,
3024 .ldt_name = LUSTRE_OST_NAME,
3025 .ldt_ops = &ofd_device_type_ops,
3026 .ldt_ctx_tags = LCT_DT_THREAD
3030 * Initialize OFD module.
3032 * This function is called upon module loading. It registers OFD device type
3033 * and prepares all in-memory structures used by all OFD devices.
3035 * \retval 0 if successful
3036 * \retval negative value on error
3038 static int __init ofd_init(void)
3042 rc = lu_kmem_init(ofd_caches);
3046 rc = ofd_fmd_init();
3048 lu_kmem_fini(ofd_caches);
3052 rc = class_register_type(&ofd_obd_ops, NULL, true, NULL,
3053 LUSTRE_OST_NAME, &ofd_device_type);
3060 * This function is called upon OFD module unloading.
3061 * It frees all related structures and unregisters OFD device type.
3063 static void __exit ofd_exit(void)
3066 lu_kmem_fini(ofd_caches);
3067 class_unregister_type(LUSTRE_OST_NAME);
3070 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3071 MODULE_DESCRIPTION("Lustre Object Filtering Device");
3072 MODULE_VERSION(LUSTRE_VERSION_STRING);
3073 MODULE_LICENSE("GPL");
3075 module_init(ofd_init);
3076 module_exit(ofd_exit);