1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_LMV
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/pagemap.h>
32 #include <asm/div64.h>
33 #include <linux/seq_file.h>
34 #include <linux/namei.h>
36 #include <liblustre.h>
38 #include <linux/ext2_fs.h>
40 #include <linux/obd_support.h>
41 #include <linux/lustre_lib.h>
42 #include <linux/lustre_net.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lustre_dlm.h>
45 #include <linux/lustre_mds.h>
46 #include <linux/obd_class.h>
47 #include <linux/obd_ost.h>
48 #include <linux/lprocfs_status.h>
49 #include <linux/lustre_fsfilt.h>
50 #include <linux/obd_lmv.h>
51 #include <linux/lustre_lite.h>
52 #include <linux/lustre_audit.h>
53 #include "lmv_internal.h"
55 /* not defined for liblustre building */
56 #if !defined(ATOMIC_INIT)
57 #define ATOMIC_INIT(val) { (val) }
61 kmem_cache_t *obj_cache;
62 atomic_t obj_cache_count = ATOMIC_INIT(0);
64 static void lmv_activate_target(struct lmv_obd *lmv,
65 struct lmv_tgt_desc *tgt,
68 if (tgt->active == activate)
71 tgt->active = activate;
72 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
77 * -EINVAL : UUID can't be found in the LMV's target list
78 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
79 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
81 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
84 struct lmv_tgt_desc *tgt;
85 struct obd_device *obd;
89 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
90 lmv, uuid->uuid, activate);
92 spin_lock(&lmv->lmv_lock);
93 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
94 if (tgt->ltd_exp == NULL)
97 CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n",
98 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
100 if (obd_uuid_equals(uuid, &tgt->uuid))
104 if (i == lmv->desc.ld_tgt_count)
105 GOTO(out_lmv_lock, rc = -EINVAL);
107 obd = class_exp2obd(tgt->ltd_exp);
109 GOTO(out_lmv_lock, rc = -ENOTCONN);
111 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
112 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
113 obd->obd_type->typ_name, i);
114 LASSERT(strcmp(obd->obd_type->typ_name, OBD_MDC_DEVICENAME) == 0);
116 if (tgt->active == activate) {
117 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
118 activate ? "" : "in");
119 GOTO(out_lmv_lock, rc);
122 CDEBUG(D_INFO, "Marking OBD %p %sactive\n",
123 obd, activate ? "" : "in");
125 lmv_activate_target(lmv, tgt, activate);
130 spin_unlock(&lmv->lmv_lock);
134 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
135 int active, void *data)
137 struct obd_uuid *uuid;
141 if (strcmp(watched->obd_type->typ_name, OBD_MDC_DEVICENAME)) {
142 CERROR("unexpected notification of %s %s!\n",
143 watched->obd_type->typ_name,
147 uuid = &watched->u.cli.cl_import->imp_target_uuid;
149 /* Set MDC as active before notifying the observer, so the observer can
150 * use the MDC normally.
152 rc = lmv_set_mdc_active(&obd->u.lmv, uuid, active);
154 CERROR("%sactivation of %s failed: %d\n",
155 active ? "" : "de", uuid->uuid, rc);
159 if (obd->obd_observer)
160 /* Pass the notification up the chain. */
161 rc = obd_notify(obd->obd_observer, watched, active, data);
166 static int lmv_attach(struct obd_device *dev, obd_count len, void *data)
168 struct lprocfs_static_vars lvars;
172 lprocfs_init_vars(lmv, &lvars);
173 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
176 struct proc_dir_entry *entry;
178 entry = create_proc_entry("target_obd_status", 0444,
179 dev->obd_proc_entry);
182 entry->proc_fops = &lmv_proc_target_fops;
189 static int lmv_detach(struct obd_device *dev)
191 return lprocfs_obd_detach(dev);
194 /* this is fake connect function. Its purpose is to initialize lmv and say
195 * caller that everything is okay. Real connection will be performed later. */
196 static int lmv_connect(struct lustre_handle *conn, struct obd_device *obd,
197 struct obd_uuid *cluuid, struct obd_connect_data *data,
201 struct proc_dir_entry *lmv_proc_dir;
203 struct lmv_obd *lmv = &obd->u.lmv;
204 struct obd_export *exp;
208 rc = class_connect(conn, obd, cluuid);
210 CERROR("class_connection() returned %d\n", rc);
214 exp = class_conn2export(conn);
216 /* we don't want to actually do the underlying connections more than
217 * once, so keep track. */
219 if (lmv->refcount > 1) {
220 class_export_put(exp);
226 lmv->cluuid = *cluuid;
227 lmv->connect_flags = flags;
229 memcpy(&lmv->conn_data, data, sizeof(*data));
232 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
234 if (IS_ERR(lmv_proc_dir)) {
235 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
236 obd->obd_type->typ_name, obd->obd_name);
242 * all real clients should perform actual connection rightaway, because
243 * it is possible, that LMV will not have opportunity to connect
244 * targets, as MDC stuff will bit called directly, for instance while
245 * reading ../mdc/../kbytesfree procfs file, etc.
247 if (flags & OBD_OPT_REAL_CLIENT)
248 rc = lmv_check_connect(obd);
253 lprocfs_remove(lmv_proc_dir);
260 static void lmv_set_timeouts(struct obd_device *obd)
262 struct lmv_tgt_desc *tgts;
267 if (lmv->server_timeout == 0)
270 if (lmv->connected == 0)
273 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
274 if (tgts->ltd_exp == NULL)
277 obd_set_info(tgts->ltd_exp, strlen("inter_mds"),
278 "inter_mds", 0, NULL);
282 static int lmv_init_ea_size(struct obd_export *exp, int easize,
285 struct obd_device *obd = exp->exp_obd;
286 struct lmv_obd *lmv = &obd->u.lmv;
287 int i, rc = 0, change = 0;
290 if (lmv->max_easize < easize) {
291 lmv->max_easize = easize;
294 if (lmv->max_cookiesize < cookiesize) {
295 lmv->max_cookiesize = cookiesize;
301 if (lmv->connected == 0)
304 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
305 if (lmv->tgts[i].ltd_exp == NULL) {
306 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
310 rc = obd_init_ea_size(lmv->tgts[i].ltd_exp, easize, cookiesize);
312 CERROR("obd_init_ea_size() failed on MDT target %d, "
313 "error %d.\n", i, rc);
320 #define MAX_STRING_SIZE 128
322 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
324 struct lmv_obd *lmv = &obd->u.lmv;
325 struct obd_uuid *cluuid = &lmv->cluuid;
326 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
327 struct lustre_handle conn = {0, };
328 struct obd_device *mdc_obd;
329 struct obd_export *mdc_exp;
332 struct proc_dir_entry *lmv_proc_dir;
336 /* for MDS: don't connect to yourself */
337 if (obd_uuid_equals(&tgt->uuid, cluuid)) {
338 CDEBUG(D_CONFIG, "don't connect back to %s\n", cluuid->uuid);
339 /* XXX - the old code didn't increment active tgt count.
344 mdc_obd = class_find_client_obd(&tgt->uuid, OBD_MDC_DEVICENAME,
347 CERROR("target %s not attached\n", tgt->uuid.uuid);
351 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
352 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
353 tgt->uuid.uuid, obd->obd_uuid.uuid,
356 if (!mdc_obd->obd_set_up) {
357 CERROR("target %s not set up\n", tgt->uuid.uuid);
361 rc = obd_connect(&conn, mdc_obd, &lmv_mdc_uuid, &lmv->conn_data,
364 CERROR("target %s connect error %d\n", tgt->uuid.uuid, rc);
368 mdc_exp = class_conn2export(&conn);
370 rc = obd_register_observer(mdc_obd, obd);
372 obd_disconnect(mdc_exp, 0);
373 CERROR("target %s register_observer error %d\n",
378 if (obd->obd_observer) {
379 /* tell the mds_lmv about the new target */
380 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd, 1,
381 (void *)(tgt - lmv->tgts));
383 obd_disconnect(mdc_exp, 0);
388 tgt->ltd_exp = mdc_exp;
390 lmv->desc.ld_active_tgt_count++;
392 obd_init_ea_size(tgt->ltd_exp, lmv->max_easize,
393 lmv->max_cookiesize);
394 CDEBUG(D_CONFIG, "connected to %s(%s) successfully (%d)\n",
395 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
396 atomic_read(&obd->obd_refcount));
399 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
401 struct proc_dir_entry *mdc_symlink;
402 char name[MAX_STRING_SIZE + 1];
404 LASSERT(mdc_obd->obd_type != NULL);
405 LASSERT(mdc_obd->obd_type->typ_name != NULL);
406 name[MAX_STRING_SIZE] = '\0';
407 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
408 mdc_obd->obd_type->typ_name,
410 mdc_symlink = proc_symlink(mdc_obd->obd_name,
412 if (mdc_symlink == NULL) {
413 CERROR("could not register LMV target "
414 "/proc/fs/lustre/%s/%s/target_obds/%s.",
415 obd->obd_type->typ_name, obd->obd_name,
417 lprocfs_remove(lmv_proc_dir);
425 int lmv_add_mdc(struct obd_device *obd, struct obd_uuid *tgt_uuid)
427 struct lmv_obd *lmv = &obd->u.lmv;
428 struct lmv_tgt_desc *tgt;
432 CDEBUG(D_CONFIG, "tgt_uuid: %s.\n", tgt_uuid->uuid);
436 if (lmv->desc.ld_active_tgt_count >= LMV_MAX_TGT_COUNT) {
437 lmv_init_unlock(lmv);
438 CERROR("can't add %s, LMV module compiled for %d MDCs. "
439 "That many MDCs already configured.\n",
440 tgt_uuid->uuid, LMV_MAX_TGT_COUNT);
443 if (lmv->desc.ld_tgt_count == 0) {
444 struct obd_device *mdc_obd;
446 mdc_obd = class_find_client_obd(tgt_uuid, OBD_MDC_DEVICENAME,
449 lmv_init_unlock(lmv);
450 CERROR("Target %s not attached\n", tgt_uuid->uuid);
454 rc = obd_llog_init(obd, &obd->obd_llogs, mdc_obd, 0, NULL);
456 lmv_init_unlock(lmv);
457 CERROR("lmv failed to setup llogging subsystems\n");
460 spin_lock(&lmv->lmv_lock);
461 tgt = lmv->tgts + lmv->desc.ld_tgt_count++;
462 tgt->uuid = *tgt_uuid;
463 spin_unlock(&lmv->lmv_lock);
465 if (lmv->connected) {
466 rc = lmv_connect_mdc(obd, tgt);
468 spin_lock(&lmv->lmv_lock);
469 lmv->desc.ld_tgt_count--;
470 memset(tgt, 0, sizeof(*tgt));
471 spin_unlock(&lmv->lmv_lock);
473 int easize = sizeof(struct mea) +
474 lmv->desc.ld_tgt_count *
475 sizeof(struct lustre_id);
476 lmv_init_ea_size(obd->obd_self_export, easize, 0);
480 lmv_init_unlock(lmv);
484 /* performs a check if passed obd is connected. If no - connect it. */
485 int lmv_check_connect(struct obd_device *obd)
487 struct lmv_obd *lmv = &obd->u.lmv;
488 struct lmv_tgt_desc *tgt;
496 if (lmv->connected) {
497 lmv_init_unlock(lmv);
501 if (lmv->desc.ld_tgt_count == 0) {
502 CERROR("%s: no targets configured.\n", obd->obd_name);
506 CDEBUG(D_CONFIG, "time to connect %s to %s\n",
507 lmv->cluuid.uuid, obd->obd_name);
509 LASSERT(lmv->tgts != NULL);
511 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
512 rc = lmv_connect_mdc(obd, tgt);
517 lmv_set_timeouts(obd);
518 class_export_put(lmv->exp);
520 easize = lmv->desc.ld_tgt_count * sizeof(struct lustre_id) +
522 lmv_init_ea_size(obd->obd_self_export, easize, 0);
523 lmv_init_unlock(lmv);
532 --lmv->desc.ld_active_tgt_count;
533 rc2 = obd_disconnect(tgt->ltd_exp, 0);
535 CERROR("error: LMV target %s disconnect on "
536 "MDC idx %d: error %d\n",
537 tgt->uuid.uuid, i, rc2);
541 class_disconnect(lmv->exp, 0);
542 lmv_init_unlock(lmv);
546 static int lmv_disconnect(struct obd_export *exp, unsigned long flags)
548 struct obd_device *obd = class_exp2obd(exp);
549 struct lmv_obd *lmv = &obd->u.lmv;
552 struct proc_dir_entry *lmv_proc_dir;
560 /* Only disconnect the underlying layers on the final disconnect. */
562 if (lmv->refcount != 0)
566 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
569 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
570 struct obd_device *mdc_obd;
572 if (lmv->tgts[i].ltd_exp == NULL)
575 mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
578 mdc_obd->obd_no_recov = obd->obd_no_recov;
582 struct proc_dir_entry *mdc_symlink;
584 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
586 lprocfs_remove(mdc_symlink);
588 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
589 obd->obd_type->typ_name, obd->obd_name,
594 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
595 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
596 lmv->tgts[i].ltd_exp->exp_obd->obd_uuid.uuid);
598 obd_register_observer(lmv->tgts[i].ltd_exp->exp_obd, NULL);
599 rc = obd_disconnect(lmv->tgts[i].ltd_exp, flags);
601 if (lmv->tgts[i].active) {
602 CERROR("Target %s disconnect error %d\n",
603 lmv->tgts[i].uuid.uuid, rc);
608 lmv_activate_target(lmv, &lmv->tgts[i], 0);
609 lmv->tgts[i].ltd_exp = NULL;
614 lprocfs_remove(lmv_proc_dir);
616 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
617 obd->obd_type->typ_name, obd->obd_name);
622 /* this is the case when no real connection is established by
623 * lmv_check_connect(). */
625 class_export_put(exp);
626 rc = class_disconnect(exp, 0);
627 if (lmv->refcount == 0)
632 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
633 int len, void *karg, void *uarg)
635 struct obd_device *obddev = class_exp2obd(exp);
636 struct lmv_obd *lmv = &obddev->u.lmv;
637 int i, rc = 0, set = 0;
640 if (lmv->desc.ld_tgt_count == 0)
643 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
646 if (lmv->tgts[i].ltd_exp == NULL)
649 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len, karg, uarg);
651 if (lmv->tgts[i].active) {
652 CERROR("error: iocontrol MDC %s on MDT"
653 "idx %d: err = %d\n",
654 lmv->tgts[i].uuid.uuid, i, err);
667 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
669 struct lmv_obd *lmv = &obd->u.lmv;
670 struct lustre_cfg *lcfg = buf;
671 struct lmv_desc *desc;
675 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
676 CERROR("LMV setup requires a descriptor\n");
680 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
681 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
682 CERROR("descriptor size wrong: %d > %d\n",
683 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
687 lmv->tgts_size = LMV_MAX_TGT_COUNT * sizeof(struct lmv_tgt_desc);
689 OBD_ALLOC(lmv->tgts, lmv->tgts_size);
690 if (lmv->tgts == NULL) {
691 CERROR("Out of memory\n");
695 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
696 lmv->desc.ld_tgt_count = 0;
697 lmv->desc.ld_active_tgt_count = 0;
698 lmv->max_cookiesize = 0;
701 spin_lock_init(&lmv->lmv_lock);
702 sema_init(&lmv->init_sem, 1);
704 rc = lmv_setup_mgr(obd);
706 CERROR("Can't setup LMV object manager, "
708 OBD_FREE(lmv->tgts, lmv->tgts_size);
715 static int lmv_cleanup(struct obd_device *obd, int flags)
717 struct lmv_obd *lmv = &obd->u.lmv;
720 lmv_cleanup_mgr(obd);
721 OBD_FREE(lmv->tgts, lmv->tgts_size);
725 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
727 struct lustre_cfg *lcfg = buf;
728 struct obd_uuid tgt_uuid;
732 switch(lcfg->lcfg_command) {
733 case LCFG_LMV_ADD_MDC:
734 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(tgt_uuid.uuid))
735 GOTO(out, rc = -EINVAL);
737 obd_str2uuid(&tgt_uuid, lustre_cfg_string(lcfg, 1));
738 rc = lmv_add_mdc(obd, &tgt_uuid);
741 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
742 GOTO(out, rc = -EINVAL);
749 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
750 unsigned long max_age)
752 struct lmv_obd *lmv = &obd->u.lmv;
753 struct obd_statfs *temp;
757 rc = lmv_check_connect(obd);
761 OBD_ALLOC(temp, sizeof(*temp));
765 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
766 if (lmv->tgts[i].ltd_exp == NULL)
769 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, temp, max_age);
771 CERROR("can't stat MDS #%d (%s), error %d\n", i,
772 lmv->tgts[i].ltd_exp->exp_obd->obd_name,
774 GOTO(out_free_temp, rc);
777 memcpy(osfs, temp, sizeof(*temp));
779 osfs->os_bavail += temp->os_bavail;
780 osfs->os_blocks += temp->os_blocks;
781 osfs->os_ffree += temp->os_ffree;
782 osfs->os_files += temp->os_files;
788 OBD_FREE(temp, sizeof(*temp));
792 static int lmv_getstatus(struct obd_export *exp, struct lustre_id *id)
794 struct obd_device *obd = exp->exp_obd;
795 struct lmv_obd *lmv = &obd->u.lmv;
799 rc = lmv_check_connect(obd);
803 rc = md_getstatus(lmv->tgts[0].ltd_exp, id);
809 static int lmv_getattr(struct obd_export *exp, struct lustre_id *id,
810 __u64 valid, const char *xattr_name,
811 const void *xattr_data, unsigned int xattr_datalen,
812 unsigned int ea_size, struct obd_capa *ocapa,
813 struct ptlrpc_request **request)
815 struct obd_device *obd = exp->exp_obd;
816 struct lmv_obd *lmv = &obd->u.lmv;
817 int rc, i = id_group(id);
821 rc = lmv_check_connect(obd);
825 LASSERT(i < lmv->desc.ld_tgt_count);
828 rc = md_getattr(lmv->tgts[i].ltd_exp, id, valid,
829 xattr_name, xattr_data, xattr_datalen,
830 ea_size, ocapa, request);
834 obj = lmv_grab_obj(obd, id);
836 CDEBUG(D_OTHER, "GETATTR for "DLID4" %s\n",
837 OLID4(id), obj ? "(splitted)" : "");
840 * if object is splitted, then we loop over all the slaves and gather
841 * size attribute. In ideal world we would have to gather also mds field
842 * from all slaves, as object is spread over the cluster and this is
843 * definitely interesting information and it is not good to loss it,
847 struct mds_body *body;
849 if (*request == NULL) {
854 body = lustre_msg_buf((*request)->rq_repmsg, 0,
856 LASSERT(body != NULL);
860 for (i = 0; i < obj->objcount; i++) {
862 if (lmv->tgts[i].ltd_exp == NULL) {
863 CWARN("%s: NULL export for %d\n",
868 /* skip master obj. */
869 if (id_equal_fid(&obj->id, &obj->objs[i].id))
872 body->size += obj->objs[i].size;
882 static int lmv_access_check(struct obd_export *exp,
883 struct lustre_id *id,
884 struct ptlrpc_request **request)
886 struct obd_device *obd = exp->exp_obd;
887 struct lmv_obd *lmv = &obd->u.lmv;
888 int rc, i = id_group(id);
891 rc = lmv_check_connect(obd);
895 LASSERT(i < lmv->desc.ld_tgt_count);
896 rc = md_access_check(lmv->tgts[i].ltd_exp, id, request);
900 static int lmv_change_cbdata(struct obd_export *exp,
901 struct lustre_id *id,
905 struct obd_device *obd = exp->exp_obd;
906 struct lmv_obd *lmv = &obd->u.lmv;
910 rc = lmv_check_connect(obd);
914 CDEBUG(D_OTHER, "CBDATA for "DLID4"\n", OLID4(id));
915 LASSERT(id_group(id) < lmv->desc.ld_tgt_count);
917 /* with CMD every object can have two locks in different
918 * namespaces: lookup lock in space of mds storing direntry
919 * and update/open lock in space of mds storing inode */
920 for (i = 0; i < lmv->desc.ld_tgt_count; i++)
921 md_change_cbdata(lmv->tgts[i].ltd_exp, id, it, data);
926 static int lmv_change_cbdata_name(struct obd_export *exp,
927 struct lustre_id *pid,
929 struct lustre_id *cid,
933 struct obd_device *obd = exp->exp_obd;
934 struct lmv_obd *lmv = &obd->u.lmv;
935 struct lustre_id rcid = *cid;
940 rc = lmv_check_connect(obd);
944 LASSERT(id_group(pid) < lmv->desc.ld_tgt_count);
945 LASSERT(id_group(cid) < lmv->desc.ld_tgt_count);
947 CDEBUG(D_OTHER, "CBDATA for "DLID4":%*s -> "DLID4"\n",
948 OLID4(pid), len, name, OLID4(cid));
950 /* this is default mds for directory name belongs to. */
952 obj = lmv_grab_obj(obd, pid);
954 /* directory is splitted. look for right mds for this name. */
955 mds = raw_name2idx(obj->hashtype, obj->objcount, name, len);
956 rcid = obj->objs[mds].id;
957 mds = id_group(&rcid);
960 rc = md_change_cbdata(lmv->tgts[mds].ltd_exp, &rcid, it, data);
964 static int lmv_valid_attrs(struct obd_export *exp, struct lustre_id *id)
966 struct obd_device *obd = exp->exp_obd;
967 struct lmv_obd *lmv = &obd->u.lmv;
971 rc = lmv_check_connect(obd);
975 CDEBUG(D_OTHER, "validate "DLID4"\n", OLID4(id));
976 LASSERT(id_group(id) < lmv->desc.ld_tgt_count);
977 rc = md_valid_attrs(lmv->tgts[id_group(id)].ltd_exp, id);
981 static int lmv_close(struct obd_export *exp, struct mdc_op_data *op_data,
982 struct obd_client_handle *och,
983 struct ptlrpc_request **request)
985 struct obd_device *obd = exp->exp_obd;
986 struct lmv_obd *lmv = &obd->u.lmv;
987 int rc, i = id_group(&op_data->id1);
990 rc = lmv_check_connect(obd);
994 LASSERT(i < lmv->desc.ld_tgt_count);
995 CDEBUG(D_OTHER, "CLOSE "DLID4"\n", OLID4(&op_data->id1));
996 rc = md_close(lmv->tgts[i].ltd_exp, op_data, och, request);
1000 int lmv_get_mea_and_update_object(struct obd_export *exp,
1001 struct lustre_id *id)
1003 struct obd_device *obd = exp->exp_obd;
1004 struct lmv_obd *lmv = &obd->u.lmv;
1005 struct ptlrpc_request *req = NULL;
1006 struct lmv_obj *obj;
1007 struct lustre_md md;
1013 mealen = MEA_SIZE_LMV(lmv);
1015 valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA;
1017 /* time to update mea of parent id */
1018 rc = md_getattr(lmv->tgts[id_group(id)].ltd_exp,
1019 id, valid, NULL, NULL, 0, mealen, NULL, &req);
1021 CERROR("md_getattr() failed, error %d\n", rc);
1025 rc = mdc_req2lustre_md(exp, req, 0, NULL, &md);
1027 CERROR("mdc_req2lustre_md() failed, error %d\n", rc);
1032 GOTO(cleanup, rc = -ENODATA);
1034 obj = lmv_create_obj(exp, id, md.mea);
1040 obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
1045 ptlrpc_req_finished(req);
1049 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
1050 const void *data, int datalen, int mode, __u32 uid,
1051 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
1053 struct obd_device *obd = exp->exp_obd;
1054 struct lmv_obd *lmv = &obd->u.lmv;
1055 struct mds_body *body;
1056 struct lmv_obj *obj;
1057 int rc, mds, loop = 0;
1060 rc = lmv_check_connect(obd);
1064 if (!lmv->desc.ld_active_tgt_count)
1067 LASSERT(++loop <= 2);
1068 obj = lmv_grab_obj(obd, &op_data->id1);
1070 mds = raw_name2idx(obj->hashtype, obj->objcount,
1071 op_data->name, op_data->namelen);
1072 op_data->id1 = obj->objs[mds].id;
1076 CDEBUG(D_OTHER, "CREATE '%*s' on "DLID4"\n", op_data->namelen,
1077 op_data->name, OLID4(&op_data->id1));
1079 rc = md_create(lmv->tgts[id_group(&op_data->id1)].ltd_exp,
1080 op_data, data, datalen, mode, uid, gid, rdev,
1083 if (*request == NULL)
1086 body = lustre_msg_buf((*request)->rq_repmsg, 0,
1091 CDEBUG(D_OTHER, "created. "DLID4"\n", OLID4(&op_data->id1));
1092 } else if (rc == -ERESTART) {
1094 * directory got splitted. time to update local object and
1095 * repeat the request with proper MDS.
1097 rc = lmv_get_mea_and_update_object(exp, &op_data->id1);
1099 ptlrpc_req_finished(*request);
1106 static int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
1108 struct obd_device *obd = exp->exp_obd;
1109 struct lmv_obd *lmv = &obd->u.lmv;
1113 rc = lmv_check_connect(obd);
1117 /* FIXME: choose right MDC here */
1118 CWARN("this method isn't implemented yet\n");
1119 rc = md_done_writing(lmv->tgts[0].ltd_exp, obdo);
1124 lmv_enqueue_slaves(struct obd_export *exp, int locktype,
1125 struct lookup_intent *it, int lockmode,
1126 struct mdc_op_data *data, struct lustre_handle *lockh,
1127 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1128 ldlm_blocking_callback cb_blocking, void *cb_data)
1130 struct obd_device *obd = exp->exp_obd;
1131 struct lmv_obd *lmv = &obd->u.lmv;
1132 struct mea *mea = data->mea1;
1133 struct mdc_op_data *data2;
1137 OBD_ALLOC(data2, sizeof(*data2));
1141 LASSERT(mea != NULL);
1142 for (i = 0; i < mea->mea_count; i++) {
1143 memset(data2, 0, sizeof(*data2));
1144 data2->id1 = mea->mea_ids[i];
1145 mds = id_group(&data2->id1);
1147 if (lmv->tgts[mds].ltd_exp == NULL)
1150 rc = md_enqueue(lmv->tgts[mds].ltd_exp, locktype, it,
1151 lockmode, data2, lockh + i, lmm, lmmsize,
1152 cb_compl, cb_blocking, cb_data);
1154 CDEBUG(D_OTHER, "take lock on slave "DLID4" -> %d/%d\n",
1155 OLID4(&mea->mea_ids[i]), rc, LUSTRE_IT(it)->it_status);
1158 if (LUSTRE_IT(it)->it_data) {
1159 struct ptlrpc_request *req;
1160 req = (struct ptlrpc_request *) LUSTRE_IT(it)->it_data;
1161 ptlrpc_req_finished(req);
1164 if (LUSTRE_IT(it)->it_status)
1165 GOTO(cleanup, rc = LUSTRE_IT(it)->it_status);
1168 OBD_FREE(data2, sizeof(*data2));
1171 OBD_FREE(data2, sizeof(*data2));
1173 /* drop all taken locks */
1175 if (lockh[i].cookie)
1176 ldlm_lock_decref(lockh + i, lockmode);
1177 lockh[i].cookie = 0;
1183 lmv_enqueue_remote(struct obd_export *exp, int lock_type,
1184 struct lookup_intent *it, int lock_mode,
1185 struct mdc_op_data *data, struct lustre_handle *lockh,
1186 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1187 ldlm_blocking_callback cb_blocking, void *cb_data)
1189 struct ptlrpc_request *req = LUSTRE_IT(it)->it_data;
1190 struct obd_device *obd = exp->exp_obd;
1191 struct lmv_obd *lmv = &obd->u.lmv;
1192 struct lustre_handle plock;
1193 struct mdc_op_data rdata;
1194 struct mds_body *body = NULL;
1198 body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body));
1199 LASSERT(body != NULL);
1201 if (!(body->valid & OBD_MD_MDS))
1204 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DLID4" -> "DLID4"\n",
1205 LL_IT2STR(it), OLID4(&data->id1), OLID4(&body->id1));
1207 /* we got LOOKUP lock, but we really need attrs */
1208 pmode = LUSTRE_IT(it)->it_lock_mode;
1209 LASSERT(pmode != 0);
1210 memcpy(&plock, lockh, sizeof(plock));
1211 LUSTRE_IT(it)->it_lock_mode = 0;
1212 LUSTRE_IT(it)->it_data = NULL;
1213 LASSERT((body->valid & OBD_MD_FID) != 0);
1215 memcpy(&rdata, data, sizeof(rdata));
1216 rdata.id1 = body->id1;
1220 LUSTRE_IT(it)->it_disposition &= ~DISP_ENQ_COMPLETE;
1221 ptlrpc_req_finished(req);
1223 rc = md_enqueue(lmv->tgts[id_group(&rdata.id1)].ltd_exp,
1224 lock_type, it, lock_mode, &rdata, lockh, lmm,
1225 lmmsize, cb_compl, cb_blocking, cb_data);
1226 ldlm_lock_decref(&plock, pmode);
1231 lmv_enqueue(struct obd_export *exp, int lock_type,
1232 struct lookup_intent *it, int lock_mode,
1233 struct mdc_op_data *data, struct lustre_handle *lockh,
1234 void *lmm, int lmmsize, ldlm_completion_callback cb_compl,
1235 ldlm_blocking_callback cb_blocking, void *cb_data)
1237 struct obd_device *obd = exp->exp_obd;
1238 struct lmv_obd *lmv = &obd->u.lmv;
1239 struct lmv_obj *obj;
1243 rc = lmv_check_connect(obd);
1247 if (data->mea1 && it->it_op == IT_UNLINK) {
1248 rc = lmv_enqueue_slaves(exp, lock_type, it, lock_mode,
1249 data, lockh, lmm, lmmsize,
1250 cb_compl, cb_blocking, cb_data);
1254 if (data->namelen) {
1255 obj = lmv_grab_obj(obd, &data->id1);
1257 /* directory is splitted. look for right mds for this
1259 mds = raw_name2idx(obj->hashtype, obj->objcount,
1260 (char *)data->name, data->namelen);
1261 data->id1 = obj->objs[mds].id;
1265 CDEBUG(D_OTHER, "ENQUEUE '%s' on "DLID4"\n", LL_IT2STR(it),
1268 rc = md_enqueue(lmv->tgts[id_group(&data->id1)].ltd_exp,
1269 lock_type, it, lock_mode, data, lockh, lmm,
1270 lmmsize, cb_compl, cb_blocking, cb_data);
1271 if (rc == 0 && it->it_op == IT_OPEN)
1272 rc = lmv_enqueue_remote(exp, lock_type, it, lock_mode,
1273 data, lockh, lmm, lmmsize,
1274 cb_compl, cb_blocking, cb_data);
1279 lmv_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1280 char *filename, int namelen, __u64 valid,
1281 unsigned int ea_size, struct ptlrpc_request **request)
1283 int rc, mds = id_group(id), loop = 0;
1284 struct obd_device *obd = exp->exp_obd;
1285 struct lmv_obd *lmv = &obd->u.lmv;
1286 struct lustre_id rid = *id;
1287 struct mds_body *body;
1288 struct lmv_obj *obj;
1291 rc = lmv_check_connect(obd);
1295 LASSERT(++loop <= 2);
1296 obj = lmv_grab_obj(obd, id);
1298 /* directory is splitted. look for right mds for this name */
1299 mds = raw_name2idx(obj->hashtype, obj->objcount,
1300 filename, namelen - 1);
1301 rid = obj->objs[mds].id;
1305 CDEBUG(D_OTHER, "getattr_lock for %*s on "DLID4" -> "DLID4"\n",
1306 namelen, filename, OLID4(id), OLID4(&rid));
1308 rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp,
1309 &rid, filename, namelen,
1310 valid == OBD_MD_FLID ? valid : valid | OBD_MD_FID,
1314 * this could be cross-node reference. in this case all we have
1315 * right now is lustre_id triple. we'd like to find other
1318 body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body));
1319 LASSERT(body != NULL);
1320 LASSERT((body->valid & OBD_MD_FID) != 0
1321 || body->valid == OBD_MD_FLID);
1323 if (body->valid & OBD_MD_MDS) {
1324 struct ptlrpc_request *req = NULL;
1327 CDEBUG(D_OTHER, "request attrs for "DLID4"\n", OLID4(&rid));
1329 rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp,
1330 &rid, NULL, 1, valid, ea_size, &req);
1331 ptlrpc_req_finished(*request);
1334 } else if (rc == -ERESTART) {
1335 /* directory got splitted. time to update local object and
1336 * repeat the request with proper MDS */
1337 rc = lmv_get_mea_and_update_object(exp, &rid);
1339 ptlrpc_req_finished(*request);
1347 * llite passes id of an target inode in data->id1 and id of directory in
1350 static int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
1351 struct ptlrpc_request **request)
1353 struct obd_device *obd = exp->exp_obd;
1354 struct lmv_obd *lmv = &obd->u.lmv;
1355 struct lmv_obj *obj;
1359 rc = lmv_check_connect(obd);
1363 if (data->namelen != 0) {
1364 /* usual link request */
1365 obj = lmv_grab_obj(obd, &data->id2);
1367 rc = raw_name2idx(obj->hashtype, obj->objcount,
1368 data->name, data->namelen);
1369 data->id2 = obj->objs[rc].id;
1373 mds = id_group(&data->id2);
1375 CDEBUG(D_OTHER,"link "DLID4":%*s to "DLID4"\n",
1376 OLID4(&data->id2), data->namelen, data->name,
1379 mds = id_group(&data->id1);
1381 /* request from MDS to acquire i_links for inode by id1 */
1382 CDEBUG(D_OTHER, "inc i_nlinks for "DLID4"\n",
1386 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n",
1387 mds, OLID4(&data->id1));
1388 rc = md_link(lmv->tgts[mds].ltd_exp, data, request);
1393 static int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
1394 const char *old, int oldlen, const char *new, int newlen,
1395 struct ptlrpc_request **request)
1397 struct obd_device *obd = exp->exp_obd;
1398 struct lmv_obd *lmv = &obd->u.lmv;
1399 struct lmv_obj *obj;
1403 CDEBUG(D_OTHER, "rename %*s in "DLID4" to %*s in "DLID4"\n",
1404 oldlen, old, OLID4(&data->id1), newlen, new,
1407 rc = lmv_check_connect(obd);
1413 * MDS with old dir entry is asking another MDS to create name
1417 "create %*s(%d/%d) in "DLID4" pointing "
1418 "to "DLID4"\n", newlen, new, oldlen, newlen,
1419 OLID4(&data->id2), OLID4(&data->id1));
1421 mds = id_group(&data->id2);
1424 * target directory can be splitted, sowe should forward request
1427 obj = lmv_grab_obj(obd, &data->id2);
1429 mds = raw_name2idx(obj->hashtype, obj->objcount,
1430 (char *)new, newlen);
1431 data->id2 = obj->objs[mds].id;
1432 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", mds,
1439 obj = lmv_grab_obj(obd, &data->id1);
1442 * directory is already splitted, so we have to forward request
1445 mds = raw_name2idx(obj->hashtype, obj->objcount,
1446 (char *)old, oldlen);
1447 data->id1 = obj->objs[mds].id;
1448 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", mds,
1453 obj = lmv_grab_obj(obd, &data->id2);
1456 * directory is already splitted, so we have to forward request
1459 mds = raw_name2idx(obj->hashtype, obj->objcount,
1460 (char *)new, newlen);
1462 data->id2 = obj->objs[mds].id;
1463 CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", mds,
1468 mds = id_group(&data->id1);
1471 if (id_group(&data->id1) != id_group(&data->id2)) {
1472 CDEBUG(D_OTHER,"cross-node rename "DLID4"/%*s to "DLID4"/%*s\n",
1473 OLID4(&data->id1), oldlen, old, OLID4(&data->id2),
1477 rc = md_rename(lmv->tgts[mds].ltd_exp, data, old, oldlen,
1478 new, newlen, request);
1482 static int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
1483 struct iattr *iattr, void *ea, int ealen, void *ea2,
1484 int ea2len, void *ea3, int ea3len,
1485 struct ptlrpc_request **request)
1487 struct obd_device *obd = exp->exp_obd;
1488 struct lmv_obd *lmv = &obd->u.lmv;
1489 struct ptlrpc_request *req;
1490 struct mds_body *body;
1491 struct lmv_obj *obj;
1495 rc = lmv_check_connect(obd);
1499 obj = lmv_grab_obj(obd, &data->id1);
1501 CDEBUG(D_OTHER, "SETATTR for "DLID4", valid 0x%x%s\n",
1502 OLID4(&data->id1), iattr->ia_valid, obj ? ", splitted" : "");
1505 for (i = 0; i < obj->objcount; i++) {
1506 data->id1 = obj->objs[i].id;
1508 rc = md_setattr(lmv->tgts[id_group(&data->id1)].ltd_exp,
1509 data, iattr, ea, ealen, ea2, ea2len,
1512 if (id_equal_fid(&obj->id, &obj->objs[i].id)) {
1514 * this is master object and this request should
1515 * be returned back to llite.
1519 ptlrpc_req_finished(req);
1527 LASSERT(id_group(&data->id1) < lmv->desc.ld_tgt_count);
1528 rc = md_setattr(lmv->tgts[id_group(&data->id1)].ltd_exp,
1529 data, iattr, ea, ealen, ea2, ea2len, ea3,
1532 body = lustre_msg_buf((*request)->rq_repmsg, 0,
1534 LASSERT(body != NULL);
1535 LASSERT((body->valid & OBD_MD_FID) != 0);
1536 LASSERT(id_group(&body->id1) == id_group(&data->id1));
1542 static int lmv_sync(struct obd_export *exp, struct lustre_id *id,
1543 struct ptlrpc_request **request)
1545 struct obd_device *obd = exp->exp_obd;
1546 struct lmv_obd *lmv = &obd->u.lmv;
1550 rc = lmv_check_connect(obd);
1554 rc = md_sync(lmv->tgts[id_group(id)].ltd_exp,
1559 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock,
1560 struct ldlm_lock_desc *desc,
1561 void *data, int flag)
1563 struct lustre_handle lockh;
1564 struct lmv_obj *obj;
1569 case LDLM_CB_BLOCKING:
1570 ldlm_lock2handle(lock, &lockh);
1571 rc = ldlm_cli_cancel(&lockh);
1573 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
1577 case LDLM_CB_CANCELING:
1578 /* time to drop cached attrs for dirobj */
1579 obj = lock->l_ast_data;
1581 CDEBUG(D_OTHER, "cancel %s on "LPU64"/"LPU64
1582 ", master "DLID4"\n",
1583 lock->l_resource->lr_name.name[3] == 1 ?
1584 "LOOKUP" : "UPDATE",
1585 lock->l_resource->lr_name.name[0],
1586 lock->l_resource->lr_name.name[1],
1597 static void lmv_remove_dots(struct page *page)
1599 unsigned limit = PAGE_CACHE_SIZE;
1600 char *kaddr = page_address(page);
1601 struct ext2_dir_entry_2 *p;
1602 unsigned offs, rec_len;
1604 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
1605 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
1606 rec_len = le16_to_cpu(p->rec_len);
1608 if ((p->name_len == 1 && p->name[0] == '.') ||
1609 (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
1614 static int lmv_readpage(struct obd_export *exp, struct lustre_id *id,
1615 __u64 offset, struct page *page,
1616 struct ptlrpc_request **request)
1618 struct obd_device *obd = exp->exp_obd;
1619 struct lmv_obd *lmv = &obd->u.lmv;
1620 struct lustre_id rid = *id;
1621 struct lmv_obj *obj;
1625 #warning "we need well-desgined readdir() implementation"
1626 rc = lmv_check_connect(obd);
1630 LASSERT(id_group(id) < lmv->desc.ld_tgt_count);
1631 CDEBUG(D_OTHER, "READPAGE at %llu from "DLID4"\n",
1632 offset, OLID4(&rid));
1634 obj = lmv_grab_obj(obd, id);
1638 /* find dirobj containing page with requested offset. */
1639 for (i = 0; i < obj->objcount; i++) {
1640 if (offset < obj->objs[i].size)
1642 offset -= obj->objs[i].size;
1644 rid = obj->objs[i].id;
1646 lmv_unlock_obj(obj);
1649 CDEBUG(D_OTHER, "forward to "DLID4" with offset %lu\n",
1650 OLID4(&rid), (unsigned long)offset);
1652 rc = md_readpage(lmv->tgts[id_group(&rid)].ltd_exp, &rid,
1653 offset, page, request);
1655 if (rc == 0 && !id_equal_fid(&rid, id))
1656 /* this page isn't from master object. To avoid "." and ".."
1657 * duplication in directory, we have to remove them from all
1659 lmv_remove_dots(page);
1664 static int lmv_unlink_slaves(struct obd_export *exp, struct mdc_op_data *data,
1665 struct ptlrpc_request **req)
1667 struct obd_device *obd = exp->exp_obd;
1668 struct lmv_obd *lmv = &obd->u.lmv;
1669 struct mea *mea = data->mea1;
1670 struct mdc_op_data *data2;
1674 OBD_ALLOC(data2, sizeof(*data2));
1678 LASSERT(mea != NULL);
1679 for (i = 0; i < mea->mea_count; i++) {
1680 memset(data2, 0, sizeof(*data2));
1681 data2->id1 = mea->mea_ids[i];
1682 data2->create_mode = MDS_MODE_DONT_LOCK | S_IFDIR;
1684 if (lmv->tgts[id_group(&data2->id1)].ltd_exp == NULL)
1687 rc = md_unlink(lmv->tgts[id_group(&data2->id1)].ltd_exp,
1690 CDEBUG(D_OTHER, "unlink slave "DLID4" -> %d\n",
1691 OLID4(&mea->mea_ids[i]), rc);
1694 ptlrpc_req_finished(*req);
1700 OBD_FREE(data2, sizeof(*data2));
1704 static int lmv_delete_inode(struct obd_export *exp, struct lustre_id *id)
1709 if (lmv_delete_obj(exp, id)) {
1710 CDEBUG(D_OTHER, "lmv object "DLID4" is destroyed.\n",
1716 static int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
1717 struct ptlrpc_request **request)
1719 struct obd_device *obd = exp->exp_obd;
1720 struct lmv_obd *lmv = &obd->u.lmv;
1724 rc = lmv_check_connect(obd);
1728 if (data->namelen == 0 && data->mea1 != NULL) {
1729 /* mds asks to remove slave objects */
1730 rc = lmv_unlink_slaves(exp, data, request);
1734 if (data->namelen != 0) {
1735 struct lmv_obj *obj;
1737 obj = lmv_grab_obj(obd, &data->id1);
1739 i = raw_name2idx(obj->hashtype, obj->objcount,
1740 data->name, data->namelen);
1741 data->id1 = obj->objs[i].id;
1744 CDEBUG(D_OTHER, "unlink '%*s' in "DLID4" -> %u\n",
1745 data->namelen, data->name, OLID4(&data->id1),
1748 CDEBUG(D_OTHER, "drop i_nlink on "DLID4"\n",
1751 rc = md_unlink(lmv->tgts[id_group(&data->id1)].ltd_exp,
1756 static struct obd_device *lmv_get_real_obd(struct obd_export *exp,
1757 struct lustre_id *id)
1759 struct obd_device *obd = exp->exp_obd;
1760 struct lmv_obd *lmv = &obd->u.lmv;
1764 rc = lmv_check_connect(obd);
1766 RETURN(ERR_PTR(rc));
1767 obd = lmv->tgts[id_group(id)].ltd_exp->exp_obd;
1773 static int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
1774 void *acl, int acl_size,
1775 struct lov_stripe_md **ea,
1776 struct obd_trans_info *oti)
1778 struct obd_device *obd = exp->exp_obd;
1779 struct lmv_obd *lmv = &obd->u.lmv;
1780 struct lov_stripe_md obj_md;
1781 struct lov_stripe_md *obj_mdp = &obj_md;
1785 LASSERT(ea == NULL);
1786 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
1788 rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp, oa,
1789 acl, acl_size, &obj_mdp, oti);
1795 * to be called from MDS only. @oa should have correct store cookie and o_fid
1796 * values for "master" object, as it will be used.
1798 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
1799 void *acl, int acl_size,
1800 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1802 struct obd_device *obd = exp->exp_obd;
1803 struct lmv_obd *lmv = &obd->u.lmv;
1804 struct lustre_id mid;
1809 rc = lmv_check_connect(obd);
1813 LASSERT(oa != NULL);
1816 rc = lmv_obd_create_single(exp, oa, acl, acl_size, NULL, oti);
1818 CERROR("Can't create object, rc = %d\n", rc);
1822 /* acl is only suppied when mds create single remote obj */
1823 LASSERT(acl == NULL && acl_size == 0);
1826 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **)ea);
1828 CERROR("obd_alloc_diskmd() failed, error %d\n",
1839 * here we should take care about splitted dir, so store cookie and fid
1840 * for "master" object should already be allocated and passed in @oa.
1842 LASSERT(oa->o_id != 0);
1843 LASSERT(oa->o_fid != 0);
1845 /* save "master" object id */
1848 mea = (struct mea *)*ea;
1849 mea->mea_master = -1;
1850 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
1852 if (!mea->mea_count || mea->mea_count > lmv->desc.ld_tgt_count)
1853 mea->mea_count = lmv->desc.ld_tgt_count;
1855 for (i = 0, c = 0; c < mea->mea_count && i < lmv->desc.ld_tgt_count; i++) {
1856 struct lov_stripe_md obj_md;
1857 struct lov_stripe_md *obj_mdp = &obj_md;
1859 if (lmv->tgts[i].ltd_exp == NULL) {
1860 /* this is "master" MDS */
1861 mea->mea_master = i;
1862 mea->mea_ids[c] = mid;
1868 * "master" MDS should always be part of stripped dir,
1871 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1874 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE |
1875 OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1877 rc = obd_create(lmv->tgts[c].ltd_exp, oa, NULL, 0,
1880 CERROR("obd_create() failed on MDT target %d, "
1881 "error %d\n", c, rc);
1885 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1886 i, oa->o_id, oa->o_generation);
1890 * here, when object is created (or it is master and was passed
1891 * from caller) on desired MDS we save its fid to local mea_ids.
1896 * store cookie should be defined here for both cases (master
1897 * object and not master), because master is already created.
1901 /* fill mea by store cookie and fid */
1902 obdo2id(&mea->mea_ids[c], oa);
1905 LASSERT(c == mea->mea_count);
1907 CDEBUG(D_OTHER, "%d dirobjects created\n",
1908 (int)mea->mea_count);
1913 static int lmv_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1914 struct obd_device *tgt, int count,
1915 struct llog_catid *logid)
1917 struct llog_ctxt *ctxt;
1921 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1924 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1925 ctxt->loc_imp = tgt->u.cli.cl_import;
1931 static int lmv_llog_finish(struct obd_device *obd,
1932 struct obd_llogs *llogs, int count)
1937 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1941 static int lmv_precleanup(struct obd_device *obd, int flags)
1945 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1947 CERROR("failed to cleanup llogging subsystems\n");
1952 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1953 void *key, __u32 *vallen, void *val)
1955 struct obd_device *obd;
1956 struct lmv_obd *lmv;
1960 obd = class_exp2obd(exp);
1962 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1963 exp->exp_handle.h_cookie);
1968 if (keylen == strlen("mdsize") && !strcmp(key, "mdsize")) {
1969 __u32 *mdsize = val;
1970 *vallen = sizeof(__u32);
1971 *mdsize = sizeof(struct lustre_id) * lmv->desc.ld_tgt_count
1972 + sizeof(struct mea);
1974 } else if (keylen == strlen("mdsnum") && !strcmp(key, "mdsnum")) {
1975 struct obd_uuid *cluuid = &lmv->cluuid;
1976 struct lmv_tgt_desc *tgts;
1977 __u32 *mdsnum = val;
1981 for (i = 0; i < lmv->desc.ld_tgt_count; i++, tgts++) {
1982 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1983 *vallen = sizeof(__u32);
1989 } else if (keylen == strlen("rootid") && !strcmp(key, "rootid")) {
1990 rc = lmv_check_connect(obd);
1994 /* getting rootid from first MDS. */
1995 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
1998 } else if (keylen >= strlen("lmvdesc") && !strcmp(key, "lmvdesc")) {
1999 struct lmv_desc *desc_ret = val;
2000 *desc_ret = lmv->desc;
2002 } else if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2003 struct lmv_tgt_desc *tgts;
2006 rc = lmv_check_connect(obd);
2010 LASSERT(*vallen == sizeof(__u32));
2011 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
2014 /* all tgts should be connected when this get called. */
2015 if (!tgts || !tgts->ltd_exp) {
2016 CERROR("target not setup?\n");
2020 if (!obd_get_info(tgts->ltd_exp, keylen, key,
2025 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
2026 rc = lmv_check_connect(obd);
2030 /* forwarding this request to first MDS, it should know LOV
2032 rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key,
2035 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
2036 struct lmv_tgt_desc *tgts;
2039 rc = lmv_check_connect(obd);
2043 LASSERT(*vallen == sizeof(struct fid_extent));
2044 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count;
2047 /* all tgts should be connected when this get called. */
2048 if (!tgts || !tgts->ltd_exp) {
2049 CERROR("target not setup?\n");
2053 rc = obd_get_info(tgts->ltd_exp, keylen, key,
2061 CDEBUG(D_IOCTL, "invalid key\n");
2065 int lmv_set_info(struct obd_export *exp, obd_count keylen,
2066 void *key, obd_count vallen, void *val)
2068 struct lmv_tgt_desc *tgt;
2069 struct obd_device *obd;
2070 struct lmv_obd *lmv;
2074 obd = class_exp2obd(exp);
2076 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2077 exp->exp_handle.h_cookie);
2082 if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
2083 lmv->server_timeout = 1;
2084 lmv_set_timeouts(obd);
2088 /* maybe this could be default */
2089 if ((keylen == strlen("sec") && strcmp(key, "sec") == 0) ||
2090 (keylen == strlen("sec_flags") && strcmp(key, "sec_flags") == 0) ||
2091 (keylen == strlen("nllu") && strcmp(key, "nllu") == 0)) {
2092 struct obd_export *exp;
2095 spin_lock(&lmv->lmv_lock);
2096 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count;
2099 /* during setup time the connections to mdc might
2100 * haven't been established.
2103 struct obd_device *tgt_obd;
2105 tgt_obd = class_find_client_obd(&tgt->uuid,
2109 CERROR("can't set info %s, "
2110 "device %s not attached?\n",
2111 (char *) key, tgt->uuid.uuid);
2115 exp = tgt_obd->obd_self_export;
2118 err = obd_set_info(exp, keylen, key, vallen, val);
2122 spin_unlock(&lmv->lmv_lock);
2126 if (keylen == 5 && strcmp(key, "audit") == 0) {
2127 struct audit_attr_msg * msg = val;
2128 int mds = id_group(&msg->id);
2130 LASSERT(mds < lmv->desc.ld_tgt_count);
2132 if (IS_AUDIT_OP(msg->attr, AUDIT_FS)) {
2133 //FS audit, send message to all mds
2134 for (i = 0; i < lmv->desc.ld_tgt_count;i++) {
2135 obd_set_info(lmv->tgts[i].ltd_exp,
2136 keylen, key, vallen, val);
2139 else if (IS_AUDIT_OP(msg->attr, AUDIT_DIR)) {
2141 //if dir is splitted, send RPC to all mds involved
2142 struct lmv_obj *obj;
2143 struct lustre_id rid;
2146 obj = lmv_grab_obj(obd, &msg->id);
2149 for (i = 0; i < obj->objcount; i++) {
2150 rid = obj->objs[i].id;
2151 mds = id_group(&rid);
2152 obd_set_info(lmv->tgts[mds].ltd_exp,
2156 lmv_unlock_obj(obj);
2160 rc = obd_set_info(lmv->tgts[mds].ltd_exp,
2161 keylen, key, vallen, val);
2165 //set audit for file
2166 rc = obd_set_info(lmv->tgts[mds].ltd_exp,
2167 keylen, key, vallen, val);
2171 if (((keylen == strlen("flush_cred") &&
2172 strcmp(key, "flush_cred") == 0)) ||
2173 ((keylen == strlen("crypto_type") &&
2174 strcmp(key, "crypto_type") == 0))) {
2177 for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count;
2181 rc = obd_set_info(tgt->ltd_exp,
2182 keylen, key, vallen, val);
2190 if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
2191 struct lustre_id *id = (struct lustre_id *)val;
2193 rc = lmv_check_connect(obd);
2197 rc = obd_set_info(lmv->tgts[id_group(id)].ltd_exp,
2198 keylen, key, vallen, val);
2202 if (keylen == strlen("chkconnect") &&
2203 memcmp(key, "chkconnect", keylen) == 0) {
2204 rc = lmv_check_connect(obd);
2211 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2212 struct lov_stripe_md *lsm)
2214 struct obd_device *obd = class_exp2obd(exp);
2215 struct lmv_obd *lmv = &obd->u.lmv;
2216 struct mea *meap, *lsmp;
2220 mea_size = (sizeof(struct lustre_id) *
2221 lmv->desc.ld_tgt_count) + sizeof(struct mea);
2225 if (*lmmp && !lsm) {
2226 OBD_FREE(*lmmp, mea_size);
2231 if (*lmmp == NULL) {
2232 OBD_ALLOC(*lmmp, mea_size);
2240 lsmp = (struct mea *)lsm;
2241 meap = (struct mea *)*lmmp;
2243 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2244 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2247 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2248 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2249 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2251 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2252 meap->mea_ids[i] = meap->mea_ids[i];
2253 id_cpu_to_le(&meap->mea_ids[i]);
2259 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2260 struct lov_mds_md *lmm, int lmm_size)
2262 struct obd_device *obd = class_exp2obd(exp);
2263 struct mea **tmea = (struct mea **)lsmp;
2264 struct mea *mea = (struct mea *)lmm;
2265 struct lmv_obd *lmv = &obd->u.lmv;
2266 int mea_size, i, rc = 0;
2270 mea_size = sizeof(struct lustre_id) *
2271 lmv->desc.ld_tgt_count + sizeof(struct mea);
2276 if (*lsmp != NULL && lmm == NULL) {
2277 OBD_FREE(*tmea, mea_size);
2281 LASSERT(mea_size == lmm_size);
2283 OBD_ALLOC(*tmea, mea_size);
2290 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2291 mea->mea_magic == MEA_MAGIC_ALL_CHARS)
2293 magic = le32_to_cpu(mea->mea_magic);
2295 struct mea_old *old = (struct mea_old *)lmm;
2297 mea_size = sizeof(struct lustre_id) * old->mea_count +
2298 sizeof(struct mea_old);
2300 if (old->mea_count > 256 || old->mea_master > 256 ||
2301 lmm_size < mea_size || old->mea_master > old->mea_count) {
2302 CWARN("bad MEA: count %u, master %u, size %u\n",
2303 old->mea_count, old->mea_master, mea_size);
2304 GOTO(out_free_mea, rc = -EINVAL);
2306 magic = MEA_MAGIC_LAST_CHAR;
2309 (*tmea)->mea_magic = magic;
2310 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2311 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2313 for (i = 0; i < (*tmea)->mea_count; i++) {
2314 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2315 id_le_to_cpu(&(*tmea)->mea_ids[i]);
2320 OBD_FREE(*tmea, mea_size);
2324 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
2325 struct lov_stripe_md *ea, obd_count oa_bufs,
2326 struct brw_page *pgarr, struct obd_trans_info *oti)
2328 struct obd_device *obd = exp->exp_obd;
2329 struct lmv_obd *lmv = &obd->u.lmv;
2330 struct mea *mea = (struct mea *) ea;
2333 LASSERT(oa != NULL);
2334 LASSERT(ea != NULL);
2335 LASSERT(pgarr != NULL);
2336 LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
2338 oa->o_gr = id_gen(&mea->mea_ids[oa->o_mds]);
2339 oa->o_id = id_ino(&mea->mea_ids[oa->o_mds]);
2340 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
2342 err = obd_brw(rw, lmv->tgts[oa->o_mds].ltd_exp,
2343 oa, NULL, oa_bufs, pgarr, oti);
2347 static int lmv_cancel_unused(struct obd_export *exp,
2348 struct lov_stripe_md *lsm,
2349 int flags, void *opaque)
2351 struct obd_device *obd = exp->exp_obd;
2352 struct lmv_obd *lmv = &obd->u.lmv;
2356 LASSERT(lsm == NULL);
2358 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2359 if (!lmv->tgts[i].ltd_exp || !lmv->tgts[i].active)
2362 err = obd_cancel_unused(lmv->tgts[i].ltd_exp,
2363 NULL, flags, opaque);
2370 struct obd_ops lmv_obd_ops = {
2371 .o_owner = THIS_MODULE,
2372 .o_attach = lmv_attach,
2373 .o_detach = lmv_detach,
2374 .o_setup = lmv_setup,
2375 .o_cleanup = lmv_cleanup,
2376 .o_precleanup = lmv_precleanup,
2377 .o_process_config = lmv_process_config,
2378 .o_connect = lmv_connect,
2379 .o_disconnect = lmv_disconnect,
2380 .o_statfs = lmv_statfs,
2381 .o_llog_init = lmv_llog_init,
2382 .o_llog_finish = lmv_llog_finish,
2383 .o_get_info = lmv_get_info,
2384 .o_set_info = lmv_set_info,
2385 .o_create = lmv_obd_create,
2386 .o_packmd = lmv_packmd,
2387 .o_unpackmd = lmv_unpackmd,
2389 .o_init_ea_size = lmv_init_ea_size,
2390 .o_notify = lmv_notify,
2391 .o_iocontrol = lmv_iocontrol,
2392 .o_cancel_unused = lmv_cancel_unused,
2395 struct md_ops lmv_md_ops = {
2396 .m_getstatus = lmv_getstatus,
2397 .m_getattr = lmv_getattr,
2398 .m_change_cbdata = lmv_change_cbdata,
2399 .m_change_cbdata_name = lmv_change_cbdata_name,
2400 .m_close = lmv_close,
2401 .m_create = lmv_create,
2402 .m_done_writing = lmv_done_writing,
2403 .m_enqueue = lmv_enqueue,
2404 .m_getattr_lock = lmv_getattr_lock,
2405 .m_intent_lock = lmv_intent_lock,
2407 .m_rename = lmv_rename,
2408 .m_setattr = lmv_setattr,
2410 .m_readpage = lmv_readpage,
2411 .m_unlink = lmv_unlink,
2412 .m_get_real_obd = lmv_get_real_obd,
2413 .m_valid_attrs = lmv_valid_attrs,
2414 .m_delete_inode = lmv_delete_inode,
2415 .m_access_check = lmv_access_check,
2418 int __init lmv_init(void)
2420 struct lprocfs_static_vars lvars;
2423 obj_cache = kmem_cache_create("lmv_objects",
2424 sizeof(struct lmv_obj),
2427 CERROR("error allocating lmv objects cache\n");
2431 lprocfs_init_vars(lmv, &lvars);
2432 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2434 OBD_LMV_DEVICENAME);
2436 kmem_cache_destroy(obj_cache);
2442 static void lmv_exit(void)
2444 class_unregister_type(OBD_LMV_DEVICENAME);
2446 LASSERTF(kmem_cache_destroy(obj_cache) == 0,
2447 "can't free lmv objects cache, %d object(s)"
2448 "still in use\n", atomic_read(&obj_cache_count));
2451 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2452 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2453 MODULE_LICENSE("GPL");
2455 module_init(lmv_init);
2456 module_exit(lmv_exit);