[Ocfs2-tools-commits] jlbec commits r417 - in trunk/libocfs2: .
include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Nov 18 18:06:33 CST 2004
Author: jlbec
Date: 2004-11-18 18:06:31 -0600 (Thu, 18 Nov 2004)
New Revision: 417
Modified:
trunk/libocfs2/alloc.c
trunk/libocfs2/chainalloc.c
trunk/libocfs2/include/ocfs2.h
trunk/libocfs2/link.c
Log:
o new_inode and delete_inode should workie
Modified: trunk/libocfs2/alloc.c
===================================================================
--- trunk/libocfs2/alloc.c 2004-11-18 23:20:16 UTC (rev 416)
+++ trunk/libocfs2/alloc.c 2004-11-19 00:06:31 UTC (rev 417)
@@ -33,7 +33,8 @@
static errcode_t ocfs2_chain_alloc_with_io(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t *blkno)
+ uint64_t *gd_blkno,
+ uint64_t *bitno)
{
errcode_t ret;
@@ -43,7 +44,7 @@
return ret;
}
- ret = ocfs2_chain_alloc(fs, cinode, blkno);
+ ret = ocfs2_chain_alloc(fs, cinode, gd_blkno, bitno);
if (ret)
return ret;
@@ -52,7 +53,7 @@
static errcode_t ocfs2_chain_free_with_io(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t blkno)
+ uint64_t bitno)
{
errcode_t ret;
@@ -62,7 +63,7 @@
return ret;
}
- ret = ocfs2_chain_free(fs, cinode, blkno);
+ ret = ocfs2_chain_free(fs, cinode, bitno);
if (ret)
return ret;
@@ -86,46 +87,146 @@
return ret;
}
+ if (!(*alloc_cinode)->ci_chains) {
+ ret = ocfs2_load_chain_allocator(fs, *alloc_cinode);
+ if (ret)
+ return ret;
+ }
+
return 0;
}
-errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *blkno)
+static void ocfs2_init_inode(ocfs2_filesys *fs, ocfs2_dinode *di,
+ uint64_t gd_blkno, 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 = (uint16_t)(blkno - gd_blkno);
+ 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);
+}
+
+errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode)
+{
errcode_t ret;
+ char *buf;
+ uint64_t gd_blkno;
+ ocfs2_dinode *di;
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ return ret;
+
ret = ocfs2_load_allocator(fs, INODE_ALLOC_SYSTEM_INODE,
0, &fs->fs_inode_allocs[0]);
if (ret)
- return ret;
+ goto out;
- return ocfs2_chain_alloc_with_io(fs, fs->fs_inode_allocs[0], blkno);
+ ret = ocfs2_chain_alloc_with_io(fs, fs->fs_inode_allocs[0],
+ &gd_blkno, ino);
+ if (ret)
+ goto out;
+
+ memset(buf, 0, fs->fs_blocksize);
+ di = (ocfs2_dinode *)buf;
+ di->i_mode = mode;
+ ocfs2_init_inode(fs, di, gd_blkno, *ino);
+
+ ret = ocfs2_write_inode(fs, *ino, buf);
+
+out:
+ ocfs2_free(&buf);
+
+ return ret;
}
-errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *blkno)
+errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino,
+ int mode)
{
errcode_t ret;
+ char *buf;
+ uint64_t gd_blkno;
+ ocfs2_dinode *di;
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ return ret;
+
ret = ocfs2_load_allocator(fs, GLOBAL_INODE_ALLOC_SYSTEM_INODE,
0, &fs->fs_system_inode_alloc);
if (ret)
- return ret;
+ goto out;
- return ocfs2_chain_alloc_with_io(fs, fs->fs_system_inode_alloc,
- blkno);
+ ret = ocfs2_chain_alloc_with_io(fs, fs->fs_system_inode_alloc,
+ &gd_blkno, ino);
+ if (ret)
+ goto out;
+
+ memset(buf, 0, fs->fs_blocksize);
+ di = (ocfs2_dinode *)buf;
+ di->i_mode = mode;
+ ocfs2_init_inode(fs, di, gd_blkno, *ino);
+ di->i_flags |= OCFS2_SYSTEM_FL;
+ di->i_generation = fs->fs_super->i_generation;
+
+ ret = ocfs2_write_inode(fs, *ino, buf);
+
+out:
+ ocfs2_free(&buf);
+
+ return ret;
}
-errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t blkno)
+errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino)
{
errcode_t ret;
+ char *buf;
+ ocfs2_dinode *di;
+ int node;
- /* XXX needs to delete from the allocator that has the inode */
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ return ret;
+ ret = ocfs2_read_inode(fs, ino, buf);
+ if (ret)
+ goto out;
+ di = (ocfs2_dinode *)buf;
+ node = di->i_suballoc_node;
+
ret = ocfs2_load_allocator(fs, INODE_ALLOC_SYSTEM_INODE,
- 0, &fs->fs_inode_allocs[0]);
+ node,
+ &fs->fs_inode_allocs[node]);
if (ret)
- return ret;
+ goto out;
- return ocfs2_chain_free_with_io(fs, fs->fs_inode_allocs[0], blkno);
+ ret = ocfs2_chain_free_with_io(fs, fs->fs_inode_allocs[node],
+ ino);
+ if (ret)
+ goto out;
+
+ di->i_flags &= ~OCFS2_VALID_FL;
+ ret = ocfs2_write_inode(fs, di->i_blkno, buf);
+
+out:
+ ocfs2_free(&buf);
+
+ return ret;
}
errcode_t ocfs2_test_inode_allocated(ocfs2_filesys *fs, uint64_t blkno,
@@ -149,15 +250,6 @@
if (ret)
break;
- /* XXX I don't understand why this isn't in
- * ocfs2_load_allocator.. the _with_io guys in this file about
- * chain_allocator */
- if ((*ci)->ci_chains == NULL) {
- ret = ocfs2_load_chain_allocator(fs, *ci);
- if (ret)
- break;
- }
-
ret = ocfs2_chain_test(fs, *ci, blkno, is_allocated);
if (ret != OCFS2_ET_INVALID_BIT)
break;
@@ -165,31 +257,6 @@
return ret;
}
-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>
@@ -229,22 +296,13 @@
di = (ocfs2_dinode *)buf;
- ret = ocfs2_new_inode(fs, &blkno);
+ ret = ocfs2_new_inode(fs, &blkno, 0644 | S_IFREG);
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) {
Modified: trunk/libocfs2/chainalloc.c
===================================================================
--- trunk/libocfs2/chainalloc.c 2004-11-18 23:20:16 UTC (rev 416)
+++ trunk/libocfs2/chainalloc.c 2004-11-19 00:06:31 UTC (rev 417)
@@ -335,23 +335,50 @@
return ocfs2_bitmap_write(cinode->ci_chains);
}
+struct find_desc_ctxt {
+ uint64_t target_bit;
+ uint64_t gd_blkno;
+};
+
+static errcode_t chainalloc_find_desc(struct ocfs2_bitmap_region *br,
+ void *private_data)
+{
+ struct chainalloc_region_private *cr = br->br_private;
+ struct find_desc_ctxt *ctxt = private_data;
+
+ if (ctxt->target_bit < br->br_start_bit)
+ return 0;
+ if (ctxt->target_bit >= (br->br_start_bit + br->br_total_bits))
+ return 0;
+
+ ctxt->gd_blkno = cr->cr_ag->bg_blkno;
+ return 0;
+}
+
/* 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)
+ uint64_t *gd_blkno,
+ uint64_t *bitno)
{
errcode_t ret;
int oldval;
+ struct find_desc_ctxt ctxt;
if (!cinode->ci_chains)
return OCFS2_ET_INVALID_ARGUMENT;
- ret = ocfs2_bitmap_find_next_clear(cinode->ci_chains, 0, blkno);
+ ret = ocfs2_bitmap_find_next_clear(cinode->ci_chains, 0, bitno);
if (ret)
return ret;
- ret = ocfs2_bitmap_set(cinode->ci_chains, *blkno, &oldval);
+ ctxt.gd_blkno = 0;
+ ctxt.target_bit = *bitno;
+ ret = ocfs2_bitmap_foreach_region(cinode->ci_chains,
+ chainalloc_find_desc, &ctxt);
+
+ ret = ocfs2_bitmap_set(cinode->ci_chains, *bitno, &oldval);
if (ret)
return ret;
if (oldval)
@@ -362,7 +389,7 @@
errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t blkno)
+ uint64_t bitno)
{
errcode_t ret;
int oldval;
@@ -370,7 +397,7 @@
if (!cinode->ci_chains)
return OCFS2_ET_INVALID_ARGUMENT;
- ret = ocfs2_bitmap_clear(cinode->ci_chains, blkno, &oldval);
+ ret = ocfs2_bitmap_clear(cinode->ci_chains, bitno, &oldval);
if (ret)
return ret;
if (!oldval)
@@ -383,7 +410,7 @@
* was already set */
errcode_t ocfs2_chain_force_val(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t blkno,
+ uint64_t bitno,
int newval,
int *oldval)
{
@@ -393,22 +420,22 @@
return OCFS2_ET_INVALID_ARGUMENT;
if (newval)
- ret = ocfs2_bitmap_set(cinode->ci_chains, blkno, oldval);
+ ret = ocfs2_bitmap_set(cinode->ci_chains, bitno, oldval);
else
- ret = ocfs2_bitmap_clear(cinode->ci_chains, blkno, oldval);
+ ret = ocfs2_bitmap_clear(cinode->ci_chains, bitno, oldval);
return ret;
}
errcode_t ocfs2_chain_test(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t blkno,
+ uint64_t bitno,
int *oldval)
{
if (!cinode->ci_chains)
return OCFS2_ET_INVALID_ARGUMENT;
- return ocfs2_bitmap_test(cinode->ci_chains, blkno, oldval);
+ return ocfs2_bitmap_test(cinode->ci_chains, bitno, oldval);
}
void ocfs2_init_group_desc(ocfs2_filesys *fs, ocfs2_group_desc *gd,
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2004-11-18 23:20:16 UTC (rev 416)
+++ trunk/libocfs2/include/ocfs2.h 2004-11-19 00:06:31 UTC (rev 417)
@@ -427,13 +427,14 @@
ocfs2_cached_inode *cinode);
errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t *blkno);
+ uint64_t *gd_blkno,
+ uint64_t *bitno);
errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t blkno);
+ uint64_t bitno);
errcode_t ocfs2_chain_test(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
- uint64_t blkno,
+ uint64_t bitno,
int *oldval);
errcode_t ocfs2_chain_force_val(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode,
@@ -458,6 +459,11 @@
errcode_t ocfs2_extent_allocation(ocfs2_filesys *fs, uint64_t ino,
uint32_t new_clusters);
+errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode);
+errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino, int mode);
+errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino);
+
+
/*
* ${foo}_to_${bar} is a floor function. blocks_to_clusters will
* returns the cluster that contains a block, not the number of clusters
Modified: trunk/libocfs2/link.c
===================================================================
--- trunk/libocfs2/link.c 2004-11-18 23:20:16 UTC (rev 416)
+++ trunk/libocfs2/link.c 2004-11-19 00:06:31 UTC (rev 417)
@@ -95,7 +95,7 @@
dirent->inode = ls->inode;
dirent->name_len = ls->namelen;
strncpy(dirent->name, ls->name, ls->namelen);
- ocfs_set_de_type(dirent, ls->flags);
+ dirent->file_type = ls->flags;
ls->done++;
return OCFS2_DIRENT_ABORT|OCFS2_DIRENT_CHANGED;
More information about the Ocfs2-tools-commits
mailing list