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) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LMV
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/pagemap.h>
39 #include <asm/div64.h>
40 #include <linux/seq_file.h>
41 #include <linux/namei.h>
42 #include <linux/uaccess.h>
44 #include "../include/lustre/lustre_idl.h"
45 #include "../include/obd_support.h"
46 #include "../include/lustre_net.h"
47 #include "../include/obd_class.h"
48 #include "../include/lustre_lmv.h"
49 #include "../include/lprocfs_status.h"
50 #include "../include/cl_object.h"
51 #include "../include/lustre_fid.h"
52 #include "../include/lustre/lustre_ioctl.h"
53 #include "../include/lustre_kernelcomm.h"
54 #include "lmv_internal.h"
56 static void lmv_activate_target(struct lmv_obd *lmv,
57 struct lmv_tgt_desc *tgt,
60 if (tgt->ltd_active == activate)
63 tgt->ltd_active = activate;
64 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
70 * -EINVAL : UUID can't be found in the LMV's target list
71 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
72 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
74 static int lmv_set_mdc_active(struct lmv_obd *lmv, const struct obd_uuid *uuid,
77 struct lmv_tgt_desc *uninitialized_var(tgt);
78 struct obd_device *obd;
82 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
83 lmv, uuid->uuid, activate);
85 spin_lock(&lmv->lmv_lock);
86 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
88 if (!tgt || !tgt->ltd_exp)
91 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
92 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
94 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
98 if (i == lmv->desc.ld_tgt_count) {
103 obd = class_exp2obd(tgt->ltd_exp);
109 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
110 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
111 obd->obd_type->typ_name, i);
112 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
114 if (tgt->ltd_active == activate) {
115 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
116 activate ? "" : "in");
120 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
121 activate ? "" : "in");
122 lmv_activate_target(lmv, tgt, activate);
125 spin_unlock(&lmv->lmv_lock);
129 static struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
131 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
132 struct lmv_tgt_desc *tgt = lmv->tgts[0];
134 return tgt ? obd_get_uuid(tgt->ltd_exp) : NULL;
137 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
138 enum obd_notify_event ev, void *data)
140 struct obd_connect_data *conn_data;
141 struct lmv_obd *lmv = &obd->u.lmv;
142 struct obd_uuid *uuid;
145 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
146 CERROR("unexpected notification of %s %s!\n",
147 watched->obd_type->typ_name,
152 uuid = &watched->u.cli.cl_target_uuid;
153 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
155 * Set MDC as active before notifying the observer, so the
156 * observer can use the MDC normally.
158 rc = lmv_set_mdc_active(lmv, uuid,
159 ev == OBD_NOTIFY_ACTIVE);
161 CERROR("%sactivation of %s failed: %d\n",
162 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
166 } else if (ev == OBD_NOTIFY_OCD) {
167 conn_data = &watched->u.cli.cl_import->imp_connect_data;
169 * XXX: Make sure that ocd_connect_flags from all targets are
170 * the same. Otherwise one of MDTs runs wrong version or
171 * something like this. --umka
173 obd->obd_self_export->exp_connect_data = *conn_data;
176 else if (ev == OBD_NOTIFY_DISCON) {
178 * For disconnect event, flush fld cache for failout MDS case.
180 fld_client_flush(&lmv->lmv_fld);
184 * Pass the notification up the chain.
186 if (obd->obd_observer)
187 rc = obd_notify(obd->obd_observer, watched, ev, data);
193 * This is fake connect function. Its purpose is to initialize lmv and say
194 * caller that everything is okay. Real connection will be performed later.
196 static int lmv_connect(const struct lu_env *env,
197 struct obd_export **exp, struct obd_device *obd,
198 struct obd_uuid *cluuid, struct obd_connect_data *data,
201 struct lmv_obd *lmv = &obd->u.lmv;
202 struct lustre_handle conn = { 0 };
206 * We don't want to actually do the underlying connections more than
207 * once, so keep track.
210 if (lmv->refcount > 1) {
215 rc = class_connect(&conn, obd, cluuid);
217 CERROR("class_connection() returned %d\n", rc);
221 *exp = class_conn2export(&conn);
222 class_export_get(*exp);
226 lmv->cluuid = *cluuid;
229 lmv->conn_data = *data;
231 lmv->lmv_tgts_kobj = kobject_create_and_add("target_obds",
234 * All real clients should perform actual connection right away, because
235 * it is possible, that LMV will not have opportunity to connect targets
236 * and MDC stuff will be called directly, for instance while reading
237 * ../mdc/../kbytesfree procfs file, etc.
239 if (data && data->ocd_connect_flags & OBD_CONNECT_REAL)
240 rc = lmv_check_connect(obd);
242 if (rc && lmv->lmv_tgts_kobj)
243 kobject_put(lmv->lmv_tgts_kobj);
248 static int lmv_init_ea_size(struct obd_export *exp, u32 easize, u32 def_easize,
249 u32 cookiesize, u32 def_cookiesize)
251 struct obd_device *obd = exp->exp_obd;
252 struct lmv_obd *lmv = &obd->u.lmv;
257 if (lmv->max_easize < easize) {
258 lmv->max_easize = easize;
261 if (lmv->max_def_easize < def_easize) {
262 lmv->max_def_easize = def_easize;
265 if (lmv->max_cookiesize < cookiesize) {
266 lmv->max_cookiesize = cookiesize;
269 if (lmv->max_def_cookiesize < def_cookiesize) {
270 lmv->max_def_cookiesize = def_cookiesize;
276 if (lmv->connected == 0)
279 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
280 struct lmv_tgt_desc *tgt = lmv->tgts[i];
282 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
283 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
287 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
288 cookiesize, def_cookiesize);
290 CERROR("%s: obd_init_ea_size() failed on MDT target %d: rc = %d\n",
291 obd->obd_name, i, rc);
298 #define MAX_STRING_SIZE 128
300 static int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
302 struct lmv_obd *lmv = &obd->u.lmv;
303 struct obd_uuid *cluuid = &lmv->cluuid;
304 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
305 struct obd_device *mdc_obd;
306 struct obd_export *mdc_exp;
307 struct lu_fld_target target;
310 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
313 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
317 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
318 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
319 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid, cluuid->uuid);
321 if (!mdc_obd->obd_set_up) {
322 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
326 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
327 &lmv->conn_data, NULL);
329 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
334 * Init fid sequence client for this mdc and add new fld target.
336 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
340 target.ft_srv = NULL;
341 target.ft_exp = mdc_exp;
342 target.ft_idx = tgt->ltd_idx;
344 fld_client_add_target(&lmv->lmv_fld, &target);
346 rc = obd_register_observer(mdc_obd, obd);
348 obd_disconnect(mdc_exp);
349 CERROR("target %s register_observer error %d\n",
350 tgt->ltd_uuid.uuid, rc);
354 if (obd->obd_observer) {
356 * Tell the observer about the new target.
358 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
360 (void *)(tgt - lmv->tgts[0]));
362 obd_disconnect(mdc_exp);
368 tgt->ltd_exp = mdc_exp;
369 lmv->desc.ld_active_tgt_count++;
371 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize,
372 lmv->max_cookiesize, lmv->max_def_cookiesize);
374 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
375 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
376 atomic_read(&obd->obd_refcount));
378 if (lmv->lmv_tgts_kobj)
379 /* Even if we failed to create the link, that's fine */
380 rc = sysfs_create_link(lmv->lmv_tgts_kobj, &mdc_obd->obd_kobj,
385 static void lmv_del_target(struct lmv_obd *lmv, int index)
387 if (!lmv->tgts[index])
390 kfree(lmv->tgts[index]);
391 lmv->tgts[index] = NULL;
395 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
396 __u32 index, int gen)
398 struct lmv_obd *lmv = &obd->u.lmv;
399 struct lmv_tgt_desc *tgt;
400 int orig_tgt_count = 0;
403 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
405 mutex_lock(&lmv->lmv_init_mutex);
407 if (lmv->desc.ld_tgt_count == 0) {
408 struct obd_device *mdc_obd;
410 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
413 mutex_unlock(&lmv->lmv_init_mutex);
414 CERROR("%s: Target %s not attached: rc = %d\n",
415 obd->obd_name, uuidp->uuid, -EINVAL);
420 if ((index < lmv->tgts_size) && lmv->tgts[index]) {
421 tgt = lmv->tgts[index];
422 CERROR("%s: UUID %s already assigned at LOV target index %d: rc = %d\n",
424 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
425 mutex_unlock(&lmv->lmv_init_mutex);
429 if (index >= lmv->tgts_size) {
430 /* We need to reallocate the lmv target array. */
431 struct lmv_tgt_desc **newtgts, **old = NULL;
435 while (newsize < index + 1)
437 newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS);
439 mutex_unlock(&lmv->lmv_init_mutex);
443 if (lmv->tgts_size) {
444 memcpy(newtgts, lmv->tgts,
445 sizeof(*newtgts) * lmv->tgts_size);
447 oldsize = lmv->tgts_size;
451 lmv->tgts_size = newsize;
455 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
459 tgt = kzalloc(sizeof(*tgt), GFP_NOFS);
461 mutex_unlock(&lmv->lmv_init_mutex);
465 mutex_init(&tgt->ltd_fid_mutex);
466 tgt->ltd_idx = index;
467 tgt->ltd_uuid = *uuidp;
469 lmv->tgts[index] = tgt;
470 if (index >= lmv->desc.ld_tgt_count) {
471 orig_tgt_count = lmv->desc.ld_tgt_count;
472 lmv->desc.ld_tgt_count = index + 1;
475 if (lmv->connected) {
476 rc = lmv_connect_mdc(obd, tgt);
478 spin_lock(&lmv->lmv_lock);
479 if (lmv->desc.ld_tgt_count == index + 1)
480 lmv->desc.ld_tgt_count = orig_tgt_count;
481 memset(tgt, 0, sizeof(*tgt));
482 spin_unlock(&lmv->lmv_lock);
484 int easize = sizeof(struct lmv_stripe_md) +
485 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
486 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
490 mutex_unlock(&lmv->lmv_init_mutex);
494 int lmv_check_connect(struct obd_device *obd)
496 struct lmv_obd *lmv = &obd->u.lmv;
497 struct lmv_tgt_desc *tgt;
505 mutex_lock(&lmv->lmv_init_mutex);
506 if (lmv->connected) {
507 mutex_unlock(&lmv->lmv_init_mutex);
511 if (lmv->desc.ld_tgt_count == 0) {
512 mutex_unlock(&lmv->lmv_init_mutex);
513 CERROR("%s: no targets configured.\n", obd->obd_name);
520 mutex_unlock(&lmv->lmv_init_mutex);
521 CERROR("%s: no target configured for index 0.\n",
526 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
527 lmv->cluuid.uuid, obd->obd_name);
529 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
533 rc = lmv_connect_mdc(obd, tgt);
538 class_export_put(lmv->exp);
540 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
541 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
542 mutex_unlock(&lmv->lmv_init_mutex);
554 --lmv->desc.ld_active_tgt_count;
555 rc2 = obd_disconnect(tgt->ltd_exp);
557 CERROR("LMV target %s disconnect on MDC idx %d: error %d\n",
558 tgt->ltd_uuid.uuid, i, rc2);
562 class_disconnect(lmv->exp);
563 mutex_unlock(&lmv->lmv_init_mutex);
567 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
569 struct lmv_obd *lmv = &obd->u.lmv;
570 struct obd_device *mdc_obd;
573 mdc_obd = class_exp2obd(tgt->ltd_exp);
576 mdc_obd->obd_force = obd->obd_force;
577 mdc_obd->obd_fail = obd->obd_fail;
578 mdc_obd->obd_no_recov = obd->obd_no_recov;
580 if (lmv->lmv_tgts_kobj)
581 sysfs_remove_link(lmv->lmv_tgts_kobj,
585 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
587 CERROR("Can't finalize fids factory\n");
589 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
590 tgt->ltd_exp->exp_obd->obd_name,
591 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
593 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
594 rc = obd_disconnect(tgt->ltd_exp);
596 if (tgt->ltd_active) {
597 CERROR("Target %s disconnect error %d\n",
598 tgt->ltd_uuid.uuid, rc);
602 lmv_activate_target(lmv, tgt, 0);
607 static int lmv_disconnect(struct obd_export *exp)
609 struct obd_device *obd = class_exp2obd(exp);
610 struct lmv_obd *lmv = &obd->u.lmv;
618 * Only disconnect the underlying layers on the final disconnect.
621 if (lmv->refcount != 0)
624 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
625 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
628 lmv_disconnect_mdc(obd, lmv->tgts[i]);
631 if (lmv->lmv_tgts_kobj)
632 kobject_put(lmv->lmv_tgts_kobj);
636 * This is the case when no real connection is established by
637 * lmv_check_connect().
640 class_export_put(exp);
641 rc = class_disconnect(exp);
642 if (lmv->refcount == 0)
647 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
650 struct obd_device *obddev = class_exp2obd(exp);
651 struct lmv_obd *lmv = &obddev->u.lmv;
652 struct getinfo_fid2path *gf;
653 struct lmv_tgt_desc *tgt;
654 struct getinfo_fid2path *remote_gf = NULL;
655 int remote_gf_size = 0;
658 gf = (struct getinfo_fid2path *)karg;
659 tgt = lmv_find_target(lmv, &gf->gf_fid);
664 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
665 if (rc != 0 && rc != -EREMOTE)
668 /* If remote_gf != NULL, it means just building the
669 * path on the remote MDT, copy this path segment to gf
672 struct getinfo_fid2path *ori_gf;
675 ori_gf = (struct getinfo_fid2path *)karg;
676 if (strlen(ori_gf->gf_path) +
677 strlen(gf->gf_path) > ori_gf->gf_pathlen) {
682 ptr = ori_gf->gf_path;
684 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
685 strlen(ori_gf->gf_path));
687 strcpy(ptr, gf->gf_path);
688 ptr += strlen(gf->gf_path);
692 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
693 tgt->ltd_exp->exp_obd->obd_name,
694 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
700 /* sigh, has to go to another MDT to do path building further */
702 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
703 remote_gf = kzalloc(remote_gf_size, GFP_NOFS);
708 remote_gf->gf_pathlen = PATH_MAX;
711 if (!fid_is_sane(&gf->gf_fid)) {
712 CERROR("%s: invalid FID "DFID": rc = %d\n",
713 tgt->ltd_exp->exp_obd->obd_name,
714 PFID(&gf->gf_fid), -EINVAL);
719 tgt = lmv_find_target(lmv, &gf->gf_fid);
725 remote_gf->gf_fid = gf->gf_fid;
726 remote_gf->gf_recno = -1;
727 remote_gf->gf_linkno = -1;
728 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
730 goto repeat_fid2path;
737 static int lmv_hsm_req_count(struct lmv_obd *lmv,
738 const struct hsm_user_request *hur,
739 const struct lmv_tgt_desc *tgt_mds)
742 struct lmv_tgt_desc *curr_tgt;
744 /* count how many requests must be sent to the given target */
745 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
746 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
747 if (IS_ERR(curr_tgt))
748 return PTR_ERR(curr_tgt);
749 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
755 static int lmv_hsm_req_build(struct lmv_obd *lmv,
756 struct hsm_user_request *hur_in,
757 const struct lmv_tgt_desc *tgt_mds,
758 struct hsm_user_request *hur_out)
761 struct lmv_tgt_desc *curr_tgt;
763 /* build the hsm_user_request for the given target */
764 hur_out->hur_request = hur_in->hur_request;
766 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
767 curr_tgt = lmv_find_target(lmv,
768 &hur_in->hur_user_item[i].hui_fid);
769 if (IS_ERR(curr_tgt))
770 return PTR_ERR(curr_tgt);
771 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
772 hur_out->hur_user_item[nr_out] =
773 hur_in->hur_user_item[i];
777 hur_out->hur_request.hr_itemcount = nr_out;
778 memcpy(hur_data(hur_out), hur_data(hur_in),
779 hur_in->hur_request.hr_data_len);
784 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
785 struct lustre_kernelcomm *lk,
791 /* unregister request (call from llapi_hsm_copytool_fini) */
792 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
793 struct lmv_tgt_desc *tgt = lmv->tgts[i];
795 if (!tgt || !tgt->ltd_exp)
798 /* best effort: try to clean as much as possible
799 * (continue on error)
801 obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, lk, uarg);
804 /* Whatever the result, remove copytool from kuc groups.
805 * Unreached coordinators will get EPIPE on next requests
806 * and will unregister automatically.
808 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
813 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
814 struct lustre_kernelcomm *lk, void __user *uarg)
819 bool any_set = false;
820 struct kkuc_ct_data kcd = { 0 };
822 /* All or nothing: try to register to all MDS.
823 * In case of failure, unregister from previous MDS,
824 * except if it because of inactive target.
826 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
827 struct lmv_tgt_desc *tgt = lmv->tgts[i];
829 if (!tgt || !tgt->ltd_exp)
832 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
834 if (tgt->ltd_active) {
835 /* permanent error */
836 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
837 tgt->ltd_uuid.uuid, i, cmd, err);
839 lk->lk_flags |= LK_FLG_STOP;
840 /* unregister from previous MDS */
841 for (j = 0; j < i; j++) {
844 if (!tgt || !tgt->ltd_exp)
846 obd_iocontrol(cmd, tgt->ltd_exp, len,
851 /* else: transient error.
852 * kuc will register to the missing MDT when it is back
860 /* no registration done: return error */
863 /* at least one registration done, with no failure */
864 filp = fget(lk->lk_wfd);
868 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
869 kcd.kcd_uuid = lmv->cluuid;
870 kcd.kcd_archive = lk->lk_data;
872 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
880 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
881 int len, void *karg, void __user *uarg)
883 struct obd_device *obddev = class_exp2obd(exp);
884 struct lmv_obd *lmv = &obddev->u.lmv;
885 struct lmv_tgt_desc *tgt = NULL;
889 u32 count = lmv->desc.ld_tgt_count;
895 case IOC_OBD_STATFS: {
896 struct obd_ioctl_data *data = karg;
897 struct obd_device *mdc_obd;
898 struct obd_statfs stat_buf = {0};
901 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
905 tgt = lmv->tgts[index];
906 if (!tgt || !tgt->ltd_active)
909 mdc_obd = class_exp2obd(tgt->ltd_exp);
914 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
915 min((int)data->ioc_plen2,
916 (int)sizeof(struct obd_uuid))))
919 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
920 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
924 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
925 min((int)data->ioc_plen1,
926 (int)sizeof(stat_buf))))
930 case OBD_IOC_QUOTACTL: {
931 struct if_quotactl *qctl = karg;
932 struct obd_quotactl *oqctl;
934 if (qctl->qc_valid == QC_MDTIDX) {
935 if (count <= qctl->qc_idx)
938 tgt = lmv->tgts[qctl->qc_idx];
939 if (!tgt || !tgt->ltd_exp)
941 } else if (qctl->qc_valid == QC_UUID) {
942 for (i = 0; i < count; i++) {
946 if (!obd_uuid_equals(&tgt->ltd_uuid,
962 LASSERT(tgt && tgt->ltd_exp);
963 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
967 QCTL_COPY(oqctl, qctl);
968 rc = obd_quotactl(tgt->ltd_exp, oqctl);
970 QCTL_COPY(qctl, oqctl);
971 qctl->qc_valid = QC_MDTIDX;
972 qctl->obd_uuid = tgt->ltd_uuid;
977 case OBD_IOC_CHANGELOG_SEND:
978 case OBD_IOC_CHANGELOG_CLEAR: {
979 struct ioc_changelog *icc = karg;
981 if (icc->icc_mdtindex >= count)
984 tgt = lmv->tgts[icc->icc_mdtindex];
985 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
987 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
990 case LL_IOC_GET_CONNECT_FLAGS: {
993 if (!tgt || !tgt->ltd_exp)
995 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
998 case LL_IOC_FID2MDTIDX: {
999 struct lu_fid *fid = karg;
1002 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1007 * Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1008 * point to user space memory for FID2MDTIDX.
1010 *(__u32 *)uarg = mdt_index;
1013 case OBD_IOC_FID2PATH: {
1014 rc = lmv_fid2path(exp, len, karg, uarg);
1017 case LL_IOC_HSM_STATE_GET:
1018 case LL_IOC_HSM_STATE_SET:
1019 case LL_IOC_HSM_ACTION: {
1020 struct md_op_data *op_data = karg;
1022 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1024 return PTR_ERR(tgt);
1029 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1032 case LL_IOC_HSM_PROGRESS: {
1033 const struct hsm_progress_kernel *hpk = karg;
1035 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1037 return PTR_ERR(tgt);
1038 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1041 case LL_IOC_HSM_REQUEST: {
1042 struct hsm_user_request *hur = karg;
1043 unsigned int reqcount = hur->hur_request.hr_itemcount;
1048 /* if the request is about a single fid
1049 * or if there is a single MDS, no need to split
1052 if (reqcount == 1 || count == 1) {
1053 tgt = lmv_find_target(lmv,
1054 &hur->hur_user_item[0].hui_fid);
1056 return PTR_ERR(tgt);
1057 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1059 /* split fid list to their respective MDS */
1060 for (i = 0; i < count; i++) {
1061 struct hsm_user_request *req;
1066 if (!tgt || !tgt->ltd_exp)
1069 nr = lmv_hsm_req_count(lmv, hur, tgt);
1072 if (nr == 0) /* nothing for this MDS */
1075 /* build a request with fids for this MDS */
1076 reqlen = offsetof(typeof(*hur),
1078 + hur->hur_request.hr_data_len;
1079 req = libcfs_kvzalloc(reqlen, GFP_NOFS);
1083 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1087 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1090 if (rc1 != 0 && rc == 0)
1097 case LL_IOC_LOV_SWAP_LAYOUTS: {
1098 struct md_op_data *op_data = karg;
1099 struct lmv_tgt_desc *tgt1, *tgt2;
1101 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1103 return PTR_ERR(tgt1);
1105 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1107 return PTR_ERR(tgt2);
1109 if (!tgt1->ltd_exp || !tgt2->ltd_exp)
1112 /* only files on same MDT can have their layouts swapped */
1113 if (tgt1->ltd_idx != tgt2->ltd_idx)
1116 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1119 case LL_IOC_HSM_CT_START: {
1120 struct lustre_kernelcomm *lk = karg;
1122 if (lk->lk_flags & LK_FLG_STOP)
1123 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1125 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1129 for (i = 0; i < count; i++) {
1130 struct obd_device *mdc_obd;
1134 if (!tgt || !tgt->ltd_exp)
1136 /* ll_umount_begin() sets force flag but for lmv, not
1137 * mdc. Let's pass it through
1139 mdc_obd = class_exp2obd(tgt->ltd_exp);
1140 mdc_obd->obd_force = obddev->obd_force;
1141 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1142 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1145 if (tgt->ltd_active) {
1146 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
1147 tgt->ltd_uuid.uuid, i, cmd, err);
1162 * This is _inode_ placement policy function (not name).
1164 static int lmv_placement_policy(struct obd_device *obd,
1165 struct md_op_data *op_data, u32 *mds)
1167 struct lmv_obd *lmv = &obd->u.lmv;
1171 if (lmv->desc.ld_tgt_count == 1) {
1176 if (op_data->op_default_stripe_offset != -1) {
1177 *mds = op_data->op_default_stripe_offset;
1182 * If stripe_offset is provided during setdirstripe
1183 * (setdirstripe -i xx), xx MDS will be chosen.
1185 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data) {
1186 struct lmv_user_md *lum;
1188 lum = op_data->op_data;
1189 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1190 *mds = le32_to_cpu(lum->lum_stripe_offset);
1193 * -1 means default, which will be in the same MDT with
1196 *mds = op_data->op_mds;
1197 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1201 * Allocate new fid on target according to operation type and
1204 *mds = op_data->op_mds;
1210 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1212 struct lmv_tgt_desc *tgt;
1215 tgt = lmv_get_target(lmv, mds, NULL);
1217 return PTR_ERR(tgt);
1220 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1221 * on server that seq in new allocated fid is not yet known.
1223 mutex_lock(&tgt->ltd_fid_mutex);
1225 if (tgt->ltd_active == 0 || !tgt->ltd_exp) {
1231 * Asking underlaying tgt layer to allocate new fid.
1233 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1235 LASSERT(fid_is_sane(fid));
1240 mutex_unlock(&tgt->ltd_fid_mutex);
1244 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1245 struct lu_fid *fid, struct md_op_data *op_data)
1247 struct obd_device *obd = class_exp2obd(exp);
1248 struct lmv_obd *lmv = &obd->u.lmv;
1255 rc = lmv_placement_policy(obd, op_data, &mds);
1257 CERROR("Can't get target for allocating fid, rc %d\n",
1262 rc = __lmv_fid_alloc(lmv, fid, mds);
1264 CERROR("Can't alloc new fid, rc %d\n", rc);
1271 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1273 struct lmv_obd *lmv = &obd->u.lmv;
1274 struct lprocfs_static_vars lvars = { NULL };
1275 struct lmv_desc *desc;
1278 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1279 CERROR("LMV setup requires a descriptor\n");
1283 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1284 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1285 CERROR("Lmv descriptor size wrong: %d > %d\n",
1286 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1290 lmv->tgts_size = 32U;
1291 lmv->tgts = kcalloc(lmv->tgts_size, sizeof(*lmv->tgts), GFP_NOFS);
1295 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1296 lmv->desc.ld_tgt_count = 0;
1297 lmv->desc.ld_active_tgt_count = 0;
1298 lmv->max_cookiesize = 0;
1299 lmv->max_def_easize = 0;
1300 lmv->max_easize = 0;
1301 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1303 spin_lock_init(&lmv->lmv_lock);
1304 mutex_init(&lmv->lmv_init_mutex);
1306 lprocfs_lmv_init_vars(&lvars);
1308 lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
1309 rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "target_obd",
1310 0444, &lmv_proc_target_fops, obd);
1312 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1314 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1315 LUSTRE_CLI_FLD_HASH_DHT);
1317 CERROR("Can't init FLD, err %d\n", rc);
1327 static int lmv_cleanup(struct obd_device *obd)
1329 struct lmv_obd *lmv = &obd->u.lmv;
1331 fld_client_fini(&lmv->lmv_fld);
1335 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1338 lmv_del_target(lmv, i);
1346 static int lmv_process_config(struct obd_device *obd, u32 len, void *buf)
1348 struct lustre_cfg *lcfg = buf;
1349 struct obd_uuid obd_uuid;
1354 switch (lcfg->lcfg_command) {
1356 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1357 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID
1359 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) {
1364 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1366 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1) {
1370 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) {
1374 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1377 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1385 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1386 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1388 struct obd_device *obd = class_exp2obd(exp);
1389 struct lmv_obd *lmv = &obd->u.lmv;
1390 struct obd_statfs *temp;
1394 rc = lmv_check_connect(obd);
1398 temp = kzalloc(sizeof(*temp), GFP_NOFS);
1402 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1403 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1406 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1409 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1410 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1417 /* If the statfs is from mount, it will needs
1418 * retrieve necessary information from MDT0.
1419 * i.e. mount does not need the merged osfs
1421 * And also clients can be mounted as long as
1422 * MDT0 is in service
1424 if (flags & OBD_STATFS_FOR_MDT0)
1427 osfs->os_bavail += temp->os_bavail;
1428 osfs->os_blocks += temp->os_blocks;
1429 osfs->os_ffree += temp->os_ffree;
1430 osfs->os_files += temp->os_files;
1439 static int lmv_getstatus(struct obd_export *exp,
1442 struct obd_device *obd = exp->exp_obd;
1443 struct lmv_obd *lmv = &obd->u.lmv;
1446 rc = lmv_check_connect(obd);
1450 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid);
1454 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1455 u64 valid, const char *name,
1456 const char *input, int input_size, int output_size,
1457 int flags, struct ptlrpc_request **request)
1459 struct obd_device *obd = exp->exp_obd;
1460 struct lmv_obd *lmv = &obd->u.lmv;
1461 struct lmv_tgt_desc *tgt;
1464 rc = lmv_check_connect(obd);
1468 tgt = lmv_find_target(lmv, fid);
1470 return PTR_ERR(tgt);
1472 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1473 input_size, output_size, flags, request);
1478 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1479 u64 valid, const char *name,
1480 const char *input, int input_size, int output_size,
1481 int flags, __u32 suppgid,
1482 struct ptlrpc_request **request)
1484 struct obd_device *obd = exp->exp_obd;
1485 struct lmv_obd *lmv = &obd->u.lmv;
1486 struct lmv_tgt_desc *tgt;
1489 rc = lmv_check_connect(obd);
1493 tgt = lmv_find_target(lmv, fid);
1495 return PTR_ERR(tgt);
1497 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1498 input_size, output_size, flags, suppgid,
1504 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1505 struct ptlrpc_request **request)
1507 struct obd_device *obd = exp->exp_obd;
1508 struct lmv_obd *lmv = &obd->u.lmv;
1509 struct lmv_tgt_desc *tgt;
1512 rc = lmv_check_connect(obd);
1516 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1518 return PTR_ERR(tgt);
1520 if (op_data->op_flags & MF_GET_MDT_IDX) {
1521 op_data->op_mds = tgt->ltd_idx;
1525 rc = md_getattr(tgt->ltd_exp, op_data, request);
1530 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1532 struct obd_device *obd = exp->exp_obd;
1533 struct lmv_obd *lmv = &obd->u.lmv;
1537 rc = lmv_check_connect(obd);
1541 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1544 * With DNE every object can have two locks in different namespaces:
1545 * lookup lock in space of MDT storing direntry and update/open lock in
1546 * space of MDT storing inode.
1548 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1549 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1551 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1557 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1558 struct md_open_data *mod, struct ptlrpc_request **request)
1560 struct obd_device *obd = exp->exp_obd;
1561 struct lmv_obd *lmv = &obd->u.lmv;
1562 struct lmv_tgt_desc *tgt;
1565 rc = lmv_check_connect(obd);
1569 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1571 return PTR_ERR(tgt);
1573 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1574 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1579 * Choosing the MDT by name or FID in @op_data.
1580 * For non-striped directory, it will locate MDT by fid.
1581 * For striped-directory, it will locate MDT by name. And also
1582 * it will reset op_fid1 with the FID of the chosen stripe.
1584 static struct lmv_tgt_desc *
1585 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1586 const char *name, int namelen, struct lu_fid *fid,
1589 const struct lmv_oinfo *oinfo;
1590 struct lmv_tgt_desc *tgt;
1592 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1593 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1594 return ERR_PTR(-EBADF);
1595 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1597 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1599 return ERR_CAST(oinfo);
1603 *fid = oinfo->lmo_fid;
1605 *mds = oinfo->lmo_mds;
1607 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1609 CDEBUG(D_INFO, "locate on mds %u " DFID "\n", oinfo->lmo_mds,
1610 PFID(&oinfo->lmo_fid));
1615 * Locate mds by fid or name
1617 * For striped directory (lsm != NULL), it will locate the stripe
1618 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1619 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1620 * walk through all of stripes to locate the entry.
1622 * For normal direcotry, it will locate MDS by FID directly.
1623 * \param[in] lmv LMV device
1624 * \param[in] op_data client MD stack parameters, name, namelen
1626 * \param[in] fid object FID used to locate MDS.
1628 * retval pointer to the lmv_tgt_desc if succeed.
1629 * ERR_PTR(errno) if failed.
1631 struct lmv_tgt_desc*
1632 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1635 struct lmv_stripe_md *lsm = op_data->op_mea1;
1636 struct lmv_tgt_desc *tgt;
1639 * During creating VOLATILE file, it should honor the mdt
1640 * index if the file under striped dir is being restored, see
1643 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1644 (int)op_data->op_mds != -1 && lsm) {
1647 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1651 /* refill the right parent fid */
1652 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1653 struct lmv_oinfo *oinfo;
1655 oinfo = &lsm->lsm_md_oinfo[i];
1656 if (oinfo->lmo_mds == op_data->op_mds) {
1657 *fid = oinfo->lmo_fid;
1662 /* Hmm, can not find the stripe by mdt_index(op_mds) */
1663 if (i == lsm->lsm_md_stripe_count)
1664 tgt = ERR_PTR(-EINVAL);
1669 if (!lsm || !op_data->op_namelen) {
1670 tgt = lmv_find_target(lmv, fid);
1674 op_data->op_mds = tgt->ltd_idx;
1679 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1680 op_data->op_namelen, fid,
1684 static int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1685 const void *data, size_t datalen, umode_t mode,
1686 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1687 __u64 rdev, struct ptlrpc_request **request)
1689 struct obd_device *obd = exp->exp_obd;
1690 struct lmv_obd *lmv = &obd->u.lmv;
1691 struct lmv_tgt_desc *tgt;
1694 rc = lmv_check_connect(obd);
1698 if (!lmv->desc.ld_active_tgt_count)
1701 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1703 return PTR_ERR(tgt);
1705 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1706 (int)op_data->op_namelen, op_data->op_name,
1707 PFID(&op_data->op_fid1), op_data->op_mds);
1709 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1713 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1715 * Send the create request to the MDT where the object
1718 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1720 return PTR_ERR(tgt);
1722 op_data->op_mds = tgt->ltd_idx;
1724 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1727 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1728 PFID(&op_data->op_fid1), op_data->op_mds);
1730 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1731 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1732 cap_effective, rdev, request);
1737 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1742 static int lmv_done_writing(struct obd_export *exp,
1743 struct md_op_data *op_data,
1744 struct md_open_data *mod)
1746 struct obd_device *obd = exp->exp_obd;
1747 struct lmv_obd *lmv = &obd->u.lmv;
1748 struct lmv_tgt_desc *tgt;
1751 rc = lmv_check_connect(obd);
1755 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1757 return PTR_ERR(tgt);
1759 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1764 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1765 const ldlm_policy_data_t *policy,
1766 struct lookup_intent *it, struct md_op_data *op_data,
1767 struct lustre_handle *lockh, __u64 extra_lock_flags)
1769 struct obd_device *obd = exp->exp_obd;
1770 struct lmv_obd *lmv = &obd->u.lmv;
1771 struct lmv_tgt_desc *tgt;
1774 rc = lmv_check_connect(obd);
1778 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1779 LL_IT2STR(it), PFID(&op_data->op_fid1));
1781 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1783 return PTR_ERR(tgt);
1785 CDEBUG(D_INODE, "ENQUEUE '%s' on " DFID " -> mds #%u\n",
1786 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1788 rc = md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh,
1795 lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
1796 struct ptlrpc_request **preq)
1798 struct ptlrpc_request *req = NULL;
1799 struct obd_device *obd = exp->exp_obd;
1800 struct lmv_obd *lmv = &obd->u.lmv;
1801 struct lmv_tgt_desc *tgt;
1802 struct mdt_body *body;
1805 rc = lmv_check_connect(obd);
1809 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1811 return PTR_ERR(tgt);
1813 CDEBUG(D_INODE, "GETATTR_NAME for %*s on " DFID " -> mds #%u\n",
1814 (int)op_data->op_namelen, op_data->op_name,
1815 PFID(&op_data->op_fid1), tgt->ltd_idx);
1817 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1821 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1822 if (body->mbo_valid & OBD_MD_MDS) {
1823 struct lu_fid rid = body->mbo_fid1;
1825 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1828 tgt = lmv_find_target(lmv, &rid);
1830 ptlrpc_req_finished(*preq);
1832 return PTR_ERR(tgt);
1835 op_data->op_fid1 = rid;
1836 op_data->op_valid |= OBD_MD_FLCROSSREF;
1837 op_data->op_namelen = 0;
1838 op_data->op_name = NULL;
1839 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1840 ptlrpc_req_finished(*preq);
1847 #define md_op_data_fid(op_data, fl) \
1848 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1849 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1850 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1851 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1854 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1855 struct md_op_data *op_data, int op_tgt,
1856 enum ldlm_mode mode, int bits, int flag)
1858 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1859 struct obd_device *obd = exp->exp_obd;
1860 struct lmv_obd *lmv = &obd->u.lmv;
1861 ldlm_policy_data_t policy = { {0} };
1864 if (!fid_is_sane(fid))
1868 tgt = lmv_find_target(lmv, fid);
1870 return PTR_ERR(tgt);
1873 if (tgt->ltd_idx != op_tgt) {
1874 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1875 policy.l_inodebits.bits = bits;
1876 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1877 mode, LCF_ASYNC, NULL);
1880 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1882 op_data->op_flags |= flag;
1890 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1893 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1894 struct ptlrpc_request **request)
1896 struct obd_device *obd = exp->exp_obd;
1897 struct lmv_obd *lmv = &obd->u.lmv;
1898 struct lmv_tgt_desc *tgt;
1901 rc = lmv_check_connect(obd);
1905 LASSERT(op_data->op_namelen != 0);
1907 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1908 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1909 op_data->op_name, PFID(&op_data->op_fid1));
1911 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1912 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1913 op_data->op_cap = cfs_curproc_cap_pack();
1914 if (op_data->op_mea2) {
1915 struct lmv_stripe_md *lsm = op_data->op_mea2;
1916 const struct lmv_oinfo *oinfo;
1918 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1919 op_data->op_namelen);
1921 return PTR_ERR(oinfo);
1923 op_data->op_fid2 = oinfo->lmo_fid;
1926 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1928 return PTR_ERR(tgt);
1931 * Cancel UPDATE lock on child (fid1).
1933 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1934 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1935 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1939 rc = md_link(tgt->ltd_exp, op_data, request);
1944 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1945 const char *old, size_t oldlen,
1946 const char *new, size_t newlen,
1947 struct ptlrpc_request **request)
1949 struct obd_device *obd = exp->exp_obd;
1950 struct lmv_obd *lmv = &obd->u.lmv;
1951 struct lmv_tgt_desc *src_tgt;
1954 LASSERT(oldlen != 0);
1956 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1957 (int)oldlen, old, PFID(&op_data->op_fid1),
1958 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1959 (int)newlen, new, PFID(&op_data->op_fid2),
1960 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1962 rc = lmv_check_connect(obd);
1966 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1967 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1968 op_data->op_cap = cfs_curproc_cap_pack();
1970 if (op_data->op_cli_flags & CLI_MIGRATE) {
1971 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1972 PFID(&op_data->op_fid3));
1974 if (op_data->op_mea1) {
1975 struct lmv_stripe_md *lsm = op_data->op_mea1;
1976 struct lmv_tgt_desc *tmp;
1978 /* Fix the parent fid for striped dir */
1979 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1984 return PTR_ERR(tmp);
1987 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1990 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1992 if (op_data->op_mea1) {
1993 struct lmv_stripe_md *lsm = op_data->op_mea1;
1995 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1999 if (IS_ERR(src_tgt))
2000 return PTR_ERR(src_tgt);
2002 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2003 if (IS_ERR(src_tgt))
2004 return PTR_ERR(src_tgt);
2006 op_data->op_mds = src_tgt->ltd_idx;
2009 if (op_data->op_mea2) {
2010 struct lmv_stripe_md *lsm = op_data->op_mea2;
2011 const struct lmv_oinfo *oinfo;
2013 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2015 return PTR_ERR(oinfo);
2017 op_data->op_fid2 = oinfo->lmo_fid;
2020 if (IS_ERR(src_tgt))
2021 return PTR_ERR(src_tgt);
2024 * LOOKUP lock on src child (fid3) should also be cancelled for
2025 * src_tgt in mdc_rename.
2027 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2030 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2033 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2034 LCK_EX, MDS_INODELOCK_UPDATE,
2035 MF_MDC_CANCEL_FID2);
2039 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
2041 if (fid_is_sane(&op_data->op_fid3)) {
2042 struct lmv_tgt_desc *tgt;
2044 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2046 return PTR_ERR(tgt);
2048 /* Cancel LOOKUP lock on its parent */
2049 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2050 LCK_EX, MDS_INODELOCK_LOOKUP,
2051 MF_MDC_CANCEL_FID3);
2055 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2056 LCK_EX, MDS_INODELOCK_FULL,
2057 MF_MDC_CANCEL_FID3);
2063 * Cancel all the locks on tgt child (fid4).
2065 if (fid_is_sane(&op_data->op_fid4))
2066 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2067 LCK_EX, MDS_INODELOCK_FULL,
2068 MF_MDC_CANCEL_FID4);
2070 CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
2071 op_data->op_mds, PFID(&op_data->op_fid2));
2073 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
2074 new, newlen, request);
2078 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2079 void *ea, size_t ealen, void *ea2, size_t ea2len,
2080 struct ptlrpc_request **request,
2081 struct md_open_data **mod)
2083 struct obd_device *obd = exp->exp_obd;
2084 struct lmv_obd *lmv = &obd->u.lmv;
2085 struct lmv_tgt_desc *tgt;
2088 rc = lmv_check_connect(obd);
2092 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2093 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2095 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2096 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2098 return PTR_ERR(tgt);
2100 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2101 ea2len, request, mod);
2106 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2107 struct ptlrpc_request **request)
2109 struct obd_device *obd = exp->exp_obd;
2110 struct lmv_obd *lmv = &obd->u.lmv;
2111 struct lmv_tgt_desc *tgt;
2114 rc = lmv_check_connect(obd);
2118 tgt = lmv_find_target(lmv, fid);
2120 return PTR_ERR(tgt);
2122 rc = md_sync(tgt->ltd_exp, fid, request);
2127 * Get current minimum entry from striped directory
2129 * This function will search the dir entry, whose hash value is the
2130 * closest(>=) to @hash_offset, from all of sub-stripes, and it is
2131 * only being called for striped directory.
2133 * \param[in] exp export of LMV
2134 * \param[in] op_data parameters transferred beween client MD stack
2135 * stripe_information will be included in this
2137 * \param[in] cb_op ldlm callback being used in enqueue in
2139 * \param[in] hash_offset the hash value, which is used to locate
2140 * minum(closet) dir entry
2141 * \param[in|out] stripe_offset the caller use this to indicate the stripe
2142 * index of last entry, so to avoid hash conflict
2143 * between stripes. It will also be used to
2144 * return the stripe index of current dir entry.
2145 * \param[in|out] entp the minum entry and it also is being used
2146 * to input the last dir entry to resolve the
2149 * \param[out] ppage the page which holds the minum entry
2151 * \retval = 0 get the entry successfully
2152 * negative errno (< 0) does not get the entry
2154 static int lmv_get_min_striped_entry(struct obd_export *exp,
2155 struct md_op_data *op_data,
2156 struct md_callback *cb_op,
2157 __u64 hash_offset, int *stripe_offset,
2158 struct lu_dirent **entp,
2159 struct page **ppage)
2161 struct lmv_stripe_md *lsm = op_data->op_mea1;
2162 struct obd_device *obd = exp->exp_obd;
2163 struct lmv_obd *lmv = &obd->u.lmv;
2164 struct lu_dirent *min_ent = NULL;
2165 struct page *min_page = NULL;
2166 struct lmv_tgt_desc *tgt;
2172 stripe_count = lsm->lsm_md_stripe_count;
2173 for (i = 0; i < stripe_count; i++) {
2174 __u64 stripe_hash = hash_offset;
2175 struct lu_dirent *ent = NULL;
2176 struct page *page = NULL;
2177 struct lu_dirpage *dp;
2179 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds, NULL);
2186 * op_data will be shared by each stripe, so we need
2187 * reset these value for each stripe
2189 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2190 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2191 op_data->op_data = lsm->lsm_md_oinfo[i].lmo_root;
2193 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, stripe_hash,
2198 dp = page_address(page);
2199 for (ent = lu_dirent_start(dp); ent;
2200 ent = lu_dirent_next(ent)) {
2201 /* Skip dummy entry */
2202 if (!le16_to_cpu(ent->lde_namelen))
2205 if (le64_to_cpu(ent->lde_hash) < hash_offset)
2208 if (le64_to_cpu(ent->lde_hash) == hash_offset &&
2209 (*entp == ent || i < *stripe_offset))
2212 /* skip . and .. for other stripes */
2213 if (i && (!strncmp(ent->lde_name, ".",
2214 le16_to_cpu(ent->lde_namelen)) ||
2215 !strncmp(ent->lde_name, "..",
2216 le16_to_cpu(ent->lde_namelen))))
2222 stripe_hash = le64_to_cpu(dp->ldp_hash_end);
2229 * reach the end of current stripe, go to next stripe
2231 if (stripe_hash == MDS_DIR_END_OFF)
2238 if (le64_to_cpu(min_ent->lde_hash) >
2239 le64_to_cpu(ent->lde_hash)) {
2262 *stripe_offset = min_idx;
2269 * Build dir entry page from a striped directory
2271 * This function gets one entry by @offset from a striped directory. It will
2272 * read entries from all of stripes, and choose one closest to the required
2273 * offset(&offset). A few notes
2274 * 1. skip . and .. for non-zero stripes, because there can only have one .
2275 * and .. in a directory.
2276 * 2. op_data will be shared by all of stripes, instead of allocating new
2277 * one, so need to restore before reusing.
2278 * 3. release the entry page if that is not being chosen.
2280 * \param[in] exp obd export refer to LMV
2281 * \param[in] op_data hold those MD parameters of read_entry
2282 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2283 * \param[out] ldp the entry being read
2284 * \param[out] ppage the page holding the entry. Note: because the entry
2285 * will be accessed in upper layer, so we need hold the
2286 * page until the usages of entry is finished, see
2287 * ll_dir_entry_next.
2289 * retval =0 if get entry successfully
2290 * <0 cannot get entry
2292 static int lmv_read_striped_page(struct obd_export *exp,
2293 struct md_op_data *op_data,
2294 struct md_callback *cb_op,
2295 __u64 offset, struct page **ppage)
2297 struct inode *master_inode = op_data->op_data;
2298 struct lu_fid master_fid = op_data->op_fid1;
2299 struct obd_device *obd = exp->exp_obd;
2300 __u64 hash_offset = offset;
2301 struct page *min_ent_page = NULL;
2302 struct page *ent_page = NULL;
2303 struct lu_dirent *min_ent = NULL;
2304 struct lu_dirent *last_ent;
2305 struct lu_dirent *ent;
2306 struct lu_dirpage *dp;
2312 rc = lmv_check_connect(obd);
2317 * Allocate a page and read entries from all of stripes and fill
2318 * the page by hash order
2320 ent_page = alloc_page(GFP_KERNEL);
2324 /* Initialize the entry page */
2325 dp = kmap(ent_page);
2326 memset(dp, 0, sizeof(*dp));
2327 dp->ldp_hash_start = cpu_to_le64(offset);
2328 dp->ldp_flags |= LDF_COLLIDE;
2331 left_bytes = PAGE_SIZE - sizeof(*dp);
2337 /* Find the minum entry from all sub-stripes */
2338 rc = lmv_get_min_striped_entry(exp, op_data, cb_op, hash_offset,
2345 * If it can not get minum entry, it means it already reaches
2346 * the end of this directory
2349 last_ent->lde_reclen = 0;
2350 hash_offset = MDS_DIR_END_OFF;
2354 ent_size = le16_to_cpu(min_ent->lde_reclen);
2357 * the last entry lde_reclen is 0, but it might not
2358 * the end of this entry of this temporay entry
2361 ent_size = lu_dirent_calc_size(
2362 le16_to_cpu(min_ent->lde_namelen),
2363 le32_to_cpu(min_ent->lde_attrs));
2364 if (ent_size > left_bytes) {
2365 last_ent->lde_reclen = cpu_to_le16(0);
2366 hash_offset = le64_to_cpu(min_ent->lde_hash);
2370 memcpy(ent, min_ent, ent_size);
2373 * Replace . with master FID and Replace .. with the parent FID
2376 if (!strncmp(ent->lde_name, ".",
2377 le16_to_cpu(ent->lde_namelen)) &&
2378 le16_to_cpu(ent->lde_namelen) == 1)
2379 fid_cpu_to_le(&ent->lde_fid, &master_fid);
2380 else if (!strncmp(ent->lde_name, "..",
2381 le16_to_cpu(ent->lde_namelen)) &&
2382 le16_to_cpu(ent->lde_namelen) == 2)
2383 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2385 left_bytes -= ent_size;
2386 ent->lde_reclen = cpu_to_le16(ent_size);
2388 ent = (void *)ent + ent_size;
2389 hash_offset = le64_to_cpu(min_ent->lde_hash);
2390 if (hash_offset == MDS_DIR_END_OFF) {
2391 last_ent->lde_reclen = 0;
2397 kunmap(min_ent_page);
2398 put_page(min_ent_page);
2402 __free_page(ent_page);
2406 dp->ldp_flags |= LDF_EMPTY;
2407 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2408 dp->ldp_hash_end = cpu_to_le64(hash_offset);
2412 * We do not want to allocate md_op_data during each
2413 * dir entry reading, so op_data will be shared by every stripe,
2414 * then we need to restore it back to original value before
2415 * return to the upper layer
2417 op_data->op_fid1 = master_fid;
2418 op_data->op_fid2 = master_fid;
2419 op_data->op_data = master_inode;
2426 static int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2427 struct md_callback *cb_op, __u64 offset,
2428 struct page **ppage)
2430 struct lmv_stripe_md *lsm = op_data->op_mea1;
2431 struct obd_device *obd = exp->exp_obd;
2432 struct lmv_obd *lmv = &obd->u.lmv;
2433 struct lmv_tgt_desc *tgt;
2436 rc = lmv_check_connect(obd);
2440 if (unlikely(lsm)) {
2441 rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2445 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2447 return PTR_ERR(tgt);
2449 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2455 * Unlink a file/directory
2457 * Unlink a file or directory under the parent dir. The unlink request
2458 * usually will be sent to the MDT where the child is located, but if
2459 * the client does not have the child FID then request will be sent to the
2460 * MDT where the parent is located.
2462 * If the parent is a striped directory then it also needs to locate which
2463 * stripe the name of the child is located, and replace the parent FID
2464 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2465 * it will walk through all of sub-stripes until the child is being
2468 * \param[in] exp export refer to LMV
2469 * \param[in] op_data different parameters transferred beween client
2470 * MD stacks, name, namelen, FIDs etc.
2471 * op_fid1 is the parent FID, op_fid2 is the child
2473 * \param[out] request point to the request of unlink.
2475 * retval 0 if succeed
2476 * negative errno if failed.
2478 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2479 struct ptlrpc_request **request)
2481 struct lmv_stripe_md *lsm = op_data->op_mea1;
2482 struct obd_device *obd = exp->exp_obd;
2483 struct lmv_obd *lmv = &obd->u.lmv;
2484 struct lmv_tgt_desc *parent_tgt = NULL;
2485 struct lmv_tgt_desc *tgt = NULL;
2486 struct mdt_body *body;
2487 int stripe_index = 0;
2490 rc = lmv_check_connect(obd);
2494 /* For striped dir, we need to locate the parent as well */
2496 struct lmv_tgt_desc *tmp;
2498 LASSERT(op_data->op_name && op_data->op_namelen);
2500 tmp = lmv_locate_target_for_name(lmv, lsm,
2502 op_data->op_namelen,
2507 * return -EBADFD means unknown hash type, might
2508 * need try all sub-stripe here
2510 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2511 return PTR_ERR(tmp);
2514 * Note: both migrating dir and unknown hash dir need to
2515 * try all of sub-stripes, so we need start search the
2516 * name from stripe 0, but migrating dir is already handled
2517 * inside lmv_locate_target_for_name(), so we only check
2518 * unknown hash type directory here
2520 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2521 struct lmv_oinfo *oinfo;
2523 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2525 op_data->op_fid1 = oinfo->lmo_fid;
2526 op_data->op_mds = oinfo->lmo_mds;
2531 /* Send unlink requests to the MDT where the child is located */
2532 if (likely(!fid_is_zero(&op_data->op_fid2)))
2533 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2535 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2537 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2540 return PTR_ERR(tgt);
2542 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2543 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2544 op_data->op_cap = cfs_curproc_cap_pack();
2547 * If child's fid is given, cancel unused locks for it if it is from
2548 * another export than parent.
2550 * LOOKUP lock for child (fid3) should also be cancelled on parent
2551 * tgt_tgt in mdc_unlink().
2553 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2556 * Cancel FULL locks on child (fid3).
2558 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2559 if (IS_ERR(parent_tgt))
2560 return PTR_ERR(parent_tgt);
2562 if (parent_tgt != tgt) {
2563 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2564 LCK_EX, MDS_INODELOCK_LOOKUP,
2565 MF_MDC_CANCEL_FID3);
2568 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2569 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2573 CDEBUG(D_INODE, "unlink with fid=" DFID "/" DFID " -> mds #%u\n",
2574 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2576 rc = md_unlink(tgt->ltd_exp, op_data, request);
2577 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2580 /* Try next stripe if it is needed. */
2581 if (rc == -ENOENT && lsm && lmv_need_try_all_stripes(lsm)) {
2582 struct lmv_oinfo *oinfo;
2585 if (stripe_index >= lsm->lsm_md_stripe_count)
2588 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2590 op_data->op_fid1 = oinfo->lmo_fid;
2591 op_data->op_mds = oinfo->lmo_mds;
2593 ptlrpc_req_finished(*request);
2596 goto try_next_stripe;
2599 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2603 /* Not cross-ref case, just get out of here. */
2604 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2607 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2608 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2610 /* This is a remote object, try remote MDT, Note: it may
2611 * try more than 1 time here, Considering following case
2612 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2613 * 1. Initially A does not know where remote1 is, it send
2614 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2615 * resend unlink RPC to MDT1 (retry 1st time).
2617 * 2. During the unlink RPC in flight,
2618 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2619 * and create new remote1, but on MDT0
2621 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2622 * /mnt/lustre, then lookup get fid of remote1, and find
2623 * it is remote dir again, and replay -EREMOTE again.
2625 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2627 * In theory, it might try unlimited time here, but it should
2628 * be very rare case.
2630 op_data->op_fid2 = body->mbo_fid1;
2631 ptlrpc_req_finished(*request);
2637 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2639 struct lmv_obd *lmv = &obd->u.lmv;
2642 case OBD_CLEANUP_EARLY:
2643 /* XXX: here should be calling obd_precleanup() down to
2647 case OBD_CLEANUP_EXPORTS:
2648 fld_client_debugfs_fini(&lmv->lmv_fld);
2649 lprocfs_obd_cleanup(obd);
2658 * Get by key a value associated with a LMV device.
2660 * Dispatch request to lower-layer devices as needed.
2662 * \param[in] env execution environment for this thread
2663 * \param[in] exp export for the LMV device
2664 * \param[in] keylen length of key identifier
2665 * \param[in] key identifier of key to get value for
2666 * \param[in] vallen size of \a val
2667 * \param[out] val pointer to storage location for value
2668 * \param[in] lsm optional striping metadata of object
2670 * \retval 0 on success
2671 * \retval negative negated errno on failure
2673 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2674 __u32 keylen, void *key, __u32 *vallen, void *val,
2675 struct lov_stripe_md *lsm)
2677 struct obd_device *obd;
2678 struct lmv_obd *lmv;
2681 obd = class_exp2obd(exp);
2683 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2684 exp->exp_handle.h_cookie);
2689 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2692 rc = lmv_check_connect(obd);
2696 LASSERT(*vallen == sizeof(__u32));
2697 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2698 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2701 * All tgts should be connected when this gets called.
2703 if (!tgt || !tgt->ltd_exp)
2706 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2711 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2712 KEY_IS(KEY_DEFAULT_EASIZE) ||
2713 KEY_IS(KEY_CONN_DATA)) {
2714 rc = lmv_check_connect(obd);
2719 * Forwarding this request to first MDS, it should know LOV
2722 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2724 if (!rc && KEY_IS(KEY_CONN_DATA))
2725 exp->exp_connect_data = *(struct obd_connect_data *)val;
2727 } else if (KEY_IS(KEY_TGT_COUNT)) {
2728 *((int *)val) = lmv->desc.ld_tgt_count;
2732 CDEBUG(D_IOCTL, "Invalid key\n");
2737 * Asynchronously set by key a value associated with a LMV device.
2739 * Dispatch request to lower-layer devices as needed.
2741 * \param[in] env execution environment for this thread
2742 * \param[in] exp export for the LMV device
2743 * \param[in] keylen length of key identifier
2744 * \param[in] key identifier of key to store value for
2745 * \param[in] vallen size of value to store
2746 * \param[in] val pointer to data to be stored
2747 * \param[in] set optional list of related ptlrpc requests
2749 * \retval 0 on success
2750 * \retval negative negated errno on failure
2752 static int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2753 u32 keylen, void *key, u32 vallen,
2754 void *val, struct ptlrpc_request_set *set)
2756 struct lmv_tgt_desc *tgt;
2757 struct obd_device *obd;
2758 struct lmv_obd *lmv;
2761 obd = class_exp2obd(exp);
2763 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2764 exp->exp_handle.h_cookie);
2769 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2770 KEY_IS(KEY_DEFAULT_EASIZE)) {
2773 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2776 if (!tgt || !tgt->ltd_exp)
2779 err = obd_set_info_async(env, tgt->ltd_exp,
2780 keylen, key, vallen, val, set);
2791 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2792 struct lmv_mds_md_v1 *lmm1)
2797 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2798 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2799 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2800 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2801 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2802 sizeof(lmm1->lmv_pool_name));
2803 if (cplen >= sizeof(lmm1->lmv_pool_name))
2806 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2807 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2808 &lsm->lsm_md_oinfo[i].lmo_fid);
2813 lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2816 int lmm_size = 0, rc = 0;
2817 bool allocated = false;
2822 if (*lmmp && !lsm) {
2825 stripe_cnt = lmv_mds_md_stripe_count_get(*lmmp);
2826 lmm_size = lmv_mds_md_size(stripe_cnt,
2827 le32_to_cpu((*lmmp)->lmv_magic));
2836 if (!*lmmp && !lsm) {
2837 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2838 LASSERT(lmm_size > 0);
2839 *lmmp = libcfs_kvzalloc(lmm_size, GFP_NOFS);
2842 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2843 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2849 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count,
2852 *lmmp = libcfs_kvzalloc(lmm_size, GFP_NOFS);
2858 switch (lsm->lsm_md_magic) {
2860 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2867 if (rc && allocated) {
2875 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2876 const struct lmv_mds_md_v1 *lmm1)
2878 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2884 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2885 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2886 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2887 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2888 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2890 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2891 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2892 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2893 sizeof(lsm->lsm_md_pool_name));
2895 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2898 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d layout_version %d\n",
2899 lsm->lsm_md_stripe_count, lsm->lsm_md_master_mdt_index,
2900 lsm->lsm_md_hash_type, lsm->lsm_md_layout_version);
2902 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2903 for (i = 0; i < stripe_count; i++) {
2904 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2905 &lmm1->lmv_stripe_fids[i]);
2906 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2907 &lsm->lsm_md_oinfo[i].lmo_mds);
2910 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2911 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2917 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2918 const union lmv_mds_md *lmm, int stripe_count)
2920 struct lmv_stripe_md *lsm;
2921 bool allocated = false;
2931 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2933 * For migrating inode, the master stripe and master
2934 * object will be the same, so do not need iput, see
2937 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2938 !i) && lsm->lsm_md_oinfo[i].lmo_root)
2939 iput(lsm->lsm_md_oinfo[i].lmo_root);
2949 lsm_size = lmv_stripe_md_size(stripe_count);
2950 lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
2953 lsm->lsm_md_stripe_count = stripe_count;
2958 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2962 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2963 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2964 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2965 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2970 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2971 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2974 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2975 * stripecount should be 0 then.
2977 lsm_size = lmv_stripe_md_size(0);
2980 lsm = libcfs_kvzalloc(lsm_size, GFP_NOFS);
2987 switch (le32_to_cpu(lmm->lmv_magic)) {
2989 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2992 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2993 le32_to_cpu(lmm->lmv_magic));
2998 if (rc && allocated) {
3005 EXPORT_SYMBOL(lmv_unpack_md);
3007 static int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
3008 struct lov_mds_md *lmm, int disk_len)
3010 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
3011 (union lmv_mds_md *)lmm, disk_len);
3014 static int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
3015 struct lov_stripe_md *lsm)
3017 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
3018 struct obd_device *obd = exp->exp_obd;
3019 struct lmv_obd *lmv_obd = &obd->u.lmv;
3024 stripe_count = lmv->lsm_md_stripe_count;
3026 stripe_count = lmv_obd->desc.ld_tgt_count;
3028 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
3031 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
3034 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
3035 ldlm_policy_data_t *policy, enum ldlm_mode mode,
3036 enum ldlm_cancel_flags flags, void *opaque)
3038 struct obd_device *obd = exp->exp_obd;
3039 struct lmv_obd *lmv = &obd->u.lmv;
3046 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3047 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3049 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
3052 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
3060 static int lmv_set_lock_data(struct obd_export *exp,
3061 const struct lustre_handle *lockh,
3062 void *data, __u64 *bits)
3064 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3065 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3068 if (!tgt || !tgt->ltd_exp)
3071 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
3075 static enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
3076 const struct lu_fid *fid,
3077 enum ldlm_type type,
3078 ldlm_policy_data_t *policy,
3079 enum ldlm_mode mode,
3080 struct lustre_handle *lockh)
3082 struct obd_device *obd = exp->exp_obd;
3083 struct lmv_obd *lmv = &obd->u.lmv;
3088 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
3091 * With DNE every object can have two locks in different namespaces:
3092 * lookup lock in space of MDT storing direntry and update/open lock in
3093 * space of MDT storing inode. Try the MDT that the FID maps to first,
3094 * since this can be easily found, and only try others if that fails.
3096 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
3097 i < lmv->desc.ld_tgt_count;
3098 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
3100 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
3101 obd->obd_name, PFID(fid), tgt);
3105 if (!lmv->tgts[tgt] || !lmv->tgts[tgt]->ltd_exp ||
3106 !lmv->tgts[tgt]->ltd_active)
3109 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
3110 type, policy, mode, lockh);
3118 static int lmv_get_lustre_md(struct obd_export *exp,
3119 struct ptlrpc_request *req,
3120 struct obd_export *dt_exp,
3121 struct obd_export *md_exp,
3122 struct lustre_md *md)
3124 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3125 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3127 if (!tgt || !tgt->ltd_exp)
3129 return md_get_lustre_md(tgt->ltd_exp, req, dt_exp, md_exp, md);
3132 static int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3134 struct obd_device *obd = exp->exp_obd;
3135 struct lmv_obd *lmv = &obd->u.lmv;
3136 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3139 lmv_free_memmd(md->lmv);
3142 if (!tgt || !tgt->ltd_exp)
3144 return md_free_lustre_md(tgt->ltd_exp, md);
3147 static int lmv_set_open_replay_data(struct obd_export *exp,
3148 struct obd_client_handle *och,
3149 struct lookup_intent *it)
3151 struct obd_device *obd = exp->exp_obd;
3152 struct lmv_obd *lmv = &obd->u.lmv;
3153 struct lmv_tgt_desc *tgt;
3155 tgt = lmv_find_target(lmv, &och->och_fid);
3157 return PTR_ERR(tgt);
3159 return md_set_open_replay_data(tgt->ltd_exp, och, it);
3162 static int lmv_clear_open_replay_data(struct obd_export *exp,
3163 struct obd_client_handle *och)
3165 struct obd_device *obd = exp->exp_obd;
3166 struct lmv_obd *lmv = &obd->u.lmv;
3167 struct lmv_tgt_desc *tgt;
3169 tgt = lmv_find_target(lmv, &och->och_fid);
3171 return PTR_ERR(tgt);
3173 return md_clear_open_replay_data(tgt->ltd_exp, och);
3176 static int lmv_intent_getattr_async(struct obd_export *exp,
3177 struct md_enqueue_info *minfo,
3178 struct ldlm_enqueue_info *einfo)
3180 struct md_op_data *op_data = &minfo->mi_data;
3181 struct obd_device *obd = exp->exp_obd;
3182 struct lmv_obd *lmv = &obd->u.lmv;
3183 struct lmv_tgt_desc *tgt = NULL;
3186 rc = lmv_check_connect(obd);
3190 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3192 return PTR_ERR(tgt);
3194 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3198 static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3199 struct lu_fid *fid, __u64 *bits)
3201 struct obd_device *obd = exp->exp_obd;
3202 struct lmv_obd *lmv = &obd->u.lmv;
3203 struct lmv_tgt_desc *tgt;
3206 rc = lmv_check_connect(obd);
3210 tgt = lmv_find_target(lmv, fid);
3212 return PTR_ERR(tgt);
3214 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3219 lmv_get_fid_from_lsm(struct obd_export *exp,
3220 const struct lmv_stripe_md *lsm,
3221 const char *name, int namelen, struct lu_fid *fid)
3223 const struct lmv_oinfo *oinfo;
3226 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3228 return PTR_ERR(oinfo);
3230 *fid = oinfo->lmo_fid;
3236 * For lmv, only need to send request to master MDT, and the master MDT will
3237 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3238 * we directly fetch data from the slave MDTs.
3240 static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3241 struct obd_quotactl *oqctl)
3243 struct obd_device *obd = class_exp2obd(exp);
3244 struct lmv_obd *lmv = &obd->u.lmv;
3245 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3247 __u64 curspace = 0, curinodes = 0;
3250 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active ||
3251 !lmv->desc.ld_tgt_count) {
3252 CERROR("master lmv inactive\n");
3256 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3257 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3261 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3266 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
3269 err = obd_quotactl(tgt->ltd_exp, oqctl);
3271 CERROR("getquota on mdt %d failed. %d\n", i, err);
3275 curspace += oqctl->qc_dqblk.dqb_curspace;
3276 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3279 oqctl->qc_dqblk.dqb_curspace = curspace;
3280 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3285 static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3286 struct obd_quotactl *oqctl)
3288 struct obd_device *obd = class_exp2obd(exp);
3289 struct lmv_obd *lmv = &obd->u.lmv;
3290 struct lmv_tgt_desc *tgt;
3294 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3298 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
3299 CERROR("lmv idx %d inactive\n", i);
3303 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3311 static int lmv_merge_attr(struct obd_export *exp,
3312 const struct lmv_stripe_md *lsm,
3313 struct cl_attr *attr,
3314 ldlm_blocking_callback cb_blocking)
3318 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3322 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3323 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3325 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u, atime %lu ctime %lu, mtime %lu.\n",
3326 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3327 i_size_read(inode), (unsigned long long)inode->i_blocks,
3328 inode->i_nlink, LTIME_S(inode->i_atime),
3329 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3331 /* for slave stripe, it needs to subtract nlink for . and .. */
3333 attr->cat_nlink += inode->i_nlink - 2;
3335 attr->cat_nlink = inode->i_nlink;
3337 attr->cat_size += i_size_read(inode);
3338 attr->cat_blocks += inode->i_blocks;
3340 if (attr->cat_atime < LTIME_S(inode->i_atime))
3341 attr->cat_atime = LTIME_S(inode->i_atime);
3343 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3344 attr->cat_ctime = LTIME_S(inode->i_ctime);
3346 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3347 attr->cat_mtime = LTIME_S(inode->i_mtime);
3352 static struct obd_ops lmv_obd_ops = {
3353 .owner = THIS_MODULE,
3355 .cleanup = lmv_cleanup,
3356 .precleanup = lmv_precleanup,
3357 .process_config = lmv_process_config,
3358 .connect = lmv_connect,
3359 .disconnect = lmv_disconnect,
3360 .statfs = lmv_statfs,
3361 .get_info = lmv_get_info,
3362 .set_info_async = lmv_set_info_async,
3363 .packmd = lmv_packmd,
3364 .unpackmd = lmv_unpackmd,
3365 .notify = lmv_notify,
3366 .get_uuid = lmv_get_uuid,
3367 .iocontrol = lmv_iocontrol,
3368 .quotacheck = lmv_quotacheck,
3369 .quotactl = lmv_quotactl
3372 static struct md_ops lmv_md_ops = {
3373 .getstatus = lmv_getstatus,
3374 .null_inode = lmv_null_inode,
3376 .create = lmv_create,
3377 .done_writing = lmv_done_writing,
3378 .enqueue = lmv_enqueue,
3379 .getattr = lmv_getattr,
3380 .getxattr = lmv_getxattr,
3381 .getattr_name = lmv_getattr_name,
3382 .intent_lock = lmv_intent_lock,
3384 .rename = lmv_rename,
3385 .setattr = lmv_setattr,
3386 .setxattr = lmv_setxattr,
3388 .read_page = lmv_read_page,
3389 .unlink = lmv_unlink,
3390 .init_ea_size = lmv_init_ea_size,
3391 .cancel_unused = lmv_cancel_unused,
3392 .set_lock_data = lmv_set_lock_data,
3393 .lock_match = lmv_lock_match,
3394 .get_lustre_md = lmv_get_lustre_md,
3395 .free_lustre_md = lmv_free_lustre_md,
3396 .merge_attr = lmv_merge_attr,
3397 .set_open_replay_data = lmv_set_open_replay_data,
3398 .clear_open_replay_data = lmv_clear_open_replay_data,
3399 .intent_getattr_async = lmv_intent_getattr_async,
3400 .revalidate_lock = lmv_revalidate_lock,
3401 .get_fid_from_lsm = lmv_get_fid_from_lsm,
3404 static int __init lmv_init(void)
3406 struct lprocfs_static_vars lvars;
3409 lprocfs_lmv_init_vars(&lvars);
3411 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
3412 LUSTRE_LMV_NAME, NULL);
3416 static void lmv_exit(void)
3418 class_unregister_type(LUSTRE_LMV_NAME);
3421 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3422 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3423 MODULE_VERSION(LUSTRE_VERSION_STRING);
3424 MODULE_LICENSE("GPL");
3426 module_init(lmv_init);
3427 module_exit(lmv_exit);