[Ocfs2-tools-commits] jlbec commits r478 - in trunk/libocfs2: .
include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Dec 10 20:10:12 CST 2004
Author: jlbec
Date: 2004-12-10 20:10:10 -0600 (Fri, 10 Dec 2004)
New Revision: 478
Modified:
trunk/libocfs2/alloc.c
trunk/libocfs2/chain.c
trunk/libocfs2/extend_file.c
trunk/libocfs2/include/ocfs2.h
Log:
o Make ocfs2_extend_allocation() try to clean up upon error.
o Put a debug chunk in extend_file.c to extend inodes.
Modified: trunk/libocfs2/alloc.c
===================================================================
--- trunk/libocfs2/alloc.c 2004-12-10 22:38:04 UTC (rev 477)
+++ trunk/libocfs2/alloc.c 2004-12-11 02:10:10 UTC (rev 478)
@@ -389,7 +389,7 @@
}
errcode_t ocfs2_free_clusters(ocfs2_filesys *fs,
- uint64_t len,
+ uint32_t len,
uint64_t start_blkno)
{
errcode_t ret;
Modified: trunk/libocfs2/chain.c
===================================================================
--- trunk/libocfs2/chain.c 2004-12-10 22:38:04 UTC (rev 477)
+++ trunk/libocfs2/chain.c 2004-12-11 02:10:10 UTC (rev 478)
@@ -26,7 +26,6 @@
#define _LARGEFILE64_SOURCE
#include <string.h>
-#include <inttypes.h>
#include "ocfs2.h"
@@ -234,6 +233,7 @@
#ifdef DEBUG_EXE
#include <stdlib.h>
#include <getopt.h>
+#include <inttypes.h>
static uint64_t read_number(const char *num)
{
Modified: trunk/libocfs2/extend_file.c
===================================================================
--- trunk/libocfs2/extend_file.c 2004-12-10 22:38:04 UTC (rev 477)
+++ trunk/libocfs2/extend_file.c 2004-12-11 02:10:10 UTC (rev 478)
@@ -346,31 +346,142 @@
}
errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
- uint64_t new_clusters)
+ uint32_t new_clusters)
{
errcode_t ret = 0;
- uint64_t n_clusters = 0;
+ uint32_t n_clusters = 0;
uint64_t blkno;
if (!(fs->fs_flags & OCFS2_FLAG_RW))
return OCFS2_ET_RO_FILESYS;
while (new_clusters) {
- /* XXX lalala, for now we can only allocate precicely as
- * much as we ask for and we leak allocations. leaking
- * allocations half-way through is a strong theme. */
n_clusters = 1;
ret = ocfs2_new_clusters(fs, n_clusters, &blkno);
if (ret)
- goto bail;
+ break;
ret = ocfs2_insert_extent(fs, ino, blkno, n_clusters);
- if (ret)
- goto bail;
+ if (ret) {
+ /* XXX: We don't wan't to overwrite the error
+ * from insert_extent(). But we probably need
+ * to BE LOUDLY UPSET. */
+ ocfs2_free_clusters(fs, n_clusters, blkno);
+ break;
+ }
new_clusters -= n_clusters;
}
-bail:
return ret;
}
+
+#ifdef DEBUG_EXE
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <inttypes.h>
+
+static void print_usage(void)
+{
+ fprintf(stdout, "debug_extend_file -i <ino> -c <clusters> <device>\n");
+}
+
+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;
+}
+
+extern int opterr, optind;
+extern char *optarg;
+
+int main(int argc, char *argv[])
+{
+ errcode_t ret;
+ char *filename;
+ ocfs2_filesys *fs;
+ uint64_t ino = 0;
+ uint32_t new_clusters = 0;
+ int c;
+
+ initialize_ocfs_error_table();
+
+ while ((c = getopt(argc, argv, "i:c:")) != EOF) {
+ switch (c) {
+ case 'i':
+ ino = read_number(optarg);
+ if (ino <= OCFS2_SUPER_BLOCK_BLKNO) {
+ fprintf(stderr,
+ "Invalid inode block: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ case 'c':
+ new_clusters = read_number(optarg);
+ if (!new_clusters) {
+ fprintf(stderr,
+ "Invalid cluster count: %s\n",
+ optarg);
+ print_usage();
+ return 1;
+ }
+ break;
+
+ default:
+ print_usage();
+ return 1;
+ break;
+ }
+ }
+
+ if (!ino) {
+ fprintf(stderr, "You must specify an inode block\n");
+ print_usage();
+ return 1;
+ }
+
+ if (!new_clusters) {
+ fprintf(stderr, "You must specify how many clusters to extend\n");
+ print_usage();
+ return 1;
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Missing filename\n");
+ print_usage();
+ return 1;
+ }
+ filename = argv[optind];
+
+ ret = ocfs2_open(filename, OCFS2_FLAG_RW, 0, 0, &fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while opening file \"%s\"", filename);
+ goto out;
+ }
+
+ ret = ocfs2_extend_allocation(fs, ino, new_clusters);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while extending inode %"PRIu64, ino);
+ }
+
+ ret = ocfs2_close(fs);
+ if (ret) {
+ com_err(argv[0], ret,
+ "while closing file \"%s\"", filename);
+ }
+out:
+ return !!ret;
+}
+#endif /* DEBUG_EXE */
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2004-12-10 22:38:04 UTC (rev 477)
+++ trunk/libocfs2/include/ocfs2.h 2004-12-11 02:10:10 UTC (rev 478)
@@ -505,12 +505,12 @@
errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno);
errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
- uint64_t new_clusters);
+ uint32_t new_clusters);
errcode_t ocfs2_new_clusters(ocfs2_filesys *fs,
uint32_t requested,
uint64_t *start_blkno);
errcode_t ocfs2_free_clusters(ocfs2_filesys *fs,
- uint64_t len,
+ uint32_t len,
uint64_t start_blkno);
/*
More information about the Ocfs2-tools-commits
mailing list