/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * linux/mds/mds_fs.c
- *
+ * mds/mds_fs.c
* Lustre Metadata Server (MDS) filesystem interface code
*
- * Copyright (C) 2002 Cluster File Systems, Inc.
+ * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
+ * Author: Andreas Dilger <adilger@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
*
- * This code is issued under the GNU General Public License.
- * See the file COPYING in this distribution
+ * Lustre is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
*
- * by Andreas Dilger <adilger@clusterfs.com>
+ * Lustre is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
+ * You should have received a copy of the GNU General Public License
+ * along with Lustre; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define EXPORT_SYMTAB
#include <linux/module.h>
#include <linux/kmod.h>
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+#include <linux/mount.h>
+#endif
#include <linux/lustre_mds.h>
#include <linux/obd_class.h>
#include <linux/obd_support.h>
#include <linux/lustre_lib.h>
+#include <linux/lustre_fsfilt.h>
-LIST_HEAD(mds_fs_types);
-
-struct mds_fs_type {
- struct list_head mft_list;
- struct mds_fs_operations *mft_ops;
- char *mft_name;
-};
-
-#define MDS_MAX_CLIENTS 1024
+/* This limit is arbitrary, but for now we fit it in 1 page (32k clients) */
+#define MDS_MAX_CLIENTS (PAGE_SIZE * 8)
#define MDS_MAX_CLIENT_WORDS (MDS_MAX_CLIENTS / sizeof(unsigned long))
static unsigned long last_rcvd_slots[MDS_MAX_CLIENT_WORDS];
+#define LAST_RCVD "last_rcvd"
+
/* Add client data to the MDS. We use a bitmap to locate a free space
* in the last_rcvd file if cl_off is -1 (i.e. a new client).
* Otherwise, we have just read the data from the last_rcvd file and
* we know its offset.
*/
-int mds_client_add(struct mds_export_data *med, int cl_off)
+int mds_client_add(struct mds_obd *mds, struct mds_export_data *med, int cl_off)
{
- if (cl_off == -1) {
- unsigned long *word;
- int bit;
+ int new_client = (cl_off == -1);
+ /* the bitmap operations can handle cl_off > sizeof(long) * 8, so
+ * there's no need for extra complication here
+ */
+ if (new_client) {
+ cl_off = find_first_zero_bit(last_rcvd_slots, MDS_MAX_CLIENTS);
repeat:
- word = last_rcvd_slots;
- while(*word == ~0UL)
- ++word;
- if (word - last_rcvd_slots >= MDS_MAX_CLIENT_WORDS) {
+ if (cl_off >= MDS_MAX_CLIENTS) {
CERROR("no room for clients - fix MDS_MAX_CLIENTS\n");
return -ENOMEM;
}
- bit = ffz(*word);
- if (test_and_set_bit(bit, word)) {
- CERROR("found bit %d set for word %d - fix locking\n",
- bit, word - last_rcvd_slots);
- LBUG();
+ if (test_and_set_bit(cl_off, last_rcvd_slots)) {
+ CERROR("MDS client %d: found bit is set in bitmap\n",
+ cl_off);
+ cl_off = find_next_zero_bit(last_rcvd_slots,
+ MDS_MAX_CLIENTS, cl_off);
goto repeat;
}
- cl_off = (word - last_rcvd_slots) * sizeof(*word) + bit;
} else {
- /* test_and_set_bit can handle cl_off > sizeof(long), so there's
- * no need to frob it */
if (test_and_set_bit(cl_off, last_rcvd_slots)) {
- CERROR("bit %d already set in bitmap - bad bad\n",
+ CERROR("MDS client %d: bit already set in bitmap!!\n",
cl_off);
LBUG();
}
cl_off, med->med_mcd->mcd_uuid);
med->med_off = cl_off;
+
+ if (new_client) {
+ struct obd_run_ctxt saved;
+ loff_t off = MDS_LR_CLIENT + (cl_off * MDS_LR_SIZE);
+ ssize_t written;
+
+ push_ctxt(&saved, &mds->mds_ctxt, NULL);
+ written = lustre_fwrite(mds->mds_rcvd_filp,
+ (char *)med->med_mcd,
+ sizeof(*med->med_mcd), &off);
+ pop_ctxt(&saved, &mds->mds_ctxt, NULL);
+
+ if (written != sizeof(*med->med_mcd)) {
+ if (written < 0)
+ RETURN(written);
+ RETURN(-EIO);
+ }
+ CDEBUG(D_INFO, "wrote client mcd at off %u (len %u)\n",
+ MDS_LR_CLIENT + (cl_off * MDS_LR_SIZE),
+ (unsigned int)sizeof(*med->med_mcd));
+ }
return 0;
}
int mds_client_free(struct obd_export *exp)
{
struct mds_export_data *med = &exp->exp_mds_data;
- unsigned long *word;
- int bit;
+ struct mds_obd *mds = &exp->exp_obd->u.mds;
+ struct mds_client_data zero_mcd;
+ struct obd_run_ctxt saved;
+ int written;
+ loff_t off;
if (!med->med_mcd)
RETURN(0);
- CDEBUG(D_INFO, "freeing client at offset %d with UUID '%s'\n",
- med->med_off, med->med_mcd->mcd_uuid);
+ off = MDS_LR_CLIENT + (med->med_off * MDS_LR_SIZE);
- word = last_rcvd_slots + med->med_off / sizeof(unsigned long);
- bit = med->med_off % sizeof(unsigned long);
+ CDEBUG(D_INFO, "freeing client at offset %u (%lld)with UUID '%s'\n",
+ med->med_off, off, med->med_mcd->mcd_uuid);
- if (!test_and_clear_bit(bit, word)) {
- CERROR("bit %d already clear in word %d - bad bad\n",
- bit, word - last_rcvd_slots);
+ if (!test_and_clear_bit(med->med_off, last_rcvd_slots)) {
+ CERROR("MDS client %u: bit already clear in bitmap!!\n",
+ med->med_off);
LBUG();
}
+ memset(&zero_mcd, 0, sizeof zero_mcd);
+ push_ctxt(&saved, &mds->mds_ctxt, NULL);
+ written = lustre_fwrite(mds->mds_rcvd_filp, (const char *)&zero_mcd,
+ sizeof(zero_mcd), &off);
+ pop_ctxt(&saved, &mds->mds_ctxt, NULL);
+
+ if (written != sizeof(zero_mcd)) {
+ CERROR("error zeroing out client %s off %d in %s: %d\n",
+ med->med_mcd->mcd_uuid, med->med_off, LAST_RCVD,
+ written);
+ } else {
+ CDEBUG(D_INFO, "zeroed out disconnecting client %s at off %d\n",
+ med->med_mcd->mcd_uuid, med->med_off);
+ }
+
OBD_FREE(med->med_mcd, sizeof(*med->med_mcd));
return 0;
return 0;
}
-#define LAST_RCVD "last_rcvd"
-
static int mds_read_last_rcvd(struct obd_device *obddev, struct file *f)
{
struct mds_obd *mds = &obddev->u.mds;
struct mds_server_data *msd;
struct mds_client_data *mcd = NULL;
- loff_t fsize = f->f_dentry->d_inode->i_size;
loff_t off = 0;
int cl_off;
- __u64 last_rcvd = 0;
+ unsigned long last_rcvd_size = f->f_dentry->d_inode->i_size;
+ __u64 last_transno = 0;
__u64 last_mount;
- int clients = 0;
int rc = 0;
OBD_ALLOC(msd, sizeof(*msd));
if (rc != sizeof(*msd)) {
CERROR("error reading MDS %s: rc = %d\n", LAST_RCVD, rc);
- if (rc > 0) {
+ if (rc > 0)
rc = -EIO;
- }
GOTO(err_msd, rc);
}
+ CDEBUG(D_INODE, "last_rcvd has size %lu (msd + %lu clients)\n",
+ last_rcvd_size, (last_rcvd_size - MDS_LR_CLIENT)/MDS_LR_SIZE);
+
/*
- * When we do a clean MDS shutdown, we save the last_rcvd into
- * the header. If we find clients with higher last_rcvd values
- * then those clients may need recovery done.
+ * When we do a clean MDS shutdown, we save the last_transno into
+ * the header.
*/
- last_rcvd = le64_to_cpu(msd->msd_last_rcvd);
- mds->mds_last_rcvd = last_rcvd;
- CDEBUG(D_INODE, "got %Lu for server last_rcvd value\n",
- (unsigned long long)last_rcvd);
+ last_transno = le64_to_cpu(msd->msd_last_transno);
+ mds->mds_last_transno = last_transno;
+ CDEBUG(D_INODE, "got "LPU64" for server last_rcvd value\n",
+ last_transno);
last_mount = le64_to_cpu(msd->msd_mount_count);
mds->mds_mount_count = last_mount;
- CDEBUG(D_INODE, "got %Lu for server last_mount value\n",
- (unsigned long long)last_mount);
+ CDEBUG(D_INODE, "got "LPU64" for server last_mount value\n",last_mount);
+
+ /* off is adjusted by lustre_fread, so we don't adjust it in the loop */
+ for (off = MDS_LR_CLIENT, cl_off = 0; off < last_rcvd_size; cl_off++) {
+ int mount_age;
- for (off = MDS_LR_CLIENT, cl_off = 0, rc = sizeof(*mcd);
- off <= fsize - sizeof(*mcd) && rc == sizeof(*mcd);
- off = MDS_LR_CLIENT + ++cl_off * MDS_LR_SIZE) {
if (!mcd) {
OBD_ALLOC(mcd, sizeof(*mcd));
if (!mcd)
if (rc != sizeof(*mcd)) {
CERROR("error reading MDS %s offset %d: rc = %d\n",
LAST_RCVD, cl_off, rc);
- if (rc > 0)
+ if (rc > 0) /* XXX fatal error or just abort reading? */
rc = -EIO;
break;
}
- last_rcvd = le64_to_cpu(mcd->mcd_last_rcvd);
+ if (mcd->mcd_uuid[0] == '\0') {
+ CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
+ cl_off);
+ continue;
+ }
+
+ last_transno = le64_to_cpu(mcd->mcd_last_transno);
- /* Do client recovery here (open files, etc) */
- if (last_rcvd && (last_mount - le64_to_cpu(mcd->mcd_mount_count)
- < MDS_MOUNT_RECOV)) {
- struct obd_export *export = class_new_export(obddev);
- if (!export) {
+ /* These exports are cleaned up by mds_disconnect(), so they
+ * need to be set up like real exports as mds_connect() does.
+ */
+ mount_age = last_mount - le64_to_cpu(mcd->mcd_mount_count);
+ if (mount_age < MDS_MOUNT_RECOV) {
+ struct obd_export *exp = class_new_export(obddev);
+ struct mds_export_data *med;
+
+ if (!exp) {
rc = -ENOMEM;
break;
}
- export->exp_mds_data.med_mcd = mcd;
- mds_client_add(&export->exp_mds_data, cl_off);
+
+ memcpy(&exp->exp_client_uuid.uuid, mcd->mcd_uuid,
+ sizeof exp->exp_client_uuid.uuid);
+ med = &exp->exp_mds_data;
+ med->med_mcd = mcd;
+ mds_client_add(mds, med, cl_off);
+ /* create helper if export init gets more complex */
+ INIT_LIST_HEAD(&med->med_open_head);
+ spin_lock_init(&med->med_open_lock);
+
mcd = NULL;
- clients++;
+ obddev->obd_recoverable_clients++;
} else {
CDEBUG(D_INFO,
- "ignored client %d, UUID '%s', last_mount %Ld\n",
+ "discarded client %d, UUID '%s', count %Ld\n",
cl_off, mcd->mcd_uuid,
(long long)le64_to_cpu(mcd->mcd_mount_count));
}
- if (last_rcvd > mds->mds_last_rcvd) {
- CDEBUG(D_OTHER,
- "client at offset %d has last_rcvd = %Lu\n",
- cl_off, (unsigned long long)last_rcvd);
- mds->mds_last_rcvd = last_rcvd;
- }
+ CDEBUG(D_OTHER, "client at offset %d has last_rcvd = %Lu\n",
+ cl_off, (unsigned long long)last_transno);
+
+ if (last_transno > mds->mds_last_transno)
+ mds->mds_last_transno = last_transno;
+ }
+
+ obddev->obd_last_committed = mds->mds_last_transno;
+ if (obddev->obd_recoverable_clients) {
+ CERROR("RECOVERY: %d recoverable clients, last_transno "
+ LPU64"\n",
+ obddev->obd_recoverable_clients, mds->mds_last_transno);
+ obddev->obd_next_recovery_transno = obddev->obd_last_committed
+ + 1;
+ obddev->obd_flags |= OBD_RECOVERING;
}
- CDEBUG(D_INODE, "got %Lu for highest last_rcvd value, %d/%d clients\n",
- (unsigned long long)mds->mds_last_rcvd, clients, cl_off);
if (mcd)
OBD_FREE(mcd, sizeof(*mcd));
- /* After recovery, there can be no local uncommitted transactions */
- mds->mds_last_committed = mds->mds_last_rcvd;
-
return 0;
err_msd:
struct file *f;
int rc;
- push_ctxt(&saved, &mds->mds_ctxt);
+ push_ctxt(&saved, &mds->mds_ctxt, NULL);
dentry = simple_mkdir(current->fs->pwd, "ROOT", 0755);
if (IS_ERR(dentry)) {
rc = PTR_ERR(dentry);
if (!S_ISREG(f->f_dentry->d_inode->i_mode)) {
CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
f->f_dentry->d_inode->i_mode);
- GOTO(err_pop, rc = -ENOENT);
+ GOTO(err_filp, rc = -ENOENT);
}
- rc = mds_fs_journal_data(mds, f);
+ rc = fsfilt_journal_data(obddev, f);
if (rc) {
CERROR("cannot journal data on %s: rc = %d\n", LAST_RCVD, rc);
GOTO(err_filp, rc);
}
mds->mds_rcvd_filp = f;
err_pop:
- pop_ctxt(&saved);
+ pop_ctxt(&saved, &mds->mds_ctxt, NULL);
return rc;
goto err_pop;
}
-static struct mds_fs_operations *mds_search_fs_type(const char *name)
-{
- struct list_head *p;
- struct mds_fs_type *type;
-
- /* lock mds_fs_types list */
- list_for_each(p, &mds_fs_types) {
- type = list_entry(p, struct mds_fs_type, mft_list);
- if (!strcmp(type->mft_name, name)) {
- /* unlock mds_fs_types list */
- return type->mft_ops;
- }
- }
- /* unlock mds_fs_types list */
- return NULL;
-}
-
-int mds_register_fs_type(struct mds_fs_operations *ops, const char *name)
-{
- struct mds_fs_operations *found;
- struct mds_fs_type *type;
-
- if ((found = mds_search_fs_type(name))) {
- if (found != ops) {
- CERROR("different operations for type %s\n", name);
- RETURN(-EEXIST);
- }
- return 0;
- }
- OBD_ALLOC(type, sizeof(*type));
- if (!type)
- RETURN(-ENOMEM);
-
- INIT_LIST_HEAD(&type->mft_list);
- type->mft_ops = ops;
- type->mft_name = strdup(name);
- if (!type->mft_name) {
- OBD_FREE(type, sizeof(*type));
- RETURN(-ENOMEM);
- }
- MOD_INC_USE_COUNT;
- list_add(&type->mft_list, &mds_fs_types);
-
- return 0;
-}
-
-void mds_unregister_fs_type(const char *name)
-{
- struct list_head *p;
-
- /* lock mds_fs_types list */
- list_for_each(p, &mds_fs_types) {
- struct mds_fs_type *type;
-
- type = list_entry(p, struct mds_fs_type, mft_list);
- if (!strcmp(type->mft_name, name)) {
- list_del(p);
- kfree(type->mft_name);
- OBD_FREE(type, sizeof(*type));
- MOD_DEC_USE_COUNT;
- break;
- }
- }
- /* unlock mds_fs_types list */
-}
-
-struct mds_fs_operations *mds_fs_get_ops(char *fstype)
-{
- struct mds_fs_operations *fs_ops;
-
- if (!(fs_ops = mds_search_fs_type(fstype))) {
- char name[32];
- int rc;
-
- snprintf(name, sizeof(name) - 1, "mds_%s", fstype);
- name[sizeof(name) - 1] = '\0';
-
- if ((rc = request_module(name))) {
- fs_ops = mds_search_fs_type(fstype);
- CDEBUG(D_INFO, "Loaded module '%s'\n", name);
- if (!fs_ops)
- rc = -ENOENT;
- }
-
- if (rc) {
- CERROR("Can't find MDS fs interface '%s'\n", name);
- RETURN(ERR_PTR(rc));
- }
- }
- __MOD_INC_USE_COUNT(fs_ops->fs_owner);
-
- return fs_ops;
-}
-
-void mds_fs_put_ops(struct mds_fs_operations *fs_ops)
-{
- __MOD_DEC_USE_COUNT(fs_ops->fs_owner);
-}
-
int mds_fs_setup(struct obd_device *obddev, struct vfsmount *mnt)
{
struct mds_obd *mds = &obddev->u.mds;
- int rc;
-
- mds->mds_fsops = mds_fs_get_ops(mds->mds_fstype);
- if (IS_ERR(mds->mds_fsops))
- RETURN(PTR_ERR(mds->mds_fsops));
+ ENTRY;
mds->mds_vfsmnt = mnt;
mds->mds_ctxt.pwd = mnt->mnt_root;
mds->mds_ctxt.fs = get_ds();
- /*
- * Replace the client filesystem delete_inode method with our own,
- * so that we can clear the object ID before the inode is deleted.
- * The fs_delete_inode method will call cl_delete_inode for us.
- * We need to do this for the MDS superblock only, hence we install
- * a modified copy of the original superblock method table.
- *
- * We still assume that there is only a single MDS client filesystem
- * type, as we don't have access to the mds struct in delete_inode
- * and store the client delete_inode method in a global table. This
- * will only become a problem if/when multiple MDSs are running on a
- * single host with different underlying filesystems.
- */
- OBD_ALLOC(mds->mds_sop, sizeof(*mds->mds_sop));
- if (!mds->mds_sop)
- GOTO(out_dec, rc = -ENOMEM);
-
- memcpy(mds->mds_sop, mds->mds_sb->s_op, sizeof(*mds->mds_sop));
- mds->mds_fsops->cl_delete_inode = mds->mds_sop->delete_inode;
- mds->mds_sop->delete_inode = mds->mds_fsops->fs_delete_inode;
- mds->mds_sb->s_op = mds->mds_sop;
-
- rc = mds_fs_prep(obddev);
-
- if (rc)
- GOTO(out_free, rc);
-
- return 0;
-
-out_free:
- OBD_FREE(mds->mds_sop, sizeof(*mds->mds_sop));
-out_dec:
- mds_fs_put_ops(mds->mds_fsops);
- return rc;
+ RETURN(mds_fs_prep(obddev));
}
-void mds_fs_cleanup(struct obd_device *obddev)
+int mds_fs_cleanup(struct obd_device *obddev)
{
struct mds_obd *mds = &obddev->u.mds;
+ struct obd_run_ctxt saved;
+ int rc = 0;
class_disconnect_all(obddev); /* this cleans up client info too */
mds_server_free_data(mds);
- OBD_FREE(mds->mds_sop, sizeof(*mds->mds_sop));
- mds_fs_put_ops(mds->mds_fsops);
-}
+ push_ctxt(&saved, &mds->mds_ctxt, NULL);
+ if (mds->mds_rcvd_filp) {
+ rc = filp_close(mds->mds_rcvd_filp, 0);
+ mds->mds_rcvd_filp = NULL;
+
+ if (rc)
+ CERROR("last_rcvd file won't close, rc=%d\n", rc);
+ }
+ pop_ctxt(&saved, &mds->mds_ctxt, NULL);
-EXPORT_SYMBOL(mds_register_fs_type);
-EXPORT_SYMBOL(mds_unregister_fs_type);
+ return rc;
+}