[Ocfs-tools-commits]
jlbec commits r144 - in trunk/ocfs2/libocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Jul 6 21:17:27 CDT 2004
Author: jlbec
Date: 2004-07-06 20:17:25 -0500 (Tue, 06 Jul 2004)
New Revision: 144
Added:
trunk/ocfs2/libocfs2/cached_inode.c
trunk/ocfs2/libocfs2/extent_map.c
trunk/ocfs2/libocfs2/include/extent_map.h
Modified:
trunk/ocfs2/libocfs2/
trunk/ocfs2/libocfs2/Makefile
trunk/ocfs2/libocfs2/include/ocfs2.h
Log:
o add extent map caching
Property changes on: trunk/ocfs2/libocfs2
___________________________________________________________________
Name: svn:ignore
- cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
inode
extents
dir_iterate
lookup
ocfs2_err.et
+ cscope*
stamp-md5
.*.sw?
.*.cmd
ocfs2_err.c
ocfs2_err.h
libocfs2.a
unix_io
openfs
inode
extents
dir_iterate
lookup
extent_map
ocfs2_err.et
Modified: trunk/ocfs2/libocfs2/Makefile
===================================================================
--- trunk/ocfs2/libocfs2/Makefile 2004-07-07 00:36:10 UTC (rev 143)
+++ trunk/ocfs2/libocfs2/Makefile 2004-07-07 01:17:25 UTC (rev 144)
@@ -32,7 +32,14 @@
CFLAGS += $(OPTIMIZE)
ifneq ($(OCFS2_DEBUG_EXE),)
-BIN_PROGRAMS += unix_io openfs inode extents dir_iterate lookup
+BIN_PROGRAMS += \
+ unix_io \
+ openfs \
+ inode \
+ extents \
+ extent_map \
+ dir_iterate \
+ lookup
unix_io: unix_io.c libocfs2.a
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
@@ -54,6 +61,11 @@
$(INCLUDES) $(DEFINES) $(VERMAGIC) \
$(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
+extent_map: extent_map.c libocfs2.a
+ $(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
+ $(INCLUDES) $(DEFINES) $(VERMAGIC) \
+ $(COM_ERR_LIBS) -DDEBUG_EXE -o $@ $^
+
dir_iterate: dir_iterate.c libocfs2.a
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(CPPFLAGS) $(LOCAL_CPPFLAGS) \
$(INCLUDES) $(DEFINES) $(VERMAGIC) \
@@ -71,6 +83,8 @@
closefs.c \
freefs.c \
inode.c \
+ cached_inode.c \
+ extent_map.c \
mkjournal.c \
extents.c \
dirblock.c \
@@ -78,7 +92,7 @@
lookup.c \
sysfile.c \
link.c \
- unlink.c
+ unlink.c
HFILES = \
include/jfs_user.h \
@@ -90,7 +104,8 @@
include/ocfs1_fs_compat.h \
include/byteorder.h \
include/ocfs2.h \
- include/dir_iterate.h
+ include/dir_iterate.h \
+ include/extent_map.h
HFILES_GEN = \
ocfs2_err.h
Added: trunk/ocfs2/libocfs2/cached_inode.c
===================================================================
--- trunk/ocfs2/libocfs2/cached_inode.c 2004-07-07 00:36:10 UTC (rev 143)
+++ trunk/ocfs2/libocfs2/cached_inode.c 2004-07-07 01:17:25 UTC (rev 144)
@@ -0,0 +1,105 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * cached_inode.c
+ *
+ * Cache inode structure for the OCFS2 userspace library.
+ *
+ * Copyright (C) 2004 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, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * Authors: Joel Becker
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers XOPEN2K in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <string.h>
+
+#include "ocfs2.h"
+
+errcode_t ocfs2_read_cached_inode(ocfs2_filesys *fs, uint64_t blkno,
+ ocfs2_cached_inode **ret_ci)
+{
+ errcode_t ret;
+ char *blk;
+ ocfs2_cached_inode *cinode;
+
+ if ((blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+ (blkno > fs->fs_blocks))
+ return OCFS2_ET_BAD_BLKNO;
+
+ ret = ocfs2_malloc0(sizeof(ocfs2_cached_inode), &cinode);
+ if (ret)
+ return ret;
+
+ cinode->ci_fs = fs;
+ cinode->ci_blkno = blkno;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &blk);
+ if (ret)
+ goto cleanup;
+
+ cinode->ci_inode = (ocfs2_dinode *)blk;
+
+ ret = ocfs2_read_inode(fs, blkno, blk);
+ if (ret)
+ goto cleanup;
+
+ *ret_ci = cinode;
+
+ return 0;
+
+cleanup:
+ ocfs2_free_cached_inode(fs, cinode);
+
+ return ret;
+}
+
+errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode)
+{
+ if (!cinode)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ if (cinode->ci_map)
+ ocfs2_free_extent_map(fs, cinode);
+
+ if (cinode->ci_inode)
+ ocfs2_free(&cinode->ci_inode);
+
+ ocfs2_free(&cinode);
+
+ return 0;
+}
+
+errcode_t ocfs2_write_cached_inode(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode)
+{
+ errcode_t ret;
+
+ if (!(fs->fs_flags & OCFS2_FLAG_RW))
+ return OCFS2_ET_RO_FILESYS;
+
+ if ((cinode->ci_blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+ (cinode->ci_blkno > fs->fs_blocks))
+ return OCFS2_ET_BAD_BLKNO;
+
+ ret = ocfs2_write_inode(fs, cinode->ci_blkno,
+ (char *)cinode->ci_inode);
+
+ return ret;
+}
Added: trunk/ocfs2/libocfs2/extent_map.c
===================================================================
--- trunk/ocfs2/libocfs2/extent_map.c 2004-07-07 00:36:10 UTC (rev 143)
+++ trunk/ocfs2/libocfs2/extent_map.c 2004-07-07 01:17:25 UTC (rev 144)
@@ -0,0 +1,336 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * extent_map.c
+ *
+ * In-memory extent map for the OCFS2 userspace library.
+ *
+ * Copyright (C) 2004 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, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * Authors: Joel Becker
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <string.h>
+
+#include "ocfs2.h"
+
+#include "extent_map.h"
+
+struct extent_map_context {
+ ocfs2_cached_inode *cinode;
+ errcode_t errcode;
+};
+
+errcode_t ocfs2_extent_map_add(ocfs2_cached_inode *cinode,
+ ocfs2_extent_rec *rec)
+{
+ errcode_t ret;
+ ocfs2_extent_map *em;
+ struct list_head *next, *prev;
+ ocfs2_extent_map_entry *ent, *tmp;
+
+ if (!cinode || !cinode->ci_map)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ if (rec->e_cpos >= cinode->ci_inode->i_clusters)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ em = cinode->ci_map;
+
+ next = prev = &em->em_extents;
+ list_for_each(next, &em->em_extents) {
+ tmp = list_entry(next, ocfs2_extent_map_entry, e_list);
+ if (rec->e_cpos >=
+ (tmp->e_rec.e_cpos + tmp->e_rec.e_clusters)) {
+ prev = next;
+ continue;
+ }
+
+ if (!memcmp(rec, &tmp->e_rec,
+ sizeof(ocfs2_extent_map_entry)))
+ return 0;
+
+ if ((rec->e_cpos + rec->e_clusters) <=
+ tmp->e_rec.e_cpos)
+ break;
+
+ return OCFS2_ET_CORRUPT_EXTENT_BLOCK;
+ }
+
+ ret = ocfs2_malloc0(sizeof(ocfs2_extent_map_entry), &ent);
+ if (ret)
+ return ret;
+
+ ent->e_rec.e_cpos = rec->e_cpos;
+ ent->e_rec.e_clusters = rec->e_clusters;
+ ent->e_rec.e_blkno = rec->e_blkno;
+ list_add(&ent->e_list, prev);
+
+ return 0;
+}
+
+static int extent_map_func(ocfs2_filesys *fs,
+ ocfs2_extent_rec *rec,
+ int tree_depth,
+ uint32_t ccount,
+ uint64_t ref_blkno,
+ int ref_recno,
+ void *priv_data)
+{
+ errcode_t ret;
+ int iret = 0;
+ struct extent_map_context *ctxt = priv_data;
+
+ ret = ocfs2_extent_map_add(ctxt->cinode, rec);
+ if (ret) {
+ ctxt->errcode = ret;
+ iret |= OCFS2_EXTENT_ABORT;
+ }
+
+ return iret;
+}
+
+errcode_t ocfs2_load_extent_map(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode)
+{
+ errcode_t ret;
+ struct extent_map_context ctxt;
+
+ if (!cinode)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ ret = ocfs2_malloc0(sizeof(ocfs2_extent_map), &cinode->ci_map);
+ if (ret)
+ return ret;
+
+ INIT_LIST_HEAD(&cinode->ci_map->em_extents);
+ cinode->ci_map->em_cinode = cinode;
+
+ ctxt.cinode = cinode;
+ ctxt.errcode = 0;
+
+ ret = ocfs2_extent_iterate(fs,
+ cinode->ci_blkno,
+ OCFS2_EXTENT_FLAG_DATA_ONLY,
+ NULL,
+ extent_map_func,
+ &ctxt);
+ if (ret)
+ goto cleanup;
+
+ if (ctxt.errcode) {
+ ret = ctxt.errcode;
+ goto cleanup;
+ }
+
+ return 0;
+
+cleanup:
+ ocfs2_free_extent_map(fs, cinode);
+
+ return ret;
+}
+
+errcode_t ocfs2_extent_map_clear(ocfs2_cached_inode *cinode,
+ uint32_t cpos, uint32_t clusters)
+{
+ ocfs2_extent_map *em;
+ struct list_head *pos, *next;
+ ocfs2_extent_map_entry *ent;
+
+ if (!cinode || !cinode->ci_map)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ em = cinode->ci_map;
+
+ for (pos = em->em_extents.next, next = pos->next;
+ pos != &em->em_extents;
+ pos = next, next = pos->next) {
+ ent = list_entry(pos, ocfs2_extent_map_entry, e_list);
+
+ if ((ent->e_rec.e_cpos + ent->e_rec.e_clusters) <=
+ cpos)
+ continue;
+
+ if ((cpos + clusters) <= (ent->e_rec.e_cpos))
+ continue;
+
+ list_del(pos);
+ ocfs2_free(&ent);
+ }
+
+ return 0;
+}
+
+errcode_t ocfs2_free_extent_map(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode)
+{
+ ocfs2_extent_map *em;
+
+ if (!cinode || !cinode->ci_map)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ em = cinode->ci_map;
+
+ ocfs2_extent_map_clear(cinode, 0, cinode->ci_inode->i_clusters);
+ ocfs2_free(&cinode->ci_map);
+
+ return 0;
+}
+
+#ifdef DEBUG_EXE
+#include <stdlib.h>
+#include <getopt.h>
+
+static uint64_t read_number(const char *num)
+{
+ uint64_t val;
+ char *ptr;
+
+ val = strtoull(num, &ptr, 0);
+ if (!ptr || *ptr)
+ return 0;
+
+ return val;
+}
+
+static void print_usage(void)
+{
+ fprintf(stderr,
+ "Usage: extent_map -i <inode_blkno> <filename>\n");
+}
+
+static int walk_extents_func(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode)
+{
+ ocfs2_extent_map *em;
+ struct list_head *pos;
+ uint32_t ccount;
+ ocfs2_extent_map_entry *ent;
+
+ em = cinode->ci_map;
+
+ fprintf(stdout, "EXTENTS:\n");
+
+ ccount = 0;
+ list_for_each(pos, &em->em_extents) {
+ ent = list_entry(pos, ocfs2_extent_map_entry, e_list);
+
+ fprintf(stdout, "(%08u, %08lu, %08llu) | + %08lu = %08lu / %08lu\n",
+ ent->e_rec.e_cpos, ent->e_rec.e_clusters,
+ ent->e_rec.e_blkno, ccount,
+ ccount + ent->e_rec.e_clusters,
+ cinode->ci_inode->i_clusters);
+
+ ccount += ent->e_rec.e_clusters;
+ }
+
+ fprintf(stdout, "TOTAL: %u\n", cinode->ci_inode->i_clusters);
+
+ return 0;
+}
+
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+ errcode_t ret;
+ uint64_t blkno;
+ int c;
+ char *filename;
+ ocfs2_filesys *fs;
+ ocfs2_cached_inode *cinode;
+
+ blkno = OCFS2_SUPER_BLOCK_BLKNO;
+
+ initialize_ocfs_error_table();
+
+ while ((c = getopt(argc, argv, "i:")) != EOF) {
+ switch (c) {
+ case 'i':
+ blkno = read_number(optarg);
+ if (blkno <= OCFS2_SUPER_BLOCK_BLKNO) {
+ fprintf(stderr,
+ "Invalid inode block: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ default:
+ print_usage();
+ return 1;
+ break;
+ }
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Missing filename\n");
+ print_usage();
+ return 1;
+ }
+ filename = argv[optind];
+
+ ret = ocfs2_open(filename, OCFS2_FLAG_RO, 0, 0, &fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while opening file \"%s\"", filename);
+ goto out;
+ }
+
+ ret = ocfs2_read_cached_inode(fs, blkno, &cinode);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while reading inode %llu", blkno);
+ goto out_close;
+ }
+
+ fprintf(stdout, "OCFS2 inode %llu on \"%s\" has depth %d\n",
+ blkno, filename,
+ cinode->ci_inode->id2.i_list.l_tree_depth);
+
+ ret = ocfs2_load_extent_map(fs, cinode);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while loading extents");
+ goto out_free;
+ }
+
+ walk_extents_func(fs, cinode);
+
+out_free:
+ ocfs2_free_cached_inode(fs, cinode);
+
+out_close:
+ ret = ocfs2_close(fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while closing file \"%s\"", filename);
+ }
+
+out:
+ return 0;
+}
+#endif /* DEBUG_EXE */
+
+
Added: trunk/ocfs2/libocfs2/include/extent_map.h
===================================================================
--- trunk/ocfs2/libocfs2/include/extent_map.h 2004-07-07 00:36:10 UTC (rev 143)
+++ trunk/ocfs2/libocfs2/include/extent_map.h 2004-07-07 01:17:25 UTC (rev 144)
@@ -0,0 +1,44 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * extent_map.h
+ *
+ * Internal extent map structures for the OCFS2 userspace library.
+ *
+ * Copyright (C) 2004 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, version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * Authors: Joel Becker
+ */
+
+#ifndef _EXTENT_MAP_H
+#define _EXTENT_MAP_H
+
+#include "kernel-list.h"
+
+typedef struct _ocfs2_extent_map_entry ocfs2_extent_map_entry;
+
+struct _ocfs2_extent_map {
+ ocfs2_cached_inode *em_cinode;
+ struct list_head em_extents;
+};
+
+struct _ocfs2_extent_map_entry {
+ struct list_head e_list;
+ ocfs2_extent_rec e_rec;
+};
+
+#endif /* _EXTENT_MAP_H */
Modified: trunk/ocfs2/libocfs2/include/ocfs2.h
===================================================================
--- trunk/ocfs2/libocfs2/include/ocfs2.h 2004-07-07 00:36:10 UTC (rev 143)
+++ trunk/ocfs2/libocfs2/include/ocfs2.h 2004-07-07 01:17:25 UTC (rev 144)
@@ -128,7 +128,9 @@
typedef struct _ocfs2_filesys ocfs2_filesys;
+typedef struct _ocfs2_cached_inode ocfs2_cached_inode;
typedef struct _io_channel io_channel;
+typedef struct _ocfs2_extent_map ocfs2_extent_map;
struct _ocfs2_filesys {
char *fs_devname;
@@ -149,6 +151,12 @@
void *fs_private;
};
+struct _ocfs2_cached_inode {
+ struct _ocfs2_filesys *ci_fs;
+ uint64_t ci_blkno;
+ ocfs2_dinode *ci_inode;
+ ocfs2_extent_map *ci_map;
+};
errcode_t ocfs2_malloc(unsigned long size, void *ptr);
@@ -184,6 +192,22 @@
char *inode_buf);
errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir);
+errcode_t ocfs2_read_cached_inode(ocfs2_filesys *fs, uint64_t blkno,
+ ocfs2_cached_inode **ret_ci);
+errcode_t ocfs2_write_cached_inode(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode);
+errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode);
+
+errcode_t ocfs2_load_extent_map(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode);
+errcode_t ocfs2_free_extent_map(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode);
+errcode_t ocfs2_extent_map_add(ocfs2_cached_inode *cinode,
+ ocfs2_extent_rec *rec);
+errcode_t ocfs2_extent_map_clear(ocfs2_cached_inode *cinode,
+ uint32_t cpos, uint32_t clusters);
+
errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
uint32_t size, int flags,
char **ret_jsb);
More information about the Ocfs-tools-commits
mailing list