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, 2014 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 lustre/doc/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;
175 lmi = server_get_mount(dev);
177 CERROR("Cannot get mount info for %s!\n", dev);
181 /* find bottom osd */
182 OBD_ALLOC(osdname, MTI_NAME_MAXLEN);
186 snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", dev);
187 rc = ofd_connect_to_next(env, m, osdname, &m->ofd_osd_exp);
188 OBD_FREE(osdname, MTI_NAME_MAXLEN);
192 d = m->ofd_osd_exp->exp_obd->obd_lu_dev;
194 m->ofd_osd = lu2dt_dev(d);
196 snprintf(info->fti_u.name, sizeof(info->fti_u.name),
197 "%s-osd", lustre_cfg_string(cfg, 0));
203 * Finalize the device stack OFD-OSD.
205 * This function cleans OFD-OSD device stack and
206 * disconnects OFD from the OSD.
208 * \param[in] env execution environment
209 * \param[in] m OFD device
210 * \param[in] top top device of stack
212 * \retval 0 if successful
213 * \retval negative value on error
215 static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m,
216 struct lu_device *top)
218 struct obd_device *obd = ofd_obd(m);
219 struct lustre_cfg_bufs bufs;
220 struct lustre_cfg *lcfg;
225 lu_site_purge(env, top->ld_site, ~0);
226 /* process cleanup, pass mdt obd name to get obd umount flags */
227 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
232 lustre_cfg_bufs_set_string(&bufs, 1, flags);
233 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
238 top->ld_ops->ldo_process_config(env, top, lcfg);
239 lustre_cfg_free(lcfg);
241 lu_site_purge(env, top->ld_site, ~0);
242 if (!cfs_hash_is_empty(top->ld_site->ls_obj_hash)) {
243 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
244 lu_site_print(env, top->ld_site, &msgdata, lu_cdebug_printer);
247 LASSERT(m->ofd_osd_exp);
248 obd_disconnect(m->ofd_osd_exp);
253 /* For interoperability, see mdt_interop_param[]. */
254 static struct cfg_interop_param ofd_interop_param[] = {
255 { "ost.quota_type", NULL },
260 * Check if parameters are symlinks to the OSD.
262 * Some parameters were moved from ofd to osd and only their
263 * symlinks were kept in ofd by LU-3106. They are:
264 * -writehthrough_cache_enable
265 * -readcache_max_filesize
269 * Since they are not included by the static lprocfs var list, a pre-check
270 * is added for them to avoid "unknown param" errors. If they are matched
271 * in this check, they will be passed to the OSD directly.
273 * \param[in] param parameters to check
275 * \retval true if param is symlink to OSD param
278 static bool match_symlink_param(char *param)
283 if (class_match_param(param, PARAM_OST, ¶m) == 0) {
284 sval = strchr(param, '=');
286 paramlen = sval - param;
287 if (strncmp(param, "writethrough_cache_enable",
289 strncmp(param, "readcache_max_filesize",
291 strncmp(param, "read_cache_enable",
293 strncmp(param, "brw_stats", paramlen) == 0)
302 * Process various configuration parameters.
304 * This function is used by MGS to process specific configurations and
305 * pass them through to the next device in server stack, i.e. the OSD.
307 * \param[in] env execution environment
308 * \param[in] d LU device of OFD
309 * \param[in] cfg parameters to process
311 * \retval 0 if successful
312 * \retval negative value on error
314 static int ofd_process_config(const struct lu_env *env, struct lu_device *d,
315 struct lustre_cfg *cfg)
317 struct ofd_device *m = ofd_dev(d);
318 struct dt_device *dt_next = m->ofd_osd;
319 struct lu_device *next = &dt_next->dd_lu_dev;
324 switch (cfg->lcfg_command) {
326 struct obd_device *obd = ofd_obd(m);
327 /* For interoperability */
328 struct cfg_interop_param *ptr = NULL;
329 struct lustre_cfg *old_cfg = NULL;
332 param = lustre_cfg_string(cfg, 1);
334 CERROR("param is empty\n");
339 ptr = class_find_old_param(param, ofd_interop_param);
341 if (ptr->new_param == NULL) {
343 CWARN("For interoperability, skip this %s."
344 " It is obsolete.\n", ptr->old_param);
348 CWARN("Found old param %s, changed it to %s.\n",
349 ptr->old_param, ptr->new_param);
352 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
359 if (match_symlink_param(param)) {
360 rc = next->ld_ops->ldo_process_config(env, next, cfg);
364 rc = class_process_proc_param(PARAM_OST, obd->obd_vars, cfg,
366 if (rc > 0 || rc == -ENOSYS) {
367 CDEBUG(D_CONFIG, "pass param %s down the stack.\n",
369 /* we don't understand; pass it on */
370 rc = next->ld_ops->ldo_process_config(env, next, cfg);
374 case LCFG_SPTLRPC_CONF: {
379 /* others are passed further */
380 rc = next->ld_ops->ldo_process_config(env, next, cfg);
387 * Implementation of lu_object_operations::loo_object_init for OFD
389 * Allocate just the next object (OSD) in stack.
391 * \param[in] env execution environment
392 * \param[in] o lu_object of OFD object
393 * \param[in] conf additional configuration parameters, not used here
395 * \retval 0 if successful
396 * \retval negative value on error
398 static int ofd_object_init(const struct lu_env *env, struct lu_object *o,
399 const struct lu_object_conf *conf)
401 struct ofd_device *d = ofd_dev(o->lo_dev);
402 struct lu_device *under;
403 struct lu_object *below;
408 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
409 PFID(lu_object_fid(o)));
411 under = &d->ofd_osd->dd_lu_dev;
412 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
414 lu_object_add(o, below);
422 * Implementation of lu_object_operations::loo_object_free.
424 * Finish OFD object lifecycle and free its memory.
426 * \param[in] env execution environment
427 * \param[in] o LU object of OFD object
429 static void ofd_object_free(const struct lu_env *env, struct lu_object *o)
431 struct ofd_object *of = ofd_obj(o);
432 struct lu_object_header *h;
437 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
438 PFID(lu_object_fid(o)));
441 lu_object_header_fini(h);
442 OBD_SLAB_FREE_PTR(of, ofd_object_kmem);
447 * Implementation of lu_object_operations::loo_object_print.
449 * Print OFD part of compound OFD-OSD object. See lu_object_print() and
450 * LU_OBJECT_DEBUG() for more details about the compound object printing.
452 * \param[in] env execution environment
453 * \param[in] cookie opaque data passed to the printer function
454 * \param[in] p printer function to use
455 * \param[in] o LU object of OFD object
457 * \retval 0 if successful
458 * \retval negative value on error
460 static int ofd_object_print(const struct lu_env *env, void *cookie,
461 lu_printer_t p, const struct lu_object *o)
463 return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
466 static struct lu_object_operations ofd_obj_ops = {
467 .loo_object_init = ofd_object_init,
468 .loo_object_free = ofd_object_free,
469 .loo_object_print = ofd_object_print
473 * Implementation of lu_device_operations::lod_object_alloc.
475 * This function allocates OFD part of compound OFD-OSD object and
476 * initializes its header, because OFD is the top device in stack
478 * \param[in] env execution environment
479 * \param[in] hdr object header, NULL for OFD
480 * \param[in] d lu_device
482 * \retval allocated object if successful
483 * \retval NULL value on failed allocation
485 static struct lu_object *ofd_object_alloc(const struct lu_env *env,
486 const struct lu_object_header *hdr,
489 struct ofd_object *of;
493 OBD_SLAB_ALLOC_PTR_GFP(of, ofd_object_kmem, GFP_NOFS);
496 struct lu_object_header *h;
498 o = &of->ofo_obj.do_lu;
500 lu_object_header_init(h);
501 lu_object_init(o, h, d);
502 lu_object_add_top(h, o);
503 o->lo_ops = &ofd_obj_ops;
511 * Return the result of LFSCK run to the OFD.
513 * Notify OFD about result of LFSCK run. That may block the new object
514 * creation until problem is fixed by LFSCK.
516 * \param[in] env execution environment
517 * \param[in] data pointer to the OFD device
518 * \param[in] event LFSCK event type
520 * \retval 0 if successful
521 * \retval negative value on unknown event
523 static int ofd_lfsck_out_notify(const struct lu_env *env, void *data,
524 enum lfsck_events event)
526 struct ofd_device *ofd = data;
527 struct obd_device *obd = ofd_obd(ofd);
530 case LE_LASTID_REBUILDING:
531 CWARN("%s: Found crashed LAST_ID, deny creating new OST-object "
532 "on the device until the LAST_ID rebuilt successfully.\n",
534 down_write(&ofd->ofd_lastid_rwsem);
535 ofd->ofd_lastid_rebuilding = 1;
536 up_write(&ofd->ofd_lastid_rwsem);
538 case LE_LASTID_REBUILT: {
539 down_write(&ofd->ofd_lastid_rwsem);
540 ofd_seqs_free(env, ofd);
541 ofd->ofd_lastid_rebuilding = 0;
542 ofd->ofd_lastid_gen++;
543 up_write(&ofd->ofd_lastid_rwsem);
544 CWARN("%s: Rebuilt crashed LAST_ID files successfully.\n",
549 CERROR("%s: unknown lfsck event: rc = %d\n",
550 ofd_name(ofd), event);
558 * Implementation of lu_device_operations::ldo_prepare.
560 * This method is called after layer has been initialized and before it starts
561 * serving user requests. In OFD it starts lfsk check routines and initializes
564 * \param[in] env execution environment
565 * \param[in] pdev higher device in stack, NULL for OFD
566 * \param[in] dev lu_device of OFD device
568 * \retval 0 if successful
569 * \retval negative value on error
571 static int ofd_prepare(const struct lu_env *env, struct lu_device *pdev,
572 struct lu_device *dev)
574 struct ofd_thread_info *info;
575 struct ofd_device *ofd = ofd_dev(dev);
576 struct obd_device *obd = ofd_obd(ofd);
577 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
582 info = ofd_info_init(env, NULL);
586 /* initialize lower device */
587 rc = next->ld_ops->ldo_prepare(env, dev, next);
591 rc = lfsck_register(env, ofd->ofd_osd, ofd->ofd_osd, obd,
592 ofd_lfsck_out_notify, ofd, false);
594 CERROR("%s: failed to initialize lfsck: rc = %d\n",
599 rc = lfsck_register_namespace(env, ofd->ofd_osd, ofd->ofd_namespace);
600 /* The LFSCK instance is registered just now, so it must be there when
601 * register the namespace to such instance. */
602 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", rc);
604 target_recovery_init(&ofd->ofd_lut, tgt_request_handle);
605 LASSERT(obd->obd_no_conn);
606 spin_lock(&obd->obd_dev_lock);
607 obd->obd_no_conn = 0;
608 spin_unlock(&obd->obd_dev_lock);
610 if (obd->obd_recovering == 0)
611 ofd_postrecov(env, ofd);
617 * Implementation of lu_device_operations::ldo_recovery_complete.
619 * This method notifies all layers about 'recovery complete' event. That means
620 * device is in full state and consistent. An OFD calculates available grant
621 * space upon this event.
623 * \param[in] env execution environment
624 * \param[in] dev lu_device of OFD device
626 * \retval 0 if successful
627 * \retval negative value on error
629 static int ofd_recovery_complete(const struct lu_env *env,
630 struct lu_device *dev)
632 struct ofd_device *ofd = ofd_dev(dev);
633 struct lu_device *next = &ofd->ofd_osd->dd_lu_dev;
634 int rc = 0, max_precreate;
639 * Grant space for object precreation on the self export.
640 * This initial reserved space (i.e. 10MB for zfs and 280KB for ldiskfs)
641 * is enough to create 10k objects. More space is then acquired for
642 * precreation in ofd_grant_create().
644 max_precreate = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
645 ofd_grant_connect(env, dev->ld_obd->obd_self_export, max_precreate,
647 rc = next->ld_ops->ldo_recovery_complete(env, next);
652 * lu_device_operations matrix for OFD device.
654 static struct lu_device_operations ofd_lu_ops = {
655 .ldo_object_alloc = ofd_object_alloc,
656 .ldo_process_config = ofd_process_config,
657 .ldo_recovery_complete = ofd_recovery_complete,
658 .ldo_prepare = ofd_prepare,
661 LPROC_SEQ_FOPS(lprocfs_nid_stats_clear);
664 * Initialize all needed procfs entries for OFD device.
666 * \param[in] ofd OFD device
668 * \retval 0 if successful
669 * \retval negative value on error
671 static int ofd_procfs_init(struct ofd_device *ofd)
673 struct obd_device *obd = ofd_obd(ofd);
674 struct proc_dir_entry *entry;
679 /* lprocfs must be setup before the ofd so state can be safely added
680 * to /proc incrementally as the ofd is setup */
681 obd->obd_vars = lprocfs_ofd_obd_vars;
682 rc = lprocfs_obd_setup(obd);
684 CERROR("%s: lprocfs_obd_setup failed: %d.\n",
689 rc = lprocfs_alloc_obd_stats(obd, LPROC_OFD_STATS_LAST);
691 CERROR("%s: lprocfs_alloc_obd_stats failed: %d.\n",
693 GOTO(obd_cleanup, rc);
696 obd->obd_uses_nid_stats = 1;
698 entry = lprocfs_register("exports", obd->obd_proc_entry, NULL, NULL);
701 CERROR("%s: error %d setting up lprocfs for %s\n",
702 obd->obd_name, rc, "exports");
703 GOTO(obd_cleanup, rc);
705 obd->obd_proc_exports_entry = entry;
707 entry = lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
708 obd, &lprocfs_nid_stats_clear_fops);
711 CERROR("%s: add proc entry 'clear' failed: %d.\n",
713 GOTO(obd_cleanup, rc);
716 ofd_stats_counter_init(obd->obd_stats);
718 rc = lprocfs_job_stats_init(obd, LPROC_OFD_STATS_LAST,
719 ofd_stats_counter_init);
721 GOTO(obd_cleanup, rc);
724 lprocfs_obd_cleanup(obd);
725 lprocfs_free_obd_stats(obd);
731 * Expose OSD statistics to OFD layer.
733 * The osd interfaces to the backend file system exposes useful data
734 * such as brw_stats and read or write cache states. This same data
735 * needs to be exposed into the obdfilter (ofd) layer to maintain
736 * backwards compatibility. This function creates the symlinks in the
737 * proc layer to enable this.
739 * \param[in] ofd OFD device
741 static void ofd_procfs_add_brw_stats_symlink(struct ofd_device *ofd)
743 struct obd_device *obd = ofd_obd(ofd);
744 struct obd_device *osd_obd = ofd->ofd_osd_exp->exp_obd;
746 if (obd->obd_proc_entry == NULL)
749 lprocfs_add_symlink("brw_stats", obd->obd_proc_entry,
750 "../../%s/%s/brw_stats",
751 osd_obd->obd_type->typ_name, obd->obd_name);
753 lprocfs_add_symlink("read_cache_enable", obd->obd_proc_entry,
754 "../../%s/%s/read_cache_enable",
755 osd_obd->obd_type->typ_name, obd->obd_name);
757 lprocfs_add_symlink("readcache_max_filesize",
759 "../../%s/%s/readcache_max_filesize",
760 osd_obd->obd_type->typ_name, obd->obd_name);
762 lprocfs_add_symlink("writethrough_cache_enable",
764 "../../%s/%s/writethrough_cache_enable",
765 osd_obd->obd_type->typ_name, obd->obd_name);
769 * Cleanup all procfs entries in OFD.
771 * \param[in] ofd OFD device
773 static void ofd_procfs_fini(struct ofd_device *ofd)
775 struct obd_device *obd = ofd_obd(ofd);
777 lprocfs_free_per_client_stats(obd);
778 lprocfs_obd_cleanup(obd);
779 lprocfs_free_obd_stats(obd);
780 lprocfs_job_stats_fini(obd);
784 * Stop SEQ/FID server on OFD.
786 * \param[in] env execution environment
787 * \param[in] ofd OFD device
789 * \retval 0 if successful
790 * \retval negative value on error
792 int ofd_fid_fini(const struct lu_env *env, struct ofd_device *ofd)
794 return seq_site_fini(env, &ofd->ofd_seq_site);
798 * Start SEQ/FID server on OFD.
800 * The SEQ/FID server on OFD is needed to allocate FIDs for new objects.
801 * It also connects to the master server to get own FID sequence (SEQ) range
802 * to this particular OFD. Typically that happens when the OST is first
803 * formatted or in the rare case that it exhausts the local sequence range.
805 * The sequence range is allocated out to the MDTs for OST object allocations,
806 * and not directly to the clients.
808 * \param[in] env execution environment
809 * \param[in] ofd OFD device
811 * \retval 0 if successful
812 * \retval negative value on error
814 int ofd_fid_init(const struct lu_env *env, struct ofd_device *ofd)
816 struct seq_server_site *ss = &ofd->ofd_seq_site;
817 struct lu_device *lu = &ofd->ofd_dt_dev.dd_lu_dev;
818 char *obd_name = ofd_name(ofd);
822 ss = &ofd->ofd_seq_site;
823 lu->ld_site->ld_seq_site = ss;
824 ss->ss_lu = lu->ld_site;
825 ss->ss_node_id = ofd->ofd_lut.lut_lsd.lsd_osd_index;
827 OBD_ALLOC_PTR(ss->ss_server_seq);
828 if (ss->ss_server_seq == NULL)
829 GOTO(out_free, rc = -ENOMEM);
831 OBD_ALLOC(name, strlen(obd_name) + 10);
833 OBD_FREE_PTR(ss->ss_server_seq);
834 ss->ss_server_seq = NULL;
835 GOTO(out_free, rc = -ENOMEM);
838 rc = seq_server_init(env, ss->ss_server_seq, ofd->ofd_osd, obd_name,
839 LUSTRE_SEQ_SERVER, ss);
841 CERROR("%s : seq server init error %d\n", obd_name, rc);
844 ss->ss_server_seq->lss_space.lsr_index = ss->ss_node_id;
846 OBD_ALLOC_PTR(ss->ss_client_seq);
847 if (ss->ss_client_seq == NULL)
848 GOTO(out_free, rc = -ENOMEM);
850 snprintf(name, strlen(obd_name) + 6, "%p-super", obd_name);
851 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_DATA,
854 CERROR("%s : seq client init error %d\n", obd_name, rc);
857 OBD_FREE(name, strlen(obd_name) + 10);
860 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
864 if (ss->ss_server_seq) {
865 seq_server_fini(ss->ss_server_seq, env);
866 OBD_FREE_PTR(ss->ss_server_seq);
867 ss->ss_server_seq = NULL;
870 if (ss->ss_client_seq) {
871 seq_client_fini(ss->ss_client_seq);
872 OBD_FREE_PTR(ss->ss_client_seq);
873 ss->ss_client_seq = NULL;
877 OBD_FREE(name, strlen(obd_name) + 10);
886 * OFD request handler for OST_SET_INFO RPC.
888 * This is OFD-specific part of request handling
890 * \param[in] tsi target session environment for this request
892 * \retval 0 if successful
893 * \retval negative value on error
895 static int ofd_set_info_hdl(struct tgt_session_info *tsi)
897 struct ptlrpc_request *req = tgt_ses_req(tsi);
898 struct ost_body *body = NULL, *repbody;
899 void *key, *val = NULL;
900 int keylen, vallen, rc = 0;
901 bool is_grant_shrink;
905 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
907 DEBUG_REQ(D_HA, req, "no set_info key");
908 RETURN(err_serious(-EFAULT));
910 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
913 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
915 DEBUG_REQ(D_HA, req, "no set_info val");
916 RETURN(err_serious(-EFAULT));
918 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
921 is_grant_shrink = KEY_IS(KEY_GRANT_SHRINK);
923 /* In this case the value is actually an RMF_OST_BODY, so we
924 * transmutate the type of this PTLRPC */
925 req_capsule_extend(tsi->tsi_pill, &RQF_OST_SET_GRANT_INFO);
927 rc = req_capsule_server_pack(tsi->tsi_pill);
931 if (is_grant_shrink) {
932 body = req_capsule_client_get(tsi->tsi_pill, &RMF_OST_BODY);
934 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
937 /** handle grant shrink, similar to a read request */
938 ofd_grant_prepare_read(tsi->tsi_env, tsi->tsi_exp,
940 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
942 obd_export_evict_by_nid(tsi->tsi_exp->exp_obd, val);
944 } else if (KEY_IS(KEY_SPTLRPC_CONF)) {
945 rc = tgt_adapt_sptlrpc_conf(tsi->tsi_tgt, 0);
947 CERROR("%s: Unsupported key %s\n",
948 tgt_name(tsi->tsi_tgt), (char *)key);
951 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SET_INFO,
958 * Get FIEMAP (FIle Extent MAPping) for object with the given FID.
960 * This function returns a list of extents which describes how a file's
961 * blocks are laid out on the disk.
963 * \param[in] env execution environment
964 * \param[in] ofd OFD device
965 * \param[in] fid FID of object
966 * \param[in] fiemap fiemap structure to fill with data
968 * \retval 0 if \a fiemap is filled with data successfully
969 * \retval negative value on error
971 int ofd_fiemap_get(const struct lu_env *env, struct ofd_device *ofd,
972 struct lu_fid *fid, struct fiemap *fiemap)
974 struct ofd_object *fo;
977 fo = ofd_object_find(env, ofd, fid);
979 CERROR("%s: error finding object "DFID"\n",
980 ofd_name(ofd), PFID(fid));
984 ofd_read_lock(env, fo);
985 if (ofd_object_exists(fo))
986 rc = dt_fiemap_get(env, ofd_object_child(fo), fiemap);
989 ofd_read_unlock(env, fo);
990 ofd_object_put(env, fo);
994 struct locked_region {
995 struct list_head list;
996 struct lustre_handle lh;
1000 * Lock single extent and save lock handle in the list.
1002 * This is supplemental function for lock_zero_regions(). It allocates
1003 * new locked_region structure and locks it with extent lock, then adds
1004 * it to the list of all such regions.
1006 * \param[in] ns LDLM namespace
1007 * \param[in] res_id resource ID
1008 * \param[in] begin start of region
1009 * \param[in] end end of region
1010 * \param[in] locked list head of regions list
1012 * \retval 0 if successful locking
1013 * \retval negative value on error
1015 static int lock_region(struct ldlm_namespace *ns, struct ldlm_res_id *res_id,
1016 unsigned long long begin, unsigned long long end,
1017 struct list_head *locked)
1019 struct locked_region *region = NULL;
1023 LASSERT(begin <= end);
1024 OBD_ALLOC_PTR(region);
1028 rc = tgt_extent_lock(ns, res_id, begin, end, ®ion->lh,
1033 CDEBUG(D_OTHER, "ost lock [%llu,%llu], lh=%p\n", begin, end,
1035 list_add(®ion->list, locked);
1041 * Lock the sparse areas of given resource.
1043 * The locking of sparse areas will cause dirty data to be flushed back from
1044 * clients. This is used when getting the FIEMAP of an object to make sure
1045 * there is no unaccounted cached data on clients.
1047 * This function goes through \a fiemap list of extents and locks only sparse
1048 * areas between extents.
1050 * \param[in] ns LDLM namespace
1051 * \param[in] res_id resource ID
1052 * \param[in] fiemap file extents mapping on disk
1053 * \param[in] locked list head of regions list
1055 * \retval 0 if successful
1056 * \retval negative value on error
1058 static int lock_zero_regions(struct ldlm_namespace *ns,
1059 struct ldlm_res_id *res_id,
1060 struct fiemap *fiemap,
1061 struct list_head *locked)
1063 __u64 begin = fiemap->fm_start;
1066 struct fiemap_extent *fiemap_start = fiemap->fm_extents;
1070 CDEBUG(D_OTHER, "extents count %u\n", fiemap->fm_mapped_extents);
1071 for (i = 0; i < fiemap->fm_mapped_extents; i++) {
1072 if (fiemap_start[i].fe_logical > begin) {
1073 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
1074 begin, fiemap_start[i].fe_logical);
1075 rc = lock_region(ns, res_id, begin,
1076 fiemap_start[i].fe_logical, locked);
1081 begin = fiemap_start[i].fe_logical + fiemap_start[i].fe_length;
1084 if (begin < (fiemap->fm_start + fiemap->fm_length)) {
1085 CDEBUG(D_OTHER, "ost lock [%llu,%llu]\n",
1086 begin, fiemap->fm_start + fiemap->fm_length);
1087 rc = lock_region(ns, res_id, begin,
1088 fiemap->fm_start + fiemap->fm_length, locked);
1095 * Unlock all previously locked sparse areas for given resource.
1097 * This function goes through list of locked regions, unlocking and freeing
1100 * \param[in] ns LDLM namespace
1101 * \param[in] locked list head of regions list
1104 unlock_zero_regions(struct ldlm_namespace *ns, struct list_head *locked)
1106 struct locked_region *entry, *temp;
1108 list_for_each_entry_safe(entry, temp, locked, list) {
1109 CDEBUG(D_OTHER, "ost unlock lh=%p\n", &entry->lh);
1110 tgt_extent_unlock(&entry->lh, LCK_PR);
1111 list_del(&entry->list);
1112 OBD_FREE_PTR(entry);
1117 * OFD request handler for OST_GET_INFO RPC.
1119 * This is OFD-specific part of request handling. The OFD-specific keys are:
1120 * - KEY_LAST_ID (obsolete)
1124 * This function reads needed data from storage and fills reply with it.
1126 * Note: the KEY_LAST_ID is obsolete, replaced by KEY_LAST_FID on newer MDTs,
1127 * and is kept for compatibility.
1129 * \param[in] tsi target session environment for this request
1131 * \retval 0 if successful
1132 * \retval negative value on error
1134 static int ofd_get_info_hdl(struct tgt_session_info *tsi)
1136 struct obd_export *exp = tsi->tsi_exp;
1137 struct ofd_device *ofd = ofd_exp(exp);
1138 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1141 int replylen, rc = 0;
1145 /* this common part for get_info rpc */
1146 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
1148 DEBUG_REQ(D_HA, tgt_ses_req(tsi), "no get_info key");
1149 RETURN(err_serious(-EPROTO));
1151 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
1154 if (KEY_IS(KEY_LAST_ID)) {
1156 struct ofd_seq *oseq;
1158 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_ID);
1159 rc = req_capsule_server_pack(tsi->tsi_pill);
1161 RETURN(err_serious(rc));
1163 last_id = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_ID);
1165 oseq = ofd_seq_load(tsi->tsi_env, ofd,
1166 (u64)exp->exp_filter_data.fed_group);
1170 *last_id = ofd_seq_last_oid(oseq);
1171 ofd_seq_put(tsi->tsi_env, oseq);
1172 } else if (KEY_IS(KEY_FIEMAP)) {
1173 struct ll_fiemap_info_key *fm_key;
1174 struct fiemap *fiemap;
1177 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_FIEMAP);
1179 fm_key = req_capsule_client_get(tsi->tsi_pill, &RMF_FIEMAP_KEY);
1180 rc = tgt_validate_obdo(tsi, &fm_key->lfik_oa);
1182 RETURN(err_serious(rc));
1184 fid = &fm_key->lfik_oa.o_oi.oi_fid;
1186 CDEBUG(D_INODE, "get FIEMAP of object "DFID"\n", PFID(fid));
1188 replylen = fiemap_count_to_size(
1189 fm_key->lfik_fiemap.fm_extent_count);
1190 req_capsule_set_size(tsi->tsi_pill, &RMF_FIEMAP_VAL,
1191 RCL_SERVER, replylen);
1193 rc = req_capsule_server_pack(tsi->tsi_pill);
1195 RETURN(err_serious(rc));
1197 fiemap = req_capsule_server_get(tsi->tsi_pill, &RMF_FIEMAP_VAL);
1201 *fiemap = fm_key->lfik_fiemap;
1202 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid, fiemap);
1204 /* LU-3219: Lock the sparse areas to make sure dirty
1205 * flushed back from client, then call fiemap again. */
1206 if (fm_key->lfik_oa.o_valid & OBD_MD_FLFLAGS &&
1207 fm_key->lfik_oa.o_flags & OBD_FL_SRVLOCK) {
1208 struct list_head locked;
1210 INIT_LIST_HEAD(&locked);
1211 ost_fid_build_resid(fid, &fti->fti_resid);
1212 rc = lock_zero_regions(ofd->ofd_namespace,
1213 &fti->fti_resid, fiemap,
1215 if (rc == 0 && !list_empty(&locked)) {
1216 rc = ofd_fiemap_get(tsi->tsi_env, ofd, fid,
1218 unlock_zero_regions(ofd->ofd_namespace,
1222 } else if (KEY_IS(KEY_LAST_FID)) {
1223 struct ofd_device *ofd = ofd_exp(exp);
1224 struct ofd_seq *oseq;
1228 req_capsule_extend(tsi->tsi_pill, &RQF_OST_GET_INFO_LAST_FID);
1229 rc = req_capsule_server_pack(tsi->tsi_pill);
1231 RETURN(err_serious(rc));
1233 fid = req_capsule_client_get(tsi->tsi_pill, &RMF_FID);
1235 RETURN(err_serious(-EPROTO));
1237 fid_le_to_cpu(&fti->fti_ostid.oi_fid, fid);
1239 fid = req_capsule_server_get(tsi->tsi_pill, &RMF_FID);
1243 oseq = ofd_seq_load(tsi->tsi_env, ofd,
1244 ostid_seq(&fti->fti_ostid));
1246 RETURN(PTR_ERR(oseq));
1248 rc = ostid_to_fid(fid, &oseq->os_oi,
1249 ofd->ofd_lut.lut_lsd.lsd_osd_index);
1253 CDEBUG(D_HA, "%s: LAST FID is "DFID"\n", ofd_name(ofd),
1256 ofd_seq_put(tsi->tsi_env, oseq);
1258 CERROR("%s: not supported key %s\n", tgt_name(tsi->tsi_tgt),
1262 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GET_INFO,
1269 * OFD request handler for OST_GETATTR RPC.
1271 * This is OFD-specific part of request handling. It finds the OFD object
1272 * by its FID, gets attributes from storage and packs result to the reply.
1274 * \param[in] tsi target session environment for this request
1276 * \retval 0 if successful
1277 * \retval negative value on error
1279 static int ofd_getattr_hdl(struct tgt_session_info *tsi)
1281 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1282 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1283 struct ost_body *repbody;
1284 struct lustre_handle lh = { 0 };
1285 struct ofd_object *fo;
1287 enum ldlm_mode lock_mode = LCK_PR;
1292 LASSERT(tsi->tsi_ost_body != NULL);
1294 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1295 if (repbody == NULL)
1298 repbody->oa.o_oi = tsi->tsi_ost_body->oa.o_oi;
1299 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1301 srvlock = tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
1302 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK;
1305 if (unlikely(tsi->tsi_ost_body->oa.o_flags & OBD_FL_FLUSH))
1308 rc = tgt_extent_lock(tsi->tsi_tgt->lut_obd->obd_namespace,
1309 &tsi->tsi_resid, 0, OBD_OBJECT_EOF, &lh,
1315 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1317 GOTO(out, rc = PTR_ERR(fo));
1319 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1323 obdo_from_la(&repbody->oa, &fti->fti_attr,
1324 OFD_VALID_FLAGS | LA_UID | LA_GID);
1325 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1327 /* Store object version in reply */
1328 curr_version = dt_version_get(tsi->tsi_env,
1329 ofd_object_child(fo));
1330 if ((__s64)curr_version != -EOPNOTSUPP) {
1331 repbody->oa.o_valid |= OBD_MD_FLDATAVERSION;
1332 repbody->oa.o_data_version = curr_version;
1336 ofd_object_put(tsi->tsi_env, fo);
1339 tgt_extent_unlock(&lh, lock_mode);
1341 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_GETATTR,
1344 repbody->oa.o_valid |= OBD_MD_FLFLAGS;
1345 repbody->oa.o_flags = OBD_FL_FLUSH;
1351 * OFD request handler for OST_SETATTR RPC.
1353 * This is OFD-specific part of request handling. It finds the OFD object
1354 * by its FID, sets attributes from request and packs result to the reply.
1356 * \param[in] tsi target session environment for this request
1358 * \retval 0 if successful
1359 * \retval negative value on error
1361 static int ofd_setattr_hdl(struct tgt_session_info *tsi)
1363 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1364 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1365 struct ost_body *body = tsi->tsi_ost_body;
1366 struct ost_body *repbody;
1367 struct ldlm_resource *res;
1368 struct ofd_object *fo;
1369 struct filter_fid *ff = NULL;
1374 LASSERT(body != NULL);
1376 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1377 if (repbody == NULL)
1380 repbody->oa.o_oi = body->oa.o_oi;
1381 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1383 /* This would be very bad - accidentally truncating a file when
1384 * changing the time or similar - bug 12203. */
1385 if (body->oa.o_valid & OBD_MD_FLSIZE &&
1386 body->oa.o_size != OBD_OBJECT_EOF) {
1387 static char mdsinum[48];
1389 if (body->oa.o_valid & OBD_MD_FLFID)
1390 snprintf(mdsinum, sizeof(mdsinum) - 1,
1391 "of parent "DFID, body->oa.o_parent_seq,
1392 body->oa.o_parent_oid, 0);
1396 CERROR("%s: setattr from %s is trying to truncate object "DFID
1397 " %s\n", ofd_name(ofd), obd_export_nid2str(tsi->tsi_exp),
1398 PFID(&tsi->tsi_fid), mdsinum);
1402 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1404 GOTO(out, rc = PTR_ERR(fo));
1406 la_from_obdo(&fti->fti_attr, &body->oa, body->oa.o_valid);
1407 fti->fti_attr.la_valid &= ~LA_TYPE;
1409 if (body->oa.o_valid & OBD_MD_FLFID) {
1410 ff = &fti->fti_mds_fid;
1411 ofd_prepare_fidea(ff, &body->oa);
1414 /* setting objects attributes (including owner/group) */
1415 rc = ofd_attr_set(tsi->tsi_env, fo, &fti->fti_attr, ff);
1419 obdo_from_la(&repbody->oa, &fti->fti_attr,
1420 OFD_VALID_FLAGS | LA_UID | LA_GID);
1421 tgt_drop_id(tsi->tsi_exp, &repbody->oa);
1423 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SETATTR,
1427 ofd_object_put(tsi->tsi_env, fo);
1430 /* we do not call this before to avoid lu_object_find() in
1431 * ->lvbo_update() holding another reference on the object.
1432 * otherwise concurrent destroy can make the object unavailable
1433 * for 2nd lu_object_find() waiting for the first reference
1434 * to go... deadlock! */
1435 res = ldlm_resource_get(ofd->ofd_namespace, NULL,
1436 &tsi->tsi_resid, LDLM_EXTENT, 0);
1438 ldlm_res_lvbo_update(res, NULL, 0);
1439 ldlm_resource_putref(res);
1446 * Destroy OST orphans.
1448 * This is part of OST_CREATE RPC handling. If there is flag OBD_FL_DELORPHAN
1449 * set then we must destroy possible orphaned objects.
1451 * \param[in] env execution environment
1452 * \param[in] exp OBD export
1453 * \param[in] ofd OFD device
1454 * \param[in] oa obdo structure for reply
1456 * \retval 0 if successful
1457 * \retval negative value on error
1459 static int ofd_orphans_destroy(const struct lu_env *env,
1460 struct obd_export *exp,
1461 struct ofd_device *ofd, struct obdo *oa)
1463 struct ofd_thread_info *info = ofd_info(env);
1464 struct lu_fid *fid = &info->fti_fid;
1465 struct ost_id *oi = &oa->o_oi;
1466 struct ofd_seq *oseq;
1467 u64 seq = ostid_seq(oi);
1468 u64 end_id = ostid_id(oi);
1476 oseq = ofd_seq_get(ofd, seq);
1478 CERROR("%s: Can not find seq for "DOSTID"\n",
1479 ofd_name(ofd), POSTID(oi));
1484 last = ofd_seq_last_oid(oseq);
1487 LASSERT(exp != NULL);
1488 skip_orphan = !!(exp_connect_flags(exp) & OBD_CONNECT_SKIP_ORPHAN);
1490 if (OBD_FAIL_CHECK(OBD_FAIL_OST_NODESTROY))
1493 LCONSOLE(D_INFO, "%s: deleting orphan objects from "DOSTID
1494 " to "DOSTID"\n", ofd_name(ofd), seq, end_id + 1, seq, last);
1496 while (oid > end_id) {
1497 rc = fid_set_id(fid, oid);
1498 if (unlikely(rc != 0))
1501 rc = ofd_destroy_by_fid(env, ofd, fid, 1);
1502 if (rc != 0 && rc != -ENOENT && rc != -ESTALE &&
1503 likely(rc != -EREMCHG && rc != -EINPROGRESS))
1504 /* this is pretty fatal... */
1505 CEMERG("%s: error destroying precreated id "
1507 ofd_name(ofd), PFID(fid), rc);
1511 ofd_seq_last_oid_set(oseq, oid);
1512 /* update last_id on disk periodically so that if we
1513 * restart * we don't need to re-scan all of the just
1514 * deleted objects. */
1515 if ((oid & 511) == 0)
1516 ofd_seq_last_oid_write(env, ofd, oseq);
1520 CDEBUG(D_HA, "%s: after destroy: set last_id to "DOSTID"\n",
1521 ofd_name(ofd), seq, oid);
1525 ofd_seq_last_oid_set(oseq, oid);
1526 rc = ofd_seq_last_oid_write(env, ofd, oseq);
1528 /* don't reuse orphan object, return last used objid */
1529 ostid_set_id(oi, last);
1536 ofd_seq_put(env, oseq);
1541 * OFD request handler for OST_CREATE RPC.
1543 * This is OFD-specific part of request handling. Its main purpose is to
1544 * create new data objects on OST, but it also used to destroy orphans.
1546 * \param[in] tsi target session environment for this request
1548 * \retval 0 if successful
1549 * \retval negative value on error
1551 static int ofd_create_hdl(struct tgt_session_info *tsi)
1553 struct ptlrpc_request *req = tgt_ses_req(tsi);
1554 struct ost_body *repbody;
1555 const struct obdo *oa = &tsi->tsi_ost_body->oa;
1556 struct obdo *rep_oa;
1557 struct obd_export *exp = tsi->tsi_exp;
1558 struct ofd_device *ofd = ofd_exp(exp);
1559 u64 seq = ostid_seq(&oa->o_oi);
1560 u64 oid = ostid_id(&oa->o_oi);
1561 struct ofd_seq *oseq;
1568 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1571 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1572 if (repbody == NULL)
1575 down_read(&ofd->ofd_lastid_rwsem);
1576 /* Currently, for safe, we do not distinguish which LAST_ID is broken,
1577 * we may do that in the future.
1578 * Return -ENOSPC until the LAST_ID rebuilt. */
1579 if (unlikely(ofd->ofd_lastid_rebuilding))
1580 GOTO(out_sem, rc = -ENOSPC);
1582 rep_oa = &repbody->oa;
1583 rep_oa->o_oi = oa->o_oi;
1585 LASSERT(seq >= FID_SEQ_OST_MDT0);
1586 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
1588 CDEBUG(D_INFO, "ofd_create("DOSTID")\n", POSTID(&oa->o_oi));
1590 oseq = ofd_seq_load(tsi->tsi_env, ofd, seq);
1592 CERROR("%s: Can't find FID Sequence "LPX64": rc = %ld\n",
1593 ofd_name(ofd), seq, PTR_ERR(oseq));
1594 GOTO(out_sem, rc = -EINVAL);
1597 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1598 (oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1599 if (!ofd_obd(ofd)->obd_recovering ||
1600 oid > ofd_seq_last_oid(oseq)) {
1601 CERROR("%s: recreate objid "DOSTID" > last id "LPU64
1602 "\n", ofd_name(ofd), POSTID(&oa->o_oi),
1603 ofd_seq_last_oid(oseq));
1604 GOTO(out_nolock, rc = -EINVAL);
1606 /* Do nothing here, we re-create objects during recovery
1607 * upon write replay, see ofd_preprw_write() */
1608 GOTO(out_nolock, rc = 0);
1610 /* former ofd_handle_precreate */
1611 if ((oa->o_valid & OBD_MD_FLFLAGS) &&
1612 (oa->o_flags & OBD_FL_DELORPHAN)) {
1613 exp->exp_filter_data.fed_lastid_gen = ofd->ofd_lastid_gen;
1615 /* destroy orphans */
1616 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1617 exp->exp_conn_cnt) {
1618 CERROR("%s: dropping old orphan cleanup request\n",
1620 GOTO(out_nolock, rc = 0);
1622 /* This causes inflight precreates to abort and drop lock */
1623 oseq->os_destroys_in_progress = 1;
1624 mutex_lock(&oseq->os_create_lock);
1625 if (!oseq->os_destroys_in_progress) {
1626 CERROR("%s:["LPU64"] destroys_in_progress already"
1627 " cleared\n", ofd_name(ofd), seq);
1628 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1631 diff = oid - ofd_seq_last_oid(oseq);
1632 CDEBUG(D_HA, "ofd_last_id() = "LPU64" -> diff = %d\n",
1633 ofd_seq_last_oid(oseq), diff);
1634 if (-diff > OST_MAX_PRECREATE) {
1635 /* Let MDS know that we are so far ahead. */
1636 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq) + 1);
1638 } else if (diff < 0) {
1639 rc = ofd_orphans_destroy(tsi->tsi_env, exp,
1641 oseq->os_destroys_in_progress = 0;
1643 /* XXX: Used by MDS for the first time! */
1644 oseq->os_destroys_in_progress = 0;
1647 if (unlikely(exp->exp_filter_data.fed_lastid_gen !=
1648 ofd->ofd_lastid_gen)) {
1649 /* Keep the export ref so we can send the reply. */
1650 ofd_obd_disconnect(class_export_get(exp));
1651 GOTO(out_nolock, rc = -ENOTCONN);
1654 mutex_lock(&oseq->os_create_lock);
1655 if (lustre_msg_get_conn_cnt(tgt_ses_req(tsi)->rq_reqmsg) <
1656 exp->exp_conn_cnt) {
1657 CERROR("%s: dropping old precreate request\n",
1661 /* only precreate if seq is 0, IDIF or normal and also o_id
1662 * must be specfied */
1663 if ((!fid_seq_is_mdt(seq) && !fid_seq_is_norm(seq) &&
1664 !fid_seq_is_idif(seq)) || oid == 0) {
1665 diff = 1; /* shouldn't we create this right now? */
1667 diff = oid - ofd_seq_last_oid(oseq);
1668 /* Do sync create if the seq is about to used up */
1669 if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) {
1670 if (unlikely(oid >= IDIF_MAX_OID - 1))
1672 } else if (fid_seq_is_norm(seq)) {
1674 LUSTRE_DATA_SEQ_MAX_WIDTH - 1))
1677 CERROR("%s : invalid o_seq "DOSTID"\n",
1678 ofd_name(ofd), POSTID(&oa->o_oi));
1679 GOTO(out, rc = -EINVAL);
1684 CERROR("%s: invalid precreate request for "
1685 DOSTID", last_id " LPU64 ". "
1686 "Likely MDS last_id corruption\n",
1687 ofd_name(ofd), POSTID(&oa->o_oi),
1688 ofd_seq_last_oid(oseq));
1689 GOTO(out, rc = -EINVAL);
1694 cfs_time_t enough_time = cfs_time_shift(DISK_TIMEOUT);
1699 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1700 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1701 /* don't enforce grant during orphan recovery */
1702 granted = ofd_grant_create(tsi->tsi_env,
1703 ofd_obd(ofd)->obd_self_export,
1708 CDEBUG(D_HA, "%s: failed to acquire grant "
1709 "space for precreate (%d): rc = %d\n",
1710 ofd_name(ofd), diff, rc);
1715 /* This can happen if a new OST is formatted and installed
1716 * in place of an old one at the same index. Instead of
1717 * precreating potentially millions of deleted old objects
1718 * (possibly filling the OST), only precreate the last batch.
1719 * LFSCK will eventually clean up any orphans. LU-14 */
1720 if (diff > 5 * OST_MAX_PRECREATE) {
1721 diff = OST_MAX_PRECREATE / 2;
1722 LCONSOLE_WARN("%s: precreate FID "DOSTID" is over %u "
1723 "larger than the LAST_ID "DOSTID", only "
1724 "precreating the last %u objects.\n",
1725 ofd_name(ofd), POSTID(&oa->o_oi),
1726 5 * OST_MAX_PRECREATE,
1727 POSTID(&oseq->os_oi), diff);
1728 ofd_seq_last_oid_set(oseq, ostid_id(&oa->o_oi) - diff);
1732 next_id = ofd_seq_last_oid(oseq) + 1;
1733 count = ofd_precreate_batch(ofd, diff);
1735 CDEBUG(D_HA, "%s: reserve %d objects in group "LPX64
1736 " at "LPU64"\n", ofd_name(ofd),
1737 count, seq, next_id);
1739 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1740 && cfs_time_after(jiffies, enough_time)) {
1741 CDEBUG(D_HA, "%s: Slow creates, %d/%d objects"
1742 " created at a rate of %d/s\n",
1743 ofd_name(ofd), created, diff + created,
1744 created / DISK_TIMEOUT);
1748 rc = ofd_precreate_objects(tsi->tsi_env, ofd, next_id,
1749 oseq, count, sync_trans);
1753 } else if (rc < 0) {
1759 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)
1760 LCONSOLE_WARN("%s: can't create the same count of"
1761 " objects when replaying the request"
1762 " (diff is %d). see LU-4621\n",
1763 ofd_name(ofd), diff);
1766 /* some objects got created, we can return
1767 * them, even if last creation failed */
1770 CERROR("%s: unable to precreate: rc = %d\n",
1773 if (!(oa->o_valid & OBD_MD_FLFLAGS) ||
1774 !(oa->o_flags & OBD_FL_DELORPHAN)) {
1775 ofd_grant_commit(ofd_obd(ofd)->obd_self_export, granted,
1780 ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq));
1783 ofd_counter_incr(exp, LPROC_OFD_STATS_CREATE,
1786 mutex_unlock(&oseq->os_create_lock);
1789 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
1790 struct ofd_thread_info *info = ofd_info(tsi->tsi_env);
1791 struct lu_fid *fid = &info->fti_fid;
1793 /* For compatible purpose, it needs to convert back to
1794 * OST ID before put it on wire. */
1795 *fid = rep_oa->o_oi.oi_fid;
1796 fid_to_ostid(fid, &rep_oa->o_oi);
1798 rep_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
1800 ofd_seq_put(tsi->tsi_env, oseq);
1803 up_read(&ofd->ofd_lastid_rwsem);
1808 * OFD request handler for OST_DESTROY RPC.
1810 * This is OFD-specific part of request handling. It destroys data objects
1811 * related to destroyed object on MDT.
1813 * \param[in] tsi target session environment for this request
1815 * \retval 0 if successful
1816 * \retval negative value on error
1818 static int ofd_destroy_hdl(struct tgt_session_info *tsi)
1820 const struct ost_body *body = tsi->tsi_ost_body;
1821 struct ost_body *repbody;
1822 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1823 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1824 struct lu_fid *fid = &fti->fti_fid;
1831 if (OBD_FAIL_CHECK(OBD_FAIL_OST_EROFS))
1834 /* This is old case for clients before Lustre 2.4 */
1835 /* If there's a DLM request, cancel the locks mentioned in it */
1836 if (req_capsule_field_present(tsi->tsi_pill, &RMF_DLM_REQ,
1838 struct ldlm_request *dlm;
1840 dlm = req_capsule_client_get(tsi->tsi_pill, &RMF_DLM_REQ);
1843 ldlm_request_cancel(tgt_ses_req(tsi), dlm, 0, LATF_SKIP);
1846 *fid = body->oa.o_oi.oi_fid;
1847 oid = ostid_id(&body->oa.o_oi);
1850 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1852 /* check that o_misc makes sense */
1853 if (body->oa.o_valid & OBD_MD_FLOBJCOUNT)
1854 count = body->oa.o_misc;
1856 count = 1; /* default case - single destroy */
1858 CDEBUG(D_HA, "%s: Destroy object "DOSTID" count %d\n", ofd_name(ofd),
1859 POSTID(&body->oa.o_oi), count);
1864 lrc = ofd_destroy_by_fid(tsi->tsi_env, ofd, fid, 0);
1865 if (lrc == -ENOENT) {
1867 "%s: destroying non-existent object "DFID"\n",
1868 ofd_name(ofd), PFID(fid));
1869 /* rewrite rc with -ENOENT only if it is 0 */
1872 } else if (lrc != 0) {
1873 CERROR("%s: error destroying object "DFID": %d\n",
1874 ofd_name(ofd), PFID(fid), lrc);
1880 lrc = fid_set_id(fid, oid);
1881 if (unlikely(lrc != 0 && count > 0))
1882 GOTO(out, rc = lrc);
1885 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_DESTROY,
1891 fid_to_ostid(fid, &repbody->oa.o_oi);
1896 * OFD request handler for OST_STATFS RPC.
1898 * This function gets statfs data from storage as part of request
1901 * \param[in] tsi target session environment for this request
1903 * \retval 0 if successful
1904 * \retval negative value on error
1906 static int ofd_statfs_hdl(struct tgt_session_info *tsi)
1908 struct obd_statfs *osfs;
1913 osfs = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_STATFS);
1915 rc = ofd_statfs(tsi->tsi_env, tsi->tsi_exp, osfs,
1916 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 0);
1918 CERROR("%s: statfs failed: rc = %d\n",
1919 tgt_name(tsi->tsi_tgt), rc);
1921 if (OBD_FAIL_CHECK(OBD_FAIL_OST_STATFS_EINPROGRESS))
1924 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_STATFS,
1931 * OFD request handler for OST_SYNC RPC.
1933 * Sync object data or all filesystem data to the disk and pack the
1936 * \param[in] tsi target session environment for this request
1938 * \retval 0 if successful
1939 * \retval negative value on error
1941 static int ofd_sync_hdl(struct tgt_session_info *tsi)
1943 struct ost_body *body = tsi->tsi_ost_body;
1944 struct ost_body *repbody;
1945 struct ofd_thread_info *fti = tsi2ofd_info(tsi);
1946 struct ofd_device *ofd = ofd_exp(tsi->tsi_exp);
1947 struct ofd_object *fo = NULL;
1952 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
1954 /* if no objid is specified, it means "sync whole filesystem" */
1955 if (!fid_is_zero(&tsi->tsi_fid)) {
1956 fo = ofd_object_find_exists(tsi->tsi_env, ofd, &tsi->tsi_fid);
1958 RETURN(PTR_ERR(fo));
1961 rc = tgt_sync(tsi->tsi_env, tsi->tsi_tgt,
1962 fo != NULL ? ofd_object_child(fo) : NULL,
1963 repbody->oa.o_size, repbody->oa.o_blocks);
1967 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_SYNC,
1972 repbody->oa.o_oi = body->oa.o_oi;
1973 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1975 rc = ofd_attr_get(tsi->tsi_env, fo, &fti->fti_attr);
1977 obdo_from_la(&repbody->oa, &fti->fti_attr,
1980 /* don't return rc from getattr */
1985 ofd_object_put(tsi->tsi_env, fo);
1990 * OFD request handler for OST_PUNCH RPC.
1992 * This is part of request processing. Validate request fields,
1993 * punch (truncate) the given OFD object and pack reply.
1995 * \param[in] tsi target session environment for this request
1997 * \retval 0 if successful
1998 * \retval negative value on error
2000 static int ofd_punch_hdl(struct tgt_session_info *tsi)
2002 const struct obdo *oa = &tsi->tsi_ost_body->oa;
2003 struct ost_body *repbody;
2004 struct ofd_thread_info *info = tsi2ofd_info(tsi);
2005 struct ldlm_namespace *ns = tsi->tsi_tgt->lut_obd->obd_namespace;
2006 struct ldlm_resource *res;
2007 struct ofd_object *fo;
2008 struct filter_fid *ff = NULL;
2010 struct lustre_handle lh = { 0, };
2017 /* check that we do support OBD_CONNECT_TRUNCLOCK. */
2018 CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK);
2020 if ((oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) !=
2021 (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS))
2022 RETURN(err_serious(-EPROTO));
2024 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
2025 if (repbody == NULL)
2026 RETURN(err_serious(-ENOMEM));
2028 /* punch start,end are passed in o_size,o_blocks throught wire */
2032 if (end != OBD_OBJECT_EOF) /* Only truncate is supported */
2035 /* standard truncate optimization: if file body is completely
2036 * destroyed, don't send data back to the server. */
2038 flags |= LDLM_FL_AST_DISCARD_DATA;
2040 repbody->oa.o_oi = oa->o_oi;
2041 repbody->oa.o_valid = OBD_MD_FLID;
2043 srvlock = oa->o_valid & OBD_MD_FLFLAGS &&
2044 oa->o_flags & OBD_FL_SRVLOCK;
2047 rc = tgt_extent_lock(ns, &tsi->tsi_resid, start, end, &lh,
2053 CDEBUG(D_INODE, "calling punch for object "DFID", valid = "LPX64
2054 ", start = "LPD64", end = "LPD64"\n", PFID(&tsi->tsi_fid),
2055 oa->o_valid, start, end);
2057 fo = ofd_object_find_exists(tsi->tsi_env, ofd_exp(tsi->tsi_exp),
2060 GOTO(out, rc = PTR_ERR(fo));
2062 la_from_obdo(&info->fti_attr, oa,
2063 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME);
2064 info->fti_attr.la_size = start;
2065 info->fti_attr.la_valid |= LA_SIZE;
2067 if (oa->o_valid & OBD_MD_FLFID) {
2068 ff = &info->fti_mds_fid;
2069 ofd_prepare_fidea(ff, oa);
2072 rc = ofd_object_punch(tsi->tsi_env, fo, start, end, &info->fti_attr,
2073 ff, (struct obdo *)oa);
2077 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_PUNCH,
2081 ofd_object_put(tsi->tsi_env, fo);
2084 tgt_extent_unlock(&lh, LCK_PW);
2086 /* we do not call this before to avoid lu_object_find() in
2087 * ->lvbo_update() holding another reference on the object.
2088 * otherwise concurrent destroy can make the object unavailable
2089 * for 2nd lu_object_find() waiting for the first reference
2090 * to go... deadlock! */
2091 res = ldlm_resource_get(ns, NULL, &tsi->tsi_resid,
2094 ldlm_res_lvbo_update(res, NULL, 0);
2095 ldlm_resource_putref(res);
2102 * OFD request handler for OST_QUOTACTL RPC.
2104 * This is part of request processing to validate incoming request fields,
2105 * get the requested data from OSD and pack reply.
2107 * \param[in] tsi target session environment for this request
2109 * \retval 0 if successful
2110 * \retval negative value on error
2112 static int ofd_quotactl(struct tgt_session_info *tsi)
2114 struct obd_quotactl *oqctl, *repoqc;
2115 struct lu_nodemap *nodemap =
2116 tsi->tsi_exp->exp_target_data.ted_nodemap;
2122 oqctl = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
2124 RETURN(err_serious(-EPROTO));
2126 repoqc = req_capsule_server_get(tsi->tsi_pill, &RMF_OBD_QUOTACTL);
2128 RETURN(err_serious(-ENOMEM));
2133 if (oqctl->qc_type == USRQUOTA)
2134 id = nodemap_map_id(nodemap, NODEMAP_UID,
2135 NODEMAP_CLIENT_TO_FS,
2137 else if (oqctl->qc_type == GRPQUOTA)
2138 id = nodemap_map_id(nodemap, NODEMAP_GID,
2139 NODEMAP_CLIENT_TO_FS,
2142 if (repoqc->qc_id != id)
2143 swap(repoqc->qc_id, id);
2145 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom, repoqc);
2147 ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_QUOTACTL,
2150 if (repoqc->qc_id != id)
2151 swap(repoqc->qc_id, id);
2157 * Calculate the amount of time for lock prolongation.
2159 * This is helper for ofd_prolong_extent_locks() function to get
2160 * the timeout extra time.
2162 * \param[in] req current request
2164 * \retval amount of time to extend the timeout with
2166 static inline int prolong_timeout(struct ptlrpc_request *req,
2167 struct ldlm_lock *lock)
2169 struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
2172 return obd_timeout / 2;
2174 /* We are in the middle of the process - BL AST is sent, CANCEL
2175 is ahead. Take half of AT + IO process time. */
2176 return at_est2timeout(at_get(&svcpt->scp_at_estimate)) +
2177 (ldlm_bl_timeout(lock) >> 1);
2181 * Prolong single lock timeout.
2183 * This is supplemental function to the ofd_prolong_locks(). It prolongs
2186 * \param[in] tsi target session environment for this request
2187 * \param[in] lock LDLM lock to prolong
2188 * \param[in] extent related extent
2189 * \param[in] timeout timeout value to add
2191 * \retval 0 if lock is not suitable for prolongation
2192 * \retval 1 if lock was prolonged successfully
2194 static int ofd_prolong_one_lock(struct tgt_session_info *tsi,
2195 struct ldlm_lock *lock,
2196 struct ldlm_extent *extent)
2198 int timeout = prolong_timeout(tgt_ses_req(tsi), lock);
2200 if (lock->l_flags & LDLM_FL_DESTROYED) /* lock already cancelled */
2203 /* XXX: never try to grab resource lock here because we're inside
2204 * exp_bl_list_lock; in ldlm_lockd.c to handle waiting list we take
2205 * res lock and then exp_bl_list_lock. */
2207 if (!(lock->l_flags & LDLM_FL_AST_SENT))
2208 /* ignore locks not being cancelled */
2211 LDLM_DEBUG(lock, "refreshed for req x"LPU64" ext("LPU64"->"LPU64") "
2212 "to %ds.\n", tgt_ses_req(tsi)->rq_xid, extent->start,
2213 extent->end, timeout);
2215 /* OK. this is a possible lock the user holds doing I/O
2216 * let's refresh eviction timer for it */
2217 ldlm_refresh_waiting_lock(lock, timeout);
2222 * Prolong lock timeout for the given extent.
2224 * This function finds all locks related with incoming request and
2225 * prolongs their timeout.
2227 * If a client is holding a lock for a long time while it sends
2228 * read or write RPCs to the OST for the object under this lock,
2229 * then we don't want the OST to evict the client. Otherwise,
2230 * if the network or disk is very busy then the client may not
2231 * be able to make any progress to clear out dirty pages under
2232 * the lock and the application will fail.
2234 * Every time a Bulk Read/Write (BRW) request arrives for the object
2235 * covered by the lock, extend the timeout on that lock. The RPC should
2236 * contain a lock handle for the lock it is using, but this
2237 * isn't handled correctly by all client versions, and the
2238 * request may cover multiple locks.
2240 * \param[in] tsi target session environment for this request
2241 * \param[in] start start of extent
2242 * \param[in] end end of extent
2244 * \retval number of prolonged locks
2246 static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
2247 __u64 start, __u64 end)
2249 struct obd_export *exp = tsi->tsi_exp;
2250 struct obdo *oa = &tsi->tsi_ost_body->oa;
2251 struct ldlm_extent extent = {
2255 struct ldlm_lock *lock;
2260 if (oa->o_valid & OBD_MD_FLHANDLE) {
2261 /* mostly a request should be covered by only one lock, try
2263 lock = ldlm_handle2lock(&oa->o_handle);
2265 /* Fast path to check if the lock covers the whole IO
2266 * region exclusively. */
2267 if (lock->l_granted_mode == LCK_PW &&
2268 ldlm_extent_contain(&lock->l_policy_data.l_extent,
2271 LASSERT(lock->l_export == exp);
2272 lock_count = ofd_prolong_one_lock(tsi, lock,
2274 LDLM_LOCK_PUT(lock);
2277 lock->l_last_used = cfs_time_current();
2278 LDLM_LOCK_PUT(lock);
2282 spin_lock_bh(&exp->exp_bl_list_lock);
2283 list_for_each_entry(lock, &exp->exp_bl_list, l_exp_list) {
2284 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
2285 LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
2287 /* ignore waiting locks, no more granted locks in the list */
2288 if (lock->l_granted_mode != lock->l_req_mode)
2291 if (!ldlm_res_eq(&tsi->tsi_resid, &lock->l_resource->lr_name))
2294 if (!ldlm_extent_overlap(&lock->l_policy_data.l_extent,
2298 lock_count += ofd_prolong_one_lock(tsi, lock, &extent);
2300 spin_unlock_bh(&exp->exp_bl_list_lock);
2306 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_match for OFD RW requests.
2308 * Determine if \a lock and the lock from request \a req are equivalent
2309 * by comparing their resource names, modes, and extents.
2311 * It is used to give priority to read and write RPCs being done
2312 * under this lock so that the client can drop the contended
2313 * lock more quickly and let other clients use it. This improves
2314 * overall performance in the case where the first client gets a
2315 * very large lock extent that prevents other clients from
2316 * submitting their writes.
2318 * \param[in] req ptlrpc_request being processed
2319 * \param[in] lock contended lock to match
2321 * \retval 1 if lock is matched
2322 * \retval 0 otherwise
2324 static int ofd_rw_hpreq_lock_match(struct ptlrpc_request *req,
2325 struct ldlm_lock *lock)
2327 struct niobuf_remote *rnb;
2328 struct obd_ioobj *ioo;
2329 enum ldlm_mode mode;
2330 struct ldlm_extent ext;
2331 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
2335 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
2336 LASSERT(ioo != NULL);
2338 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
2339 LASSERT(rnb != NULL);
2341 ext.start = rnb->rnb_offset;
2342 rnb += ioo->ioo_bufcnt - 1;
2343 ext.end = rnb->rnb_offset + rnb->rnb_len - 1;
2345 LASSERT(lock->l_resource != NULL);
2346 if (!ostid_res_name_eq(&ioo->ioo_oid, &lock->l_resource->lr_name))
2349 /* a bulk write can only hold a reference on a PW extent lock */
2351 if (opc == OST_READ)
2352 /* whereas a bulk read can be protected by either a PR or PW
2356 if (!(lock->l_granted_mode & mode))
2359 RETURN(ldlm_extent_overlap(&lock->l_policy_data.l_extent, &ext));
2363 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_check for OFD RW requests.
2365 * Check for whether the given PTLRPC request (\a req) is blocking
2366 * an LDLM lock cancel.
2368 * \param[in] req the incoming request
2370 * \retval 1 if \a req is blocking an LDLM lock cancel
2371 * \retval 0 if it is not
2373 static int ofd_rw_hpreq_check(struct ptlrpc_request *req)
2375 struct tgt_session_info *tsi;
2376 struct obd_ioobj *ioo;
2377 struct niobuf_remote *rnb;
2383 /* Don't use tgt_ses_info() to get session info, because lock_match()
2384 * can be called while request has no processing thread yet. */
2385 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
2388 * Use LASSERT below because malformed RPCs should have
2389 * been filtered out in tgt_hpreq_handler().
2391 ioo = req_capsule_client_get(&req->rq_pill, &RMF_OBD_IOOBJ);
2392 LASSERT(ioo != NULL);
2394 rnb = req_capsule_client_get(&req->rq_pill, &RMF_NIOBUF_REMOTE);
2395 LASSERT(rnb != NULL);
2396 LASSERT(!(rnb->rnb_flags & OBD_BRW_SRVLOCK));
2398 start = rnb->rnb_offset;
2399 rnb += ioo->ioo_bufcnt - 1;
2400 end = rnb->rnb_offset + rnb->rnb_len - 1;
2402 DEBUG_REQ(D_RPCTRACE, req, "%s %s: refresh rw locks: "DFID
2403 " ("LPU64"->"LPU64")\n",
2404 tgt_name(tsi->tsi_tgt), current->comm,
2405 PFID(&tsi->tsi_fid), start, end);
2407 lock_count = ofd_prolong_extent_locks(tsi, start, end);
2409 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2410 tgt_name(tsi->tsi_tgt), lock_count, req);
2412 RETURN(lock_count > 0);
2416 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_fini for OFD RW requests.
2418 * Called after the request has been handled. It refreshes lock timeout again
2419 * so that client has more time to send lock cancel RPC.
2421 * \param[in] req request which is being processed.
2423 static void ofd_rw_hpreq_fini(struct ptlrpc_request *req)
2425 ofd_rw_hpreq_check(req);
2429 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_match for OST_PUNCH request.
2431 * This function checks if the given lock is the same by its resname, mode
2432 * and extent as one taken from the request.
2433 * It is used to give priority to punch/truncate RPCs that might lead to
2434 * the fastest release of that lock when a lock is contended.
2436 * \param[in] req ptlrpc_request being processed
2437 * \param[in] lock contended lock to match
2439 * \retval 1 if lock is matched
2440 * \retval 0 otherwise
2442 static int ofd_punch_hpreq_lock_match(struct ptlrpc_request *req,
2443 struct ldlm_lock *lock)
2445 struct tgt_session_info *tsi;
2447 /* Don't use tgt_ses_info() to get session info, because lock_match()
2448 * can be called while request has no processing thread yet. */
2449 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
2452 * Use LASSERT below because malformed RPCs should have
2453 * been filtered out in tgt_hpreq_handler().
2455 LASSERT(tsi->tsi_ost_body != NULL);
2456 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLHANDLE &&
2457 tsi->tsi_ost_body->oa.o_handle.cookie == lock->l_handle.h_cookie)
2464 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_check for OST_PUNCH request.
2466 * High-priority queue request check for whether the given punch request
2467 * (\a req) is blocking an LDLM lock cancel.
2469 * \param[in] req the incoming request
2471 * \retval 1 if \a req is blocking an LDLM lock cancel
2472 * \retval 0 if it is not
2474 static int ofd_punch_hpreq_check(struct ptlrpc_request *req)
2476 struct tgt_session_info *tsi;
2482 /* Don't use tgt_ses_info() to get session info, because lock_match()
2483 * can be called while request has no processing thread yet. */
2484 tsi = lu_context_key_get(&req->rq_session, &tgt_session_key);
2485 LASSERT(tsi != NULL);
2486 oa = &tsi->tsi_ost_body->oa;
2488 LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS &&
2489 oa->o_flags & OBD_FL_SRVLOCK));
2492 "%s: refresh locks: "LPU64"/"LPU64" ("LPU64"->"LPU64")\n",
2493 tgt_name(tsi->tsi_tgt), tsi->tsi_resid.name[0],
2494 tsi->tsi_resid.name[1], oa->o_size, oa->o_blocks);
2496 lock_count = ofd_prolong_extent_locks(tsi, oa->o_size, oa->o_blocks);
2498 CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n",
2499 tgt_name(tsi->tsi_tgt), lock_count, req);
2501 RETURN(lock_count > 0);
2505 * Implementation of ptlrpc_hpreq_ops::hpreq_lock_fini for OST_PUNCH request.
2507 * Called after the request has been handled. It refreshes lock timeout again
2508 * so that client has more time to send lock cancel RPC.
2510 * \param[in] req request which is being processed.
2512 static void ofd_punch_hpreq_fini(struct ptlrpc_request *req)
2514 ofd_punch_hpreq_check(req);
2517 static struct ptlrpc_hpreq_ops ofd_hpreq_rw = {
2518 .hpreq_lock_match = ofd_rw_hpreq_lock_match,
2519 .hpreq_check = ofd_rw_hpreq_check,
2520 .hpreq_fini = ofd_rw_hpreq_fini
2523 static struct ptlrpc_hpreq_ops ofd_hpreq_punch = {
2524 .hpreq_lock_match = ofd_punch_hpreq_lock_match,
2525 .hpreq_check = ofd_punch_hpreq_check,
2526 .hpreq_fini = ofd_punch_hpreq_fini
2530 * Assign high priority operations to an IO request.
2532 * Check if the incoming request is a candidate for
2533 * high-priority processing. If it is, assign it a high
2534 * priority operations table.
2536 * \param[in] tsi target session environment for this request
2538 static void ofd_hp_brw(struct tgt_session_info *tsi)
2540 struct niobuf_remote *rnb;
2541 struct obd_ioobj *ioo;
2545 ioo = req_capsule_client_get(tsi->tsi_pill, &RMF_OBD_IOOBJ);
2546 LASSERT(ioo != NULL); /* must exist after request preprocessing */
2547 if (ioo->ioo_bufcnt > 0) {
2548 rnb = req_capsule_client_get(tsi->tsi_pill, &RMF_NIOBUF_REMOTE);
2549 LASSERT(rnb != NULL); /* must exist after request preprocessing */
2551 /* no high priority if server lock is needed */
2552 if (rnb->rnb_flags & OBD_BRW_SRVLOCK)
2555 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_rw;
2559 * Assign high priority operations to an punch request.
2561 * Check if the incoming request is a candidate for
2562 * high-priority processing. If it is, assign it a high
2563 * priority operations table.
2565 * \param[in] tsi target session environment for this request
2567 static void ofd_hp_punch(struct tgt_session_info *tsi)
2569 LASSERT(tsi->tsi_ost_body != NULL); /* must exists if we are here */
2570 /* no high-priority if server lock is needed */
2571 if (tsi->tsi_ost_body->oa.o_valid & OBD_MD_FLFLAGS &&
2572 tsi->tsi_ost_body->oa.o_flags & OBD_FL_SRVLOCK)
2574 tgt_ses_req(tsi)->rq_ops = &ofd_hpreq_punch;
2577 #define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
2578 #define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
2579 #define OST_BRW_READ OST_READ
2580 #define OST_BRW_WRITE OST_WRITE
2583 * Table of OFD-specific request handlers
2585 * This table contains all opcodes accepted by OFD and
2586 * specifies handlers for them. The tgt_request_handler()
2587 * uses such table from each target to process incoming
2590 static struct tgt_handler ofd_tgt_handlers[] = {
2591 TGT_RPC_HANDLER(OST_FIRST_OPC,
2592 0, OST_CONNECT, tgt_connect,
2593 &RQF_CONNECT, LUSTRE_OBD_VERSION),
2594 TGT_RPC_HANDLER(OST_FIRST_OPC,
2595 0, OST_DISCONNECT, tgt_disconnect,
2596 &RQF_OST_DISCONNECT, LUSTRE_OBD_VERSION),
2597 TGT_RPC_HANDLER(OST_FIRST_OPC,
2598 0, OST_SET_INFO, ofd_set_info_hdl,
2599 &RQF_OBD_SET_INFO, LUSTRE_OST_VERSION),
2600 TGT_OST_HDL(0, OST_GET_INFO, ofd_get_info_hdl),
2601 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_GETATTR, ofd_getattr_hdl),
2602 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2603 OST_SETATTR, ofd_setattr_hdl),
2604 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2605 OST_CREATE, ofd_create_hdl),
2606 TGT_OST_HDL(0 | HABEO_REFERO | MUTABOR,
2607 OST_DESTROY, ofd_destroy_hdl),
2608 TGT_OST_HDL(0 | HABEO_REFERO, OST_STATFS, ofd_statfs_hdl),
2609 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO,
2610 OST_BRW_READ, tgt_brw_read,
2612 /* don't set CORPUS flag for brw_write because -ENOENT may be valid case */
2613 TGT_OST_HDL_HP(HABEO_CORPUS| MUTABOR, OST_BRW_WRITE, tgt_brw_write,
2615 TGT_OST_HDL_HP(HABEO_CORPUS| HABEO_REFERO | MUTABOR,
2616 OST_PUNCH, ofd_punch_hdl,
2618 TGT_OST_HDL(HABEO_CORPUS| HABEO_REFERO, OST_SYNC, ofd_sync_hdl),
2619 TGT_OST_HDL(0 | HABEO_REFERO, OST_QUOTACTL, ofd_quotactl),
2622 static struct tgt_opc_slice ofd_common_slice[] = {
2624 .tos_opc_start = OST_FIRST_OPC,
2625 .tos_opc_end = OST_LAST_OPC,
2626 .tos_hs = ofd_tgt_handlers
2629 .tos_opc_start = OBD_FIRST_OPC,
2630 .tos_opc_end = OBD_LAST_OPC,
2631 .tos_hs = tgt_obd_handlers
2634 .tos_opc_start = LDLM_FIRST_OPC,
2635 .tos_opc_end = LDLM_LAST_OPC,
2636 .tos_hs = tgt_dlm_handlers
2639 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
2640 .tos_opc_end = OUT_UPDATE_LAST_OPC,
2641 .tos_hs = tgt_out_handlers
2644 .tos_opc_start = SEQ_FIRST_OPC,
2645 .tos_opc_end = SEQ_LAST_OPC,
2646 .tos_hs = seq_handlers
2649 .tos_opc_start = LFSCK_FIRST_OPC,
2650 .tos_opc_end = LFSCK_LAST_OPC,
2651 .tos_hs = tgt_lfsck_handlers
2654 .tos_opc_start = SEC_FIRST_OPC,
2655 .tos_opc_end = SEC_LAST_OPC,
2656 .tos_hs = tgt_sec_ctx_handlers
2663 /* context key constructor/destructor: ofd_key_init(), ofd_key_fini() */
2664 LU_KEY_INIT_FINI(ofd, struct ofd_thread_info);
2667 * Implementation of lu_context_key::lct_key_exit.
2669 * Optional method called on lu_context_exit() for all allocated
2671 * It is used in OFD to sanitize context values which may be re-used
2672 * during another request processing by the same thread.
2674 * \param[in] ctx execution context
2675 * \param[in] key context key
2676 * \param[in] data ofd_thread_info
2678 static void ofd_key_exit(const struct lu_context *ctx,
2679 struct lu_context_key *key, void *data)
2681 struct ofd_thread_info *info = data;
2683 info->fti_env = NULL;
2684 info->fti_exp = NULL;
2687 info->fti_pre_version = 0;
2690 memset(&info->fti_attr, 0, sizeof info->fti_attr);
2693 struct lu_context_key ofd_thread_key = {
2694 .lct_tags = LCT_DT_THREAD,
2695 .lct_init = ofd_key_init,
2696 .lct_fini = ofd_key_fini,
2697 .lct_exit = ofd_key_exit
2701 * Initialize OFD device according to parameters in the config log \a cfg.
2703 * This is the main starting point of OFD initialization. It fills all OFD
2704 * parameters with their initial values and calls other initializing functions
2705 * to set up all OFD subsystems.
2707 * \param[in] env execution environment
2708 * \param[in] m OFD device
2709 * \param[in] ldt LU device type of OFD
2710 * \param[in] cfg configuration log
2712 * \retval 0 if successful
2713 * \retval negative value on error
2715 static int ofd_init0(const struct lu_env *env, struct ofd_device *m,
2716 struct lu_device_type *ldt, struct lustre_cfg *cfg)
2718 const char *dev = lustre_cfg_string(cfg, 0);
2719 struct ofd_thread_info *info = NULL;
2720 struct obd_device *obd;
2721 struct obd_statfs *osfs;
2726 obd = class_name2obd(dev);
2728 CERROR("Cannot find obd with name %s\n", dev);
2732 rc = lu_env_refill((struct lu_env *)env);
2736 obd->u.obt.obt_magic = OBT_MAGIC;
2738 m->ofd_fmd_max_num = OFD_FMD_MAX_NUM_DEFAULT;
2739 m->ofd_fmd_max_age = OFD_FMD_MAX_AGE_DEFAULT;
2741 spin_lock_init(&m->ofd_flags_lock);
2742 m->ofd_raid_degraded = 0;
2743 m->ofd_syncjournal = 0;
2745 m->ofd_grant_compat_disable = 0;
2746 m->ofd_soft_sync_limit = OFD_SOFT_SYNC_LIMIT_DEFAULT;
2749 spin_lock_init(&m->ofd_osfs_lock);
2750 m->ofd_osfs_age = cfs_time_shift_64(-1000);
2751 m->ofd_osfs_unstable = 0;
2752 m->ofd_statfs_inflight = 0;
2753 m->ofd_osfs_inflight = 0;
2756 spin_lock_init(&m->ofd_grant_lock);
2757 m->ofd_tot_dirty = 0;
2758 m->ofd_tot_granted = 0;
2759 m->ofd_tot_pending = 0;
2760 m->ofd_seq_count = 0;
2761 init_waitqueue_head(&m->ofd_inconsistency_thread.t_ctl_waitq);
2762 INIT_LIST_HEAD(&m->ofd_inconsistency_list);
2763 spin_lock_init(&m->ofd_inconsistency_lock);
2765 spin_lock_init(&m->ofd_batch_lock);
2766 init_rwsem(&m->ofd_lastid_rwsem);
2768 m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops;
2769 m->ofd_dt_dev.dd_lu_dev.ld_obd = obd;
2770 /* set this lu_device to obd, because error handling need it */
2771 obd->obd_lu_dev = &m->ofd_dt_dev.dd_lu_dev;
2773 rc = ofd_procfs_init(m);
2775 CERROR("Can't init ofd lprocfs, rc %d\n", rc);
2779 /* No connection accepted until configurations will finish */
2780 spin_lock(&obd->obd_dev_lock);
2781 obd->obd_no_conn = 1;
2782 spin_unlock(&obd->obd_dev_lock);
2783 obd->obd_replayable = 1;
2784 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
2785 char *str = lustre_cfg_string(cfg, 4);
2787 if (strchr(str, 'n')) {
2788 CWARN("%s: recovery disabled\n", obd->obd_name);
2789 obd->obd_replayable = 0;
2793 info = ofd_info_init(env, NULL);
2797 rc = ofd_stack_init(env, m, cfg);
2799 CERROR("Can't init device stack, rc %d\n", rc);
2800 GOTO(err_fini_proc, rc);
2803 ofd_procfs_add_brw_stats_symlink(m);
2805 /* populate cached statfs data */
2806 osfs = &ofd_info(env)->fti_u.osfs;
2807 rc = ofd_statfs_internal(env, m, osfs, 0, NULL);
2809 CERROR("%s: can't get statfs data, rc %d\n", obd->obd_name, rc);
2810 GOTO(err_fini_stack, rc);
2812 if (!IS_PO2(osfs->os_bsize)) {
2813 CERROR("%s: blocksize (%d) is not a power of 2\n",
2814 obd->obd_name, osfs->os_bsize);
2815 GOTO(err_fini_stack, rc = -EPROTO);
2817 m->ofd_blockbits = fls(osfs->os_bsize) - 1;
2819 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_DEFAULT;
2820 if (osfs->os_bsize * osfs->os_blocks < OFD_PRECREATE_SMALL_FS)
2821 m->ofd_precreate_batch = OFD_PRECREATE_BATCH_SMALL;
2823 snprintf(info->fti_u.name, sizeof(info->fti_u.name), "%s-%s",
2824 "filter"/*LUSTRE_OST_NAME*/, obd->obd_uuid.uuid);
2825 m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name,
2826 LDLM_NAMESPACE_SERVER,
2827 LDLM_NAMESPACE_GREEDY,
2829 if (m->ofd_namespace == NULL)
2830 GOTO(err_fini_stack, rc = -ENOMEM);
2831 /* set obd_namespace for compatibility with old code */
2832 obd->obd_namespace = m->ofd_namespace;
2833 ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);
2834 m->ofd_namespace->ns_lvbo = &ofd_lvbo;
2835 m->ofd_namespace->ns_lvbp = m;
2837 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
2838 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
2840 dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf);
2842 /* Allow at most ddp_grant_reserved% of the available filesystem space
2843 * to be granted to clients, so that any errors in the grant overhead
2844 * calculations do not allow granting more space to clients than can be
2845 * written. Assumes that in aggregate the grant overhead calculations do
2846 * not have more than ddp_grant_reserved% estimation error in them. */
2847 m->ofd_grant_ratio =
2848 ofd_grant_ratio_conv(m->ofd_dt_conf.ddp_grant_reserved);
2850 rc = tgt_init(env, &m->ofd_lut, obd, m->ofd_osd, ofd_common_slice,
2851 OBD_FAIL_OST_ALL_REQUEST_NET,
2852 OBD_FAIL_OST_ALL_REPLY_NET);
2854 GOTO(err_free_ns, rc);
2856 rc = ofd_fs_setup(env, m, obd);
2858 GOTO(err_fini_lut, rc);
2860 rc = ofd_start_inconsistency_verification_thread(m);
2862 GOTO(err_fini_fs, rc);
2864 tgt_adapt_sptlrpc_conf(&m->ofd_lut, 1);
2869 ofd_fs_cleanup(env, m);
2871 tgt_fini(env, &m->ofd_lut);
2873 ldlm_namespace_free(m->ofd_namespace, NULL, obd->obd_force);
2874 obd->obd_namespace = m->ofd_namespace = NULL;
2876 ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev);
2883 * Stop the OFD device
2885 * This function stops the OFD device and all its subsystems.
2886 * This is the end of OFD lifecycle.
2888 * \param[in] env execution environment
2889 * \param[in] m OFD device
2891 static void ofd_fini(const struct lu_env *env, struct ofd_device *m)
2893 struct obd_device *obd = ofd_obd(m);
2894 struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev;
2895 struct lfsck_stop stop;
2897 stop.ls_status = LS_PAUSED;
2899 lfsck_stop(env, m->ofd_osd, &stop);
2900 target_recovery_fini(obd);
2901 if (m->ofd_namespace != NULL)
2902 ldlm_namespace_free_prior(m->ofd_namespace, NULL,
2903 d->ld_obd->obd_force);
2905 obd_exports_barrier(obd);
2906 obd_zombie_barrier();
2908 tgt_fini(env, &m->ofd_lut);
2909 ofd_stop_inconsistency_verification_thread(m);
2910 lfsck_degister(env, m->ofd_osd);
2911 ofd_fs_cleanup(env, m);
2913 if (m->ofd_namespace != NULL) {
2914 ldlm_namespace_free_post(m->ofd_namespace);
2915 d->ld_obd->obd_namespace = m->ofd_namespace = NULL;
2918 ofd_stack_fini(env, m, &m->ofd_dt_dev.dd_lu_dev);
2920 LASSERT(atomic_read(&d->ld_ref) == 0);
2921 server_put_mount(obd->obd_name, true);
2926 * Implementation of lu_device_type_operations::ldto_device_fini.
2928 * Finalize device. Dual to ofd_device_init(). It is called from
2929 * obd_precleanup() and stops the current device.
2931 * \param[in] env execution environment
2932 * \param[in] d LU device of OFD
2936 static struct lu_device *ofd_device_fini(const struct lu_env *env,
2937 struct lu_device *d)
2940 ofd_fini(env, ofd_dev(d));
2945 * Implementation of lu_device_type_operations::ldto_device_free.
2947 * Free OFD device. Dual to ofd_device_alloc().
2949 * \param[in] env execution environment
2950 * \param[in] d LU device of OFD
2954 static struct lu_device *ofd_device_free(const struct lu_env *env,
2955 struct lu_device *d)
2957 struct ofd_device *m = ofd_dev(d);
2959 dt_device_fini(&m->ofd_dt_dev);
2965 * Implementation of lu_device_type_operations::ldto_device_alloc.
2967 * This function allocates the new OFD device. It is called from
2968 * obd_setup() if OBD device had lu_device_type defined.
2970 * \param[in] env execution environment
2971 * \param[in] t lu_device_type of OFD device
2972 * \param[in] cfg configuration log
2974 * \retval pointer to the lu_device of just allocated OFD
2975 * \retval ERR_PTR of return value on error
2977 static struct lu_device *ofd_device_alloc(const struct lu_env *env,
2978 struct lu_device_type *t,
2979 struct lustre_cfg *cfg)
2981 struct ofd_device *m;
2982 struct lu_device *l;
2987 return ERR_PTR(-ENOMEM);
2989 l = &m->ofd_dt_dev.dd_lu_dev;
2990 dt_device_init(&m->ofd_dt_dev, t);
2991 rc = ofd_init0(env, m, t, cfg);
2993 ofd_device_free(env, l);
3000 /* type constructor/destructor: ofd_type_init(), ofd_type_fini() */
3001 LU_TYPE_INIT_FINI(ofd, &ofd_thread_key);
3003 static struct lu_device_type_operations ofd_device_type_ops = {
3004 .ldto_init = ofd_type_init,
3005 .ldto_fini = ofd_type_fini,
3007 .ldto_start = ofd_type_start,
3008 .ldto_stop = ofd_type_stop,
3010 .ldto_device_alloc = ofd_device_alloc,
3011 .ldto_device_free = ofd_device_free,
3012 .ldto_device_fini = ofd_device_fini
3015 static struct lu_device_type ofd_device_type = {
3016 .ldt_tags = LU_DEVICE_DT,
3017 .ldt_name = LUSTRE_OST_NAME,
3018 .ldt_ops = &ofd_device_type_ops,
3019 .ldt_ctx_tags = LCT_DT_THREAD
3023 * Initialize OFD module.
3025 * This function is called upon module loading. It registers OFD device type
3026 * and prepares all in-memory structures used by all OFD devices.
3028 * \retval 0 if successful
3029 * \retval negative value on error
3031 static int __init ofd_init(void)
3035 rc = lu_kmem_init(ofd_caches);
3039 rc = ofd_fmd_init();
3041 lu_kmem_fini(ofd_caches);
3045 rc = class_register_type(&ofd_obd_ops, NULL, true, NULL,
3046 LUSTRE_OST_NAME, &ofd_device_type);
3053 * This function is called upon OFD module unloading.
3054 * It frees all related structures and unregisters OFD device type.
3056 static void __exit ofd_exit(void)
3059 lu_kmem_fini(ofd_caches);
3060 class_unregister_type(LUSTRE_OST_NAME);
3063 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3064 MODULE_DESCRIPTION("Lustre Object Filtering Device");
3065 MODULE_VERSION(LUSTRE_VERSION_STRING);
3066 MODULE_LICENSE("GPL");
3068 module_init(ofd_init);
3069 module_exit(ofd_exit);