[Ocfs2-commits] manish commits r2559 - in trunk/fs/ocfs2: . cluster
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Aug 31 20:12:45 CDT 2005
Author: manish
Signed-off-by: mfasheh
Date: 2005-08-31 20:12:43 -0500 (Wed, 31 Aug 2005)
New Revision: 2559
Added:
trunk/fs/ocfs2/export.c
trunk/fs/ocfs2/export.h
Modified:
trunk/fs/ocfs2/Makefile
trunk/fs/ocfs2/cluster/masklog.c
trunk/fs/ocfs2/cluster/masklog.h
trunk/fs/ocfs2/inode.c
trunk/fs/ocfs2/journal.c
trunk/fs/ocfs2/namei.c
trunk/fs/ocfs2/super.c
trunk/fs/ocfs2/sysfile.c
Log:
Flesh out export_operations, so we handle NFS exporting better. This includes
a change to ocfs2_iget, so it returns an ERR_PTR on error instead of NULL.
Signed-off-by: mfasheh
Modified: trunk/fs/ocfs2/Makefile
===================================================================
--- trunk/fs/ocfs2/Makefile 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/Makefile 2005-09-01 01:12:43 UTC (rev 2559)
@@ -47,6 +47,7 @@
dcache.c \
dir.c \
dlmglue.c \
+ export.c \
extent_map.c \
file.c \
heartbeat.c \
Modified: trunk/fs/ocfs2/cluster/masklog.c
===================================================================
--- trunk/fs/ocfs2/cluster/masklog.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/cluster/masklog.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -211,6 +211,7 @@
set_a_string(DCACHE);
set_a_string(CONN);
set_a_string(QUORUM);
+ set_a_string(EXPORT);
set_a_string(ERROR);
set_a_string(NOTICE);
set_a_string(KTHREAD);
Modified: trunk/fs/ocfs2/cluster/masklog.h
===================================================================
--- trunk/fs/ocfs2/cluster/masklog.h 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/cluster/masklog.h 2005-09-01 01:12:43 UTC (rev 2559)
@@ -111,6 +111,7 @@
#define ML_DCACHE 0x0000000002000000ULL /* ocfs2 dcache operations */
#define ML_CONN 0x0000000004000000ULL /* net connection management */
#define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */
+#define ML_EXPORT 0x0000000010000000ULL /* ocfs2 export operations */
/* bits that are infrequently given and frequently matched in the high word */
#define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */
#define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */
Added: trunk/fs/ocfs2/export.c
===================================================================
--- trunk/fs/ocfs2/export.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/export.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -0,0 +1,248 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * export.c
+ *
+ * Functions to facilitate NFS exporting
+ *
+ * Copyright (C) 2002, 2005 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <linux/fs.h>
+#include <linux/types.h>
+
+#define MLOG_MASK_PREFIX ML_EXPORT
+#include <cluster/masklog.h>
+
+#include "ocfs2.h"
+
+#include "dir.h"
+#include "dlmglue.h"
+#include "export.h"
+#include "inode.h"
+
+#include "buffer_head_io.h"
+
+struct ocfs2_inode_handle
+{
+ u64 ih_blkno;
+ u32 ih_generation;
+};
+
+static struct dentry *ocfs2_get_dentry(struct super_block *sb, void *vobjp)
+{
+ struct ocfs2_inode_handle *handle = vobjp;
+ struct inode *inode;
+ struct dentry *result;
+
+ mlog_entry("(0x%p, 0x%p)\n", sb, handle);
+
+ if (handle->ih_blkno == 0) {
+ mlog_errno(-ESTALE);
+ return ERR_PTR(-ESTALE);
+ }
+
+ inode = ocfs2_iget(OCFS2_SB(sb), handle->ih_blkno);
+
+ if (IS_ERR(inode)) {
+ mlog_errno(PTR_ERR(inode));
+ return (void *)inode;
+ }
+
+ if (handle->ih_generation != inode->i_generation) {
+ iput(inode);
+ mlog_errno(-ESTALE);
+ return ERR_PTR(-ESTALE);
+ }
+
+ result = d_alloc_anon(inode);
+
+ if (!result) {
+ iput(inode);
+ mlog_errno(-ENOMEM);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ mlog_exit_ptr(result);
+ return result;
+}
+
+static struct dentry *ocfs2_get_parent(struct dentry *child)
+{
+ int status;
+ u64 blkno;
+ struct dentry *parent;
+ struct inode *inode;
+ struct inode *dir = child->d_inode;
+ struct buffer_head *dirent_bh = NULL;
+ struct ocfs2_dir_entry *dirent;
+
+ mlog_entry("(0x%p, '%.*s')\n", child,
+ child->d_name.len, child->d_name.name);
+
+ mlog(0, "find parent of directory %"MLFu64"\n",
+ OCFS2_I(dir)->ip_blkno);
+
+ status = ocfs2_meta_lock(dir, NULL, NULL, 0);
+ if (status < 0) {
+ if (status != -ENOENT)
+ mlog_errno(status);
+ parent = ERR_PTR(status);
+ goto bail;
+ }
+
+ status = ocfs2_find_files_on_disk("..", 2, &blkno, dir, &dirent_bh,
+ &dirent);
+ if (status < 0) {
+ parent = ERR_PTR(-ENOENT);
+ goto bail_unlock;
+ }
+
+ inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno);
+ if (IS_ERR(inode)) {
+ mlog(ML_ERROR, "Unable to create inode %"MLFu64"\n", blkno);
+ parent = ERR_PTR(-EACCES);
+ goto bail_unlock;
+ }
+
+ parent = d_alloc_anon(inode);
+ if (!parent) {
+ iput(inode);
+ parent = ERR_PTR(-ENOMEM);
+ }
+
+bail_unlock:
+ ocfs2_meta_unlock(dir, 0);
+
+ if (dirent_bh)
+ brelse(dirent_bh);
+
+bail:
+ mlog_exit_ptr(parent);
+
+ return parent;
+}
+
+static int ocfs2_encode_fh(struct dentry *dentry, __be32 *fh, int *max_len,
+ int connectable)
+{
+ struct inode *inode = dentry->d_inode;
+ int len = *max_len;
+ int type = 1;
+ u64 blkno;
+ u32 generation;
+
+ mlog_entry("(0x%p, '%.*s', 0x%p, %d, %d)\n", dentry,
+ dentry->d_name.len, dentry->d_name.name,
+ fh, len, connectable);
+
+ if (len < 3 || (connectable && len < 6)) {
+ mlog(ML_ERROR, "fh buffer is too small for encoding\n");
+ type = 255;
+ goto bail;
+ }
+
+ blkno = OCFS2_I(inode)->ip_blkno;
+ generation = inode->i_generation;
+
+ mlog(0, "Encoding fh: blkno: %"MLFu64", generation: %u\n",
+ blkno, generation);
+
+ len = 3;
+ fh[0] = cpu_to_le32((u32)(blkno >> 32));
+ fh[1] = cpu_to_le32((u32)(blkno & 0xffffffff));
+ fh[2] = cpu_to_le32(generation);
+
+ if (connectable && !S_ISDIR(inode->i_mode)) {
+ struct inode *parent;
+
+ spin_lock(&dentry->d_lock);
+
+ parent = dentry->d_parent->d_inode;
+ blkno = OCFS2_I(parent)->ip_blkno;
+ generation = parent->i_generation;
+
+ fh[3] = cpu_to_le32((u32)(blkno >> 32));
+ fh[4] = cpu_to_le32((u32)(blkno & 0xffffffff));
+ fh[5] = cpu_to_le32(generation);
+
+ spin_unlock(&dentry->d_lock);
+
+ len = 6;
+ type = 2;
+
+ mlog(0, "Encoding parent: blkno: %"MLFu64", generation: %u\n",
+ blkno, generation);
+ }
+
+ *max_len = len;
+
+bail:
+ mlog_exit(type);
+ return type;
+}
+
+static struct dentry *ocfs2_decode_fh(struct super_block *sb, __be32 *fh,
+ int fh_len, int fileid_type,
+ int (*acceptable)(void *context,
+ struct dentry *de),
+ void *context)
+{
+ struct ocfs2_inode_handle handle, parent;
+ struct dentry *ret = NULL;
+
+ mlog_entry("(0x%p, 0x%p, %d, %d, 0x%p, 0x%p)\n",
+ sb, fh, fh_len, fileid_type, acceptable, context);
+
+ if (fh_len < 3 || fileid_type > 2)
+ goto bail;
+
+ if (fileid_type == 2) {
+ if (fh_len < 6)
+ goto bail;
+
+ parent.ih_blkno = (u64)le32_to_cpu(fh[3]) << 32;
+ parent.ih_blkno |= (u64)le32_to_cpu(fh[4]);
+ parent.ih_generation = le32_to_cpu(fh[5]);
+
+ mlog(0, "Decoding parent: blkno: %"MLFu64", generation: %u\n",
+ parent.ih_blkno, parent.ih_generation);
+ }
+
+ handle.ih_blkno = (u64)le32_to_cpu(fh[0]) << 32;
+ handle.ih_blkno |= (u64)le32_to_cpu(fh[1]);
+ handle.ih_generation = le32_to_cpu(fh[2]);
+
+ mlog(0, "Encoding fh: blkno: %"MLFu64", generation: %u\n",
+ handle.ih_blkno, handle.ih_generation);
+
+ ret = ocfs2_export_ops.find_exported_dentry(sb, &handle, &parent,
+ acceptable, context);
+
+bail:
+ mlog_exit_ptr(ret);
+ return ret;
+}
+
+struct export_operations ocfs2_export_ops = {
+ .decode_fh = ocfs2_decode_fh,
+ .encode_fh = ocfs2_encode_fh,
+
+ .get_parent = ocfs2_get_parent,
+ .get_dentry = ocfs2_get_dentry,
+};
Added: trunk/fs/ocfs2/export.h
===================================================================
--- trunk/fs/ocfs2/export.h 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/export.h 2005-09-01 01:12:43 UTC (rev 2559)
@@ -0,0 +1,31 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * export.h
+ *
+ * Function prototypes
+ *
+ * Copyright (C) 2002, 2005 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef OCFS2_EXPORT_H
+#define OCFS2_EXPORT_H
+
+extern struct export_operations ocfs2_export_ops;
+
+#endif /* OCFS2_EXPORT_H */
Modified: trunk/fs/ocfs2/inode.c
===================================================================
--- trunk/fs/ocfs2/inode.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/inode.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -100,7 +100,8 @@
* caller, or we just pulled them off the bh. Lets do some
* sanity checks to make sure they're OK. */
if (blkno == 0) {
- mlog_errno(-EINVAL);
+ inode = ERR_PTR(-EINVAL);
+ mlog_errno(PTR_ERR(inode));
goto bail;
}
@@ -119,24 +120,25 @@
unlock_new_inode(inode);
}
if (inode == NULL) {
- mlog(ML_ERROR, "access error\n");
- inode = NULL;
+ inode = ERR_PTR(-ENOMEM);
+ mlog_errno(PTR_ERR(inode));
goto bail;
}
if (is_bad_inode(inode)) {
- mlog(ML_ERROR, "access error (bad inode)\n");
iput(inode);
- inode = NULL;
+ inode = ERR_PTR(-ESTALE);
+ mlog_errno(PTR_ERR(inode));
goto bail;
}
bail:
- if (inode)
+ if (!IS_ERR(inode)) {
mlog(0, "returning inode with number %"MLFu64"\n",
OCFS2_I(inode)->ip_blkno);
+ mlog_exit_ptr(inode);
+ } else
+ mlog_errno(PTR_ERR(inode));
- mlog_exit_ptr(inode);
-
return inode;
}
Modified: trunk/fs/ocfs2/journal.c
===================================================================
--- trunk/fs/ocfs2/journal.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/journal.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -1441,7 +1441,7 @@
continue;
iter = ocfs2_iget(osb, le64_to_cpu(de->inode));
- if (!iter)
+ if (IS_ERR(iter))
continue;
mlog(0, "queue orphan %"MLFu64"\n",
Modified: trunk/fs/ocfs2/namei.c
===================================================================
--- trunk/fs/ocfs2/namei.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/namei.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -177,7 +177,7 @@
goto bail_add;
inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno);
- if (!inode) {
+ if (IS_ERR(inode)) {
mlog(ML_ERROR, "Unable to create inode %"MLFu64"\n", blkno);
ret = ERR_PTR(-EACCES);
goto bail_unlock;
@@ -197,8 +197,7 @@
bail_add:
dentry->d_op = &ocfs2_dentry_ops;
- d_add(dentry, inode);
- ret = NULL;
+ ret = d_splice_alias(inode, dentry);
bail_unlock:
/* Don't drop the cluster lock until *after* the d_add --
@@ -216,62 +215,6 @@
return ret;
}
-struct dentry *ocfs2_get_parent(struct dentry *child)
-{
- int status;
- u64 blkno;
- struct dentry *parent;
- struct inode *inode;
- struct inode *dir = child->d_inode;
- struct buffer_head *dirent_bh = NULL;
- struct ocfs2_dir_entry *dirent;
-
- mlog_entry("(0x%p, '%.*s')\n", child,
- child->d_name.len, child->d_name.name);
-
- mlog(0, "find parent of directory %"MLFu64"\n",
- OCFS2_I(dir)->ip_blkno);
-
- status = ocfs2_meta_lock(dir, NULL, NULL, 0);
- if (status < 0) {
- if (status != -ENOENT)
- mlog_errno(status);
- parent = ERR_PTR(status);
- goto bail;
- }
-
- status = ocfs2_find_files_on_disk("..", 2, &blkno, dir, &dirent_bh,
- &dirent);
- if (status < 0) {
- parent = ERR_PTR(-ENOENT);
- goto bail_unlock;
- }
-
- inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno);
- if (!inode) {
- mlog(ML_ERROR, "Unable to create inode %"MLFu64"\n", blkno);
- parent = ERR_PTR(-EACCES);
- goto bail_unlock;
- }
-
- parent = d_alloc_anon(inode);
- if (!parent) {
- iput(inode);
- parent = ERR_PTR(-ENOMEM);
- }
-
-bail_unlock:
- ocfs2_meta_unlock(dir, 0);
-
- if (dirent_bh)
- brelse(dirent_bh);
-
-bail:
- mlog_exit_ptr(parent);
-
- return parent;
-}
-
static int ocfs2_fill_new_dir(ocfs2_super *osb,
ocfs2_journal_handle *handle,
struct inode *parent,
Modified: trunk/fs/ocfs2/super.c
===================================================================
--- trunk/fs/ocfs2/super.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/super.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -52,6 +52,7 @@
#include "alloc.h"
#include "dlmglue.h"
+#include "export.h"
#include "extent_map.h"
#include "heartbeat.h"
#include "inode.h"
@@ -131,10 +132,6 @@
.put_super = ocfs2_put_super,
};
-static struct export_operations ocfs2_export_ops = {
- .get_parent = ocfs2_get_parent,
-};
-
#ifdef OCFS2_ORACORE_WORKAROUNDS
#define OCFS_SUPER_MAGIC 0xa156f7eb
#endif
@@ -200,16 +197,16 @@
mlog_entry_void();
new = ocfs2_iget(osb, osb->root_blkno);
- if (!new) {
- status = -EINVAL;
+ if (IS_ERR(new)) {
+ status = PTR_ERR(new);
mlog_errno(status);
goto bail;
}
osb->root_inode = new;
new = ocfs2_iget(osb, osb->system_dir_blkno);
- if (!new) {
- status = -EINVAL;
+ if (IS_ERR(new)) {
+ status = PTR_ERR(new);
mlog_errno(status);
goto bail;
}
Modified: trunk/fs/ocfs2/sysfile.c
===================================================================
--- trunk/fs/ocfs2/sysfile.c 2005-08-31 18:12:32 UTC (rev 2558)
+++ trunk/fs/ocfs2/sysfile.c 2005-09-01 01:12:43 UTC (rev 2559)
@@ -118,8 +118,9 @@
}
inode = ocfs2_iget(osb, blkno);
- if (!inode) {
- mlog(ML_ERROR, "Could not create inode!\n");
+ if (IS_ERR(inode)) {
+ mlog_errno(PTR_ERR(inode));
+ inode = NULL;
goto bail;
}
bail:
More information about the Ocfs2-commits
mailing list