[Ocfs2-tools-commits] jlbec commits r364 - in trunk/libocfs2: .
include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Nov 4 15:48:25 CST 2004
Author: jlbec
Date: 2004-11-04 15:48:23 -0600 (Thu, 04 Nov 2004)
New Revision: 364
Added:
trunk/libocfs2/alloc.c
Modified:
trunk/libocfs2/Makefile
trunk/libocfs2/chainalloc.c
trunk/libocfs2/include/ocfs2.h
trunk/libocfs2/ocfs2_err.et.in
Log:
work-in-progress alloc.c. It compiles, but doesn't work
Modified: trunk/libocfs2/Makefile
===================================================================
--- trunk/libocfs2/Makefile 2004-11-04 01:25:57 UTC (rev 363)
+++ trunk/libocfs2/Makefile 2004-11-04 21:48:23 UTC (rev 364)
@@ -62,6 +62,7 @@
fileio.c \
chain.c \
chainalloc.c \
+ alloc.c \
checkhb.c \
kernel-rbtree.c \
bitops.c
Added: trunk/libocfs2/alloc.c
===================================================================
--- trunk/libocfs2/alloc.c 2004-11-04 01:25:57 UTC (rev 363)
+++ trunk/libocfs2/alloc.c 2004-11-04 21:48:23 UTC (rev 364)
@@ -0,0 +1,230 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * alloc.c
+ *
+ * Allocate inodes, extent_blocks, and actual data space. Part of 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.
+ */
+
+#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
+#define _LARGEFILE64_SOURCE
+
+#include <string.h>
+#include <inttypes.h>
+
+#include "ocfs2.h"
+
+static errcode_t ocfs2_chain_alloc_with_io(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode,
+ uint64_t *blkno)
+{
+ errcode_t ret;
+
+ if (!cinode->ci_chains) {
+ ret = ocfs2_load_chain_allocator(fs, cinode);
+ if (ret)
+ return ret;
+ }
+
+ ret = ocfs2_chain_alloc(fs, cinode, blkno);
+ if (ret)
+ return ret;
+
+ return ocfs2_write_chain_allocator(fs, cinode);
+}
+
+static errcode_t ocfs2_chain_free_with_io(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode,
+ uint64_t blkno)
+{
+ errcode_t ret;
+
+ if (!cinode->ci_chains) {
+ ret = ocfs2_load_chain_allocator(fs, cinode);
+ if (ret)
+ return ret;
+ }
+
+ ret = ocfs2_chain_free(fs, cinode, blkno);
+ if (ret)
+ return ret;
+
+ return ocfs2_write_chain_allocator(fs, cinode);
+}
+
+static errcode_t ocfs2_load_allocator(ocfs2_filesys *fs,
+ int type, int node_num,
+ ocfs2_cached_inode **alloc_cinode)
+{
+ errcode_t ret;
+ uint64_t blkno;
+
+ if (!*alloc_cinode) {
+ ret = ocfs2_lookup_system_inode(fs, type, node_num,
+ &blkno);
+ if (ret)
+ return ret;
+ ret = ocfs2_read_cached_inode(fs, blkno, alloc_cinode);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *blkno)
+{
+ errcode_t ret;
+
+ ret = ocfs2_load_allocator(fs, INODE_ALLOC_SYSTEM_INODE,
+ 0, &fs->fs_inode_alloc);
+ if (ret)
+ return ret;
+
+ return ocfs2_chain_alloc_with_io(fs, fs->fs_inode_alloc, blkno);
+}
+
+errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *blkno)
+{
+ errcode_t ret;
+
+ ret = ocfs2_load_allocator(fs, GLOBAL_INODE_ALLOC_SYSTEM_INODE,
+ 0, &fs->fs_system_inode_alloc);
+ if (ret)
+ return ret;
+
+ return ocfs2_chain_alloc_with_io(fs, fs->fs_system_inode_alloc,
+ blkno);
+}
+
+errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t blkno)
+{
+ errcode_t ret;
+
+ ret = ocfs2_load_allocator(fs, INODE_ALLOC_SYSTEM_INODE,
+ 0, &fs->fs_inode_alloc);
+ if (ret)
+ return ret;
+
+ return ocfs2_chain_free_with_io(fs, fs->fs_inode_alloc, blkno);
+}
+
+void ocfs2_init_inode(ocfs2_filesys *fs, ocfs2_dinode *di,
+ uint64_t blkno)
+{
+ ocfs2_extent_list *fel;
+
+ di->i_generation = 0; /* FIXME */
+ di->i_blkno = blkno;
+ di->i_suballoc_node = 0;
+ di->i_suballoc_bit = 0; /* FIXME */
+ di->i_uid = di->i_gid = 0;
+ if (S_ISDIR(di->i_mode))
+ di->i_links_count = 2;
+ else
+ di->i_links_count = 1;
+ strcpy(di->i_signature, OCFS2_INODE_SIGNATURE);
+ di->i_flags |= OCFS2_VALID_FL;
+ di->i_atime = di->i_ctime = di->i_mtime = 0; /* FIXME */
+ di->i_dtime = 0;
+
+ fel = &di->id2.i_list;
+ fel->l_tree_depth = 0;
+ fel->l_next_free_rec = 0;
+ fel->l_count = ocfs2_extent_recs_per_inode(fs->fs_blocksize);
+}
+
+#ifdef DEBUG_EXE
+#include <stdio.h>
+
+static void print_usage(void)
+{
+ fprintf(stdout, "debug_alloc <newfile> <device>\n");
+}
+
+int main(int argc, char *argv[])
+{
+ errcode_t ret;
+ ocfs2_filesys *fs;
+ char *buf;
+ ocfs2_dinode *di;
+ uint64_t blkno;
+
+ if (argc < 3) {
+ print_usage();
+ return 1;
+ }
+
+ initialize_ocfs_error_table();
+
+ ret = ocfs2_open(argv[2], OCFS2_FLAG_RW, 0, 0, &fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while opening \"%s\"", argv[2]);
+ goto out;
+ }
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while allocating buffer");
+ goto out_close;
+ }
+
+ di = (ocfs2_dinode *)buf;
+
+ ret = ocfs2_new_inode(fs, &blkno);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while allocating a new inode");
+ goto out_free;
+ }
+
+ ocfs2_init_inode(fs, di, blkno);
+
+ ret = ocfs2_write_inode(fs, blkno, buf);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while writing new inode %"PRIu64, blkno);
+ goto out_free;
+ }
+
+ ret = ocfs2_link(fs, fs->fs_root_blkno, argv[1],
+ blkno, OCFS2_FT_REG_FILE);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while linking inode %"PRIu64, blkno);
+ }
+
+out_free:
+ ocfs2_free(&buf);
+
+out_close:
+ ret = ocfs2_close(fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while closing \"%s\"", argv[2]);
+ }
+
+out:
+ return ret;
+}
+
+#endif /* DEBUG_EXE */
Modified: trunk/libocfs2/chainalloc.c
===================================================================
--- trunk/libocfs2/chainalloc.c 2004-11-04 01:25:57 UTC (rev 363)
+++ trunk/libocfs2/chainalloc.c 2004-11-04 21:48:23 UTC (rev 364)
@@ -229,6 +229,51 @@
return ocfs2_bitmap_write(cinode->ci_chains);
}
+/* FIXME: should take a hint, no? */
+/* FIXME: Better name, too */
+errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode,
+ uint64_t *blkno)
+{
+ errcode_t ret;
+ int oldval;
+
+ if (!cinode->ci_chains)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ ret = ocfs2_bitmap_find_next_clear(cinode->ci_chains, 0, blkno);
+ if (ret)
+ return ret;
+
+ ret = ocfs2_bitmap_set(cinode->ci_chains, *blkno, &oldval);
+ if (ret)
+ return ret;
+ if (oldval)
+ return OCFS2_ET_INTERNAL_FAILURE;
+
+ return 0;
+}
+
+errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode,
+ uint64_t blkno)
+{
+ errcode_t ret;
+ int oldval;
+
+ if (!cinode->ci_chains)
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ ret = ocfs2_bitmap_clear(cinode->ci_chains, blkno, &oldval);
+ if (ret)
+ return ret;
+ if (!oldval)
+ return OCFS2_ET_FREEING_UNALLOCATED_REGION;
+
+ return 0;
+}
+
+
#ifdef DEBUG_EXE
#include <stdlib.h>
#include <getopt.h>
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2004-11-04 01:25:57 UTC (rev 363)
+++ trunk/libocfs2/include/ocfs2.h 2004-11-04 21:48:23 UTC (rev 364)
@@ -178,6 +178,13 @@
uint64_t fs_sysdir_blkno;
uint64_t fs_bm_blkno;
+ /* Allocators */
+ ocfs2_cached_inode *fs_cluster_alloc;
+ ocfs2_cached_inode *fs_inode_alloc;
+ ocfs2_cached_inode *fs_system_inode_alloc;
+ ocfs2_cached_inode *fs_eb_alloc;
+ ocfs2_cached_inode *fs_system_eb_alloc;
+
/* Reserved for the use of the calling application. */
void *fs_private;
};
@@ -412,6 +419,12 @@
ocfs2_cached_inode *cinode);
errcode_t ocfs2_write_chain_allocator(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode);
+errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode,
+ uint64_t *blkno);
+errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
+ ocfs2_cached_inode *cinode,
+ uint64_t blkno);
/*
* ${foo}_to_${bar} is a floor function. blocks_to_clusters will
Modified: trunk/libocfs2/ocfs2_err.et.in
===================================================================
--- trunk/libocfs2/ocfs2_err.et.in 2004-11-04 01:25:57 UTC (rev 363)
+++ trunk/libocfs2/ocfs2_err.et.in 2004-11-04 21:48:23 UTC (rev 364)
@@ -116,4 +116,7 @@
ec OCFS2_ET_BIT_NOT_FOUND,
"Unable to find available bit"
+ec OCFS2_ET_FREEING_UNALLOCATED_REGION,
+ "Attempting to free unallocated region"
+
end
More information about the Ocfs2-tools-commits
mailing list