SELinux relabel API
by Richard W.M. Jones
[
I realized that we were discussing adding this feature, in various
private email, IRC, and this long bugzilla thread:
https://bugzilla.redhat.com/show_bug.cgi?id=1060423
That's not how we should do things. Let's discuss it on the
mailing list.
]
One thing that virt-customize/virt-sysprep/virt-builder have to do is
relabel SELinux guests.
What we do at the moment is run:
if load_policy && fixfiles restore; then
rm -f /.autorelabel
else
touch /.autorelabel
echo '%s: SELinux relabelling failed, will relabel at boot instead.'
fi
while chrooted into the guest (using the 'guestfs_sh' API).
This has a number of problems:
- It has to load the policy using 'load_policy', but this doesn't
work sometimes:
* RHEL 5 load_policy takes a parameter.
* Doesn't work if appliance kernel is significantly different from
guest kernel version, because the binary policy format changes
irregularly and is not backwards compatible.
* Requires the appliance [host] kernel to be compiled with
LSM/SELinux support.
- Touching /.autorelabel is often broken, eg. it's broken in Fedora 20
because of systemd (RHBZ#1049656).
- /etc/resolv.conf will not be relabelled if guestfs network is on,
because of resolv.conf shenanigans in libguestfs.git/daemon/command.c
- It requires running guest code, which we'd like to avoid.
What would be nice would be to have an API to just do this
relabelling. Libguestfs could change this API as required to handle
different guests.
Dan Walsh helpfully pointed out to us that we've been doing it wrong
all along :-) A much better way to relabel is to run:
setfiles /etc/selinux/targeted/contexts/files/file_contexts DIR
where 'file_contexts' is a file which contains the default labels for
files (a set of regexps), and 'DIR' is the directory at which
relabelling starts. Note that 'setfiles' would be the libguestfs
appliance binary, so no guest binary needs to be run.
A simple API could just look like this:
guestfs_selinux_relabel (g);
which would always use the 'targeted' policy from the guest, and
always start relabelling at the root. This would work fine for
virt-builder.
For Colin's requirements for Project Atomic, I suspect he will want to
be able to set the file_contexts file and the root directory, but I'll
leave him to describe what would be useful.
A couple of notes:
- I'd like to avoid baking in assumptions from the 'setfiles' command
as far as possible. libguestfs APIs last for many years and some
have caused us many years of regret (but that's our job) :-/
- Is it a good idea to tie this into inspection in some way -- for
example, inspection could provide us with the path to the current or
default SELinux policy.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
8 years, 11 months
virt-resize: support to MBR logical partitions and some question
by Hu Tao
Hi,
I'm adding support to resizing logical partitions(patch is in progess).
But encounter an error when adding a logical partition in dest image:
virt-resize: libguestfs error: part_add: parted: /dev/sdb: Warning: The resulting partition is not properly aligned for best performance.
Error: Error informing the kernel about modifications to partition /dev/sdb5 -- Device or resource busy. This means Linux won't know about any changes you made to /dev/sdb5 until you reboot -- so you shouldn't mount it or use it in any way before rebooting.
Error: Failed to add partition 5 (Device or resource busy)
The error is actually no harm since the logical partition has been added
successfully, and I don't want to inform kernel at all. But it prevents
virt-resize from adding further logical partitions.
I can ignore the error when adding logical partitions manually using parted.
The question is, is there any way to ignore such errors in virt-resize?
Regards,
Hu Tao
10 years, 2 months
Re: [Libguestfs] hang after seabios
by Richard W.M. Jones
[Let's keep this on the mailing list]
On Thu, Jul 31, 2014 at 02:48:25PM -0700, Zetan Drableg wrote:
> Hi Richard,
> I created qemu-wrapper:
> #!/bin/bash -x
>
> exec gdbserver :1234 /usr/libexec/qemu-kvm "$@"
gdbserver will end up debugging the qemu process, not the guest
inside. This is not useful.
You need to do something like:
exec /usr/libexec/qemu-kvm -s -S "$@"
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
10 years, 3 months
Re: [Libguestfs] [PATCH 2/2] Use setfiles from the appliance for the SELinux relabel (RHBZ#1089100).
by Richard W.M. Jones
[Including libguestfs mailing list this time]
On Tue, May 27, 2014 at 06:05:15AM -0700, Colin Walters wrote:
> On Tue, May 27, 2014, at 02:04 AM, Richard W.M. Jones wrote:
> >
> > I'm still anxious for Colin to tell us if this API is suitable for his
> > needs.
>
> I'd like an API that allows me to only relabel *unlabeled* files.
> The use case here is: I have an existing disk image with an OS,
> I want to inject e.g. a systemd service into it. If I do this offline
> from libguestfs, the injected /usr/libexec/mydaemon and
> /usr/lib/systemd/system/mydaemon.service
> won't be labeled, but everything else will be.
>
> > I'm guessing that OStree does not have /etc/selinux/config,
>
> Right, it's in the "deployment root" of
> /ostree/deploy/$osname/deploy/$checksum/etc/selinux/config
Got it:
><fs> ll /ostree/deploy/project-atomic-controller/deploy/afc1794b4b42df77edf1988897b167573b99e299fa39a15b07b235a0e7387d02.0/etc/selinux/targeted/contexts/files/file_contexts
-rw-r--r--. 1 root root 352240 Apr 14 20:14 /sysroot/ostree/deploy/project-atomic-controller/deploy/afc1794b4b42df77edf1988897b167573b99e299fa39a15b07b235a0e7387d02.0/etc/selinux/targeted/contexts/files/file_contexts
> To figure that out you'd want to use the OSTree APIs; and then it
> introduces
> further questions around *which* deployments you want to relabel. All?
> Only
> one (the default?).
>
> What I do currently in my scripts is only relabel the default, and that
> would
> be the best default for an API.
>
> But a totally valid thing to do with OSTree is - say you're running
> RHEL7,
> and you want to check whether the latest Fedora kernel fixes an issue
> you're seeing. You can use ostree to dynamically parallel install
> Fedora content in a new deployment root, try it with near-total
> safety[1],
> and then if it doesn't work, just delete it and free up the space.
So I think an API which looks like this ...
required params:
None
optional params:
path =>
Either a directory to be relabelled recursively, or a single
file (defaults to "/").
root =>
Inspection root of guest. Optional, only makes sense when
'contexts' param is *omitted*.
contexts =>
The `file_contexts' file. Defaults to
/etc/selinux/$selinux_type/contexts/files/file_contexts
OSTree would probably want to pass:
/ostree/deploy/$osname/deploy/$checksum/etc/selinux/targeted/contexts/files/file_contexts
Inspection could be updated to parse /etc/selinux/config in order to
get the default SELinux policy and pass it back through an API such as
`inspect-get-selinux-type'.
If 'contexts' is omitted, 'root' must be supplied, and it causes an
internal call to guestfs_inspect_get_selinux_type (g, root) in order
to get the default policy.
What do you think?
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
10 years, 3 months
Re: [Libguestfs] hang after seabios
by Richard W.M. Jones
On Wed, Jul 30, 2014 at 03:58:43PM -0700, Zetan Drableg wrote:
> [00183ms] /usr/libexec/qemu-kvm \
> -global virtio-blk-pci.scsi=off \
> -nodefconfig \
> -nodefaults \
> -nographic \
> -machine accel=kvm:tcg \
> -cpu host,+kvmclock \
> -m 500 \
> -no-reboot \
> -kernel /var/tmp/.guestfs-0/kernel.47903 \
> -initrd /var/tmp/.guestfs-0/initrd.47903 \
> -device virtio-scsi-pci,id=scsi \
> -drive file=/tmp/libguestfs-test-tool-sda-Iakpwe,cache=none,format
> =raw,id=hd0,if=none \
> -device scsi-hd,drive=hd0 \
> -drive file=/var/tmp/.guestfs-0/root.47903,snapshot=on,id=appliance,
> if=none,cache=unsafe \
> -device scsi-hd,drive=appliance \
> -device virtio-serial \
> -serial stdio \
> -device sga \
> -chardev socket,path=/tmp/libguestfspx9994/guestfsd.sock,id=channel0
> \
> -device virtserialport,chardev=channel0,name=org.libguestfs.channel.0
> \
> -append 'panic=1 console=ttyS0 udevtimeout=600 no_timer_check
> acpi=off printk.time=1 cgroup_disable=memory root=/dev/sdb selinux=0
> guestfs_verbose=1 TERM=xterm edd=off'
> \x1b[1;256r\x1b[256;256H\x1b[6n
> Google, Inc.
> Serial Graphics Adapter 10/14/11
> SGABIOS $Id: sgabios.S 8 2010-04-22 00:03:40Z nlaredo $ (mockbuild@
> ca-build44.us.oracle.com) Fri Oct 14 20:04:36 UTC 2011
> Term: 80x24
> 4 0
> SeaBIOS (version seabios-0.6.1.2-28.el6)
> \x1b[2J
>
> At this point it hangs forever.
These hangs can be tricky to diagnose.
There are a couple of things you can do however:
(1) strace qemu to find out what it is doing, or:
(2) [harder, but much more informative] gdb into the guest to find out
where the guest hangs, or:
(3) Take the command line above, and cut it down to try to isolate the
problematic options. I would concentrate on the following options as
being most likely to cause trouble:
-cpu
-machine
-kernel
-device sga (remove it)
For (1) and (2) you can use a qemu wrapper to modify the qemu command
that the test tool runs.
See also:
http://libguestfs.org/guestfs.3.html#qemu-wrappers
http://rwmj.wordpress.com/2011/10/12/tip-debugging-the-early-boot-process...
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
10 years, 3 months
[PATCH 1/3] ext2: create a struct for the OCaml 't' type
by Pino Toscano
Use an helper struct for holding the ext2_filsys variable, so that can
be used to add more data.
---
src/ext2fs-c.c | 77 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 41 insertions(+), 36 deletions(-)
diff --git a/src/ext2fs-c.c b/src/ext2fs-c.c
index 70755c9..8eab24c 100644
--- a/src/ext2fs-c.c
+++ b/src/ext2fs-c.c
@@ -52,6 +52,11 @@
/* fts.h in glibc is broken, forcing us to use the GNUlib alternative. */
#include "fts_.h"
+struct ext2_data
+{
+ ext2_filsys fs;
+};
+
static void initialize (void) __attribute__((constructor));
static void
@@ -78,18 +83,18 @@ ext2_handle_closed (void)
caml_failwith ("ext2fs: function called on a closed handle");
}
-#define Ext2fs_val(v) (*((ext2_filsys *)Data_custom_val(v)))
+#define Ext2fs_val(v) (*((struct ext2_data *)Data_custom_val(v)))
static void
ext2_finalize (value fsv)
{
- ext2_filsys fs = Ext2fs_val (fsv);
+ struct ext2_data data = Ext2fs_val (fsv);
- if (fs) {
+ if (data.fs) {
#ifdef HAVE_EXT2FS_CLOSE2
- ext2fs_close2 (fs, EXT2_FLAG_FLUSH_NO_SYNC);
+ ext2fs_close2 (data.fs, EXT2_FLAG_FLUSH_NO_SYNC);
#else
- ext2fs_close (fs);
+ ext2fs_close (data.fs);
#endif
}
}
@@ -104,14 +109,14 @@ static struct custom_operations ext2_custom_operations = {
};
static value
-Val_ext2fs (ext2_filsys fs)
+Val_ext2fs (struct ext2_data *data)
{
CAMLparam0 ();
CAMLlocal1 (fsv);
fsv = caml_alloc_custom (&ext2_custom_operations,
- sizeof (ext2_filsys), 0, 1);
- Ext2fs_val (fsv) = fs;
+ sizeof (struct ext2_data), 0, 1);
+ Ext2fs_val (fsv) = *data;
CAMLreturn (fsv);
}
@@ -122,18 +127,18 @@ supermin_ext2fs_open (value filev)
CAMLlocal1 (fsv);
int fs_flags = EXT2_FLAG_RW;
errcode_t err;
- ext2_filsys fs;
+ struct ext2_data data;
#ifdef EXT2_FLAG_64BITS
fs_flags |= EXT2_FLAG_64BITS;
#endif
err = ext2fs_open (String_val (filev), fs_flags, 0, 0,
- unix_io_manager, &fs);
+ unix_io_manager, &data.fs);
if (err != 0)
ext2_error_to_exception ("ext2fs_open", err, String_val (filev));
- fsv = Val_ext2fs (fs);
+ fsv = Val_ext2fs (&data);
CAMLreturn (fsv);
}
@@ -145,7 +150,7 @@ supermin_ext2fs_close (value fsv)
ext2_finalize (fsv);
/* So we don't double-free in the finalizer. */
- Ext2fs_val (fsv) = NULL;
+ Ext2fs_val (fsv).fs = NULL;
CAMLreturn (Val_unit);
}
@@ -154,14 +159,14 @@ value
supermin_ext2fs_read_bitmaps (value fsv)
{
CAMLparam1 (fsv);
- ext2_filsys fs;
+ struct ext2_data data;
errcode_t err;
- fs = Ext2fs_val (fsv);
- if (fs == NULL)
+ data = Ext2fs_val (fsv);
+ if (data.fs == NULL)
ext2_handle_closed ();
- err = ext2fs_read_bitmaps (fs);
+ err = ext2fs_read_bitmaps (data.fs);
if (err != 0)
ext2_error_to_exception ("ext2fs_read_bitmaps", err, NULL);
@@ -173,7 +178,7 @@ static void ext2_empty_inode (ext2_filsys fs, ext2_ino_t dir_ino, const char *di
static void ext2_write_file (ext2_filsys fs, ext2_ino_t ino, const char *buf, size_t size, const char *filename);
static void ext2_link (ext2_filsys fs, ext2_ino_t dir_ino, const char *basename, ext2_ino_t ino, int dir_ft);
static void ext2_clean_path (ext2_filsys fs, ext2_ino_t dir_ino, const char *dirname, const char *basename, int isdir);
-static void ext2_copy_file (ext2_filsys fs, const char *src, const char *dest);
+static void ext2_copy_file (struct ext2_data *data, const char *src, const char *dest);
/* Copy the host filesystem file/directory 'src' to the destination
* 'dest'. Directories are NOT copied recursively - the directory is
@@ -185,13 +190,13 @@ supermin_ext2fs_copy_file_from_host (value fsv, value srcv, value destv)
CAMLparam3 (fsv, srcv, destv);
const char *src = String_val (srcv);
const char *dest = String_val (destv);
- ext2_filsys fs;
+ struct ext2_data data;
- fs = Ext2fs_val (fsv);
- if (fs == NULL)
+ data = Ext2fs_val (fsv);
+ if (data.fs == NULL)
ext2_handle_closed ();
- ext2_copy_file (fs, src, dest);
+ ext2_copy_file (&data, src, dest);
CAMLreturn (Val_unit);
}
@@ -207,7 +212,7 @@ supermin_ext2fs_copy_dir_recursively_from_host (value fsv,
const char *srcdir = String_val (srcdirv);
const char *destdir = String_val (destdirv);
size_t srclen = strlen (srcdir);
- ext2_filsys fs;
+ struct ext2_data data;
char *paths[2];
FTS *fts;
FTSENT *entry;
@@ -216,8 +221,8 @@ supermin_ext2fs_copy_dir_recursively_from_host (value fsv,
size_t i, n;
int r;
- fs = Ext2fs_val (fsv);
- if (fs == NULL)
+ data = Ext2fs_val (fsv);
+ if (data.fs == NULL)
ext2_handle_closed ();
paths[0] = (char *) srcdir;
@@ -269,7 +274,7 @@ supermin_ext2fs_copy_dir_recursively_from_host (value fsv,
}
}
- ext2_copy_file (fs, entry->fts_path, destpath);
+ ext2_copy_file (&data, entry->fts_path, destpath);
free (destpath);
}
@@ -538,7 +543,7 @@ read_whole_file (const char *filename, size_t size)
/* Copy a file (or directory etc) from the host. */
static void
-ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
+ext2_copy_file (struct ext2_data *data, const char *src, const char *dest)
{
errcode_t err;
struct stat statbuf;
@@ -551,13 +556,13 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
* Note we cheat by looking at fs->device_name (which is the output
* file). We could store this filename separately.
*/
- if (fs->device_name && statvfs (fs->device_name, &statvfsbuf) == 0) {
+ if (data->fs->device_name && statvfs (data->fs->device_name, &statvfsbuf) == 0) {
uint64_t space = statvfsbuf.f_bavail * statvfsbuf.f_bsize;
uint64_t estimate = 128*1024 + 2 * statbuf.st_size;
if (space < estimate)
unix_error (ENOSPC, (char *) "statvfs",
- caml_copy_string (fs->device_name));
+ caml_copy_string (data->fs->device_name));
}
#if 0
@@ -638,7 +643,7 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
cont:
/* Look up the parent directory. */
- err = ext2fs_namei (fs, EXT2_ROOT_INO, EXT2_ROOT_INO, dirname, &dir_ino);
+ err = ext2fs_namei (data->fs, EXT2_ROOT_INO, EXT2_ROOT_INO, dirname, &dir_ino);
if (err != 0) {
/* This is the most popular supermin "WTF" error, so make
* sure we capture as much information as possible.
@@ -654,7 +659,7 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
}
}
- ext2_clean_path (fs, dir_ino, dirname, basename, S_ISDIR (statbuf.st_mode));
+ ext2_clean_path (data->fs, dir_ino, dirname, basename, S_ISDIR (statbuf.st_mode));
int dir_ft;
@@ -670,13 +675,13 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
goto skip_unreadable_file;
}
- ext2_empty_inode (fs, dir_ino, dirname, basename,
+ ext2_empty_inode (data->fs, dir_ino, dirname, basename,
statbuf.st_mode, statbuf.st_uid, statbuf.st_gid,
statbuf.st_ctime, statbuf.st_atime, statbuf.st_mtime,
0, 0, EXT2_FT_REG_FILE, &ino);
if (statbuf.st_size > 0) {
- ext2_write_file (fs, ino, buf, statbuf.st_size, dest);
+ ext2_write_file (data->fs, ino, buf, statbuf.st_size, dest);
free (buf);
}
skip_unreadable_file: ;
@@ -684,7 +689,7 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
/* Create a symlink. */
else if (S_ISLNK (statbuf.st_mode)) {
ext2_ino_t ino;
- ext2_empty_inode (fs, dir_ino, dirname, basename,
+ ext2_empty_inode (data->fs, dir_ino, dirname, basename,
statbuf.st_mode, statbuf.st_uid, statbuf.st_gid,
statbuf.st_ctime, statbuf.st_atime, statbuf.st_mtime,
0, 0, EXT2_FT_SYMLINK, &ino);
@@ -693,11 +698,11 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
ssize_t r = readlink (src, buf, sizeof buf);
if (r == -1)
unix_error (errno, (char *) "readlink", caml_copy_string (src));
- ext2_write_file (fs, ino, buf, r, dest);
+ ext2_write_file (data->fs, ino, buf, r, dest);
}
/* Create directory. */
else if (S_ISDIR (statbuf.st_mode))
- ext2_mkdir (fs, dir_ino, dirname, basename,
+ ext2_mkdir (data->fs, dir_ino, dirname, basename,
statbuf.st_mode, statbuf.st_uid, statbuf.st_gid,
statbuf.st_ctime, statbuf.st_atime, statbuf.st_mtime);
/* Create a special file. */
@@ -714,7 +719,7 @@ ext2_copy_file (ext2_filsys fs, const char *src, const char *dest)
} else if (S_ISSOCK (statbuf.st_mode)) {
dir_ft = EXT2_FT_SOCK;
make_special:
- ext2_empty_inode (fs, dir_ino, dirname, basename,
+ ext2_empty_inode (data->fs, dir_ino, dirname, basename,
statbuf.st_mode, statbuf.st_uid, statbuf.st_gid,
statbuf.st_ctime, statbuf.st_atime, statbuf.st_mtime,
major (statbuf.st_rdev), minor (statbuf.st_rdev),
--
1.9.3
10 years, 3 months
[PATCH 3/3] ext2: print every file being copied
by Pino Toscano
Print every file copied by supermin, so it is easier to spot whether
some file causes troubles to supermin (e.g. what happens in
RHBZ#1099172).
Since the resulting output is huge, make it valid for debug level 3.
---
src/ext2fs-c.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/ext2fs-c.c b/src/ext2fs-c.c
index c9d3994..9e0770a 100644
--- a/src/ext2fs-c.c
+++ b/src/ext2fs-c.c
@@ -554,6 +554,9 @@ ext2_copy_file (struct ext2_data *data, const char *src, const char *dest)
struct stat statbuf;
struct statvfs statvfsbuf;
+ if (data->debug >= 3)
+ printf ("supermin: ext2: copy_file %s -> %s\n", src, dest);
+
if (lstat (src, &statbuf) == -1)
unix_error (errno, (char *) "lstat", caml_copy_string (src));
@@ -570,11 +573,6 @@ ext2_copy_file (struct ext2_data *data, const char *src, const char *dest)
caml_copy_string (data->fs->device_name));
}
-#if 0
- /* if debug >= 3 */
- fprintf (stderr, "ext2_copy_file %s %s 0%o\n", src, dest, statbuf.st_mode);
-#endif
-
/* Sanity check the path. These rules are always true for the paths
* passed to us here from the appliance layer. The assertions just
* verify that the rules haven't changed.
--
1.9.3
10 years, 3 months
[PATCH 2/3] ext2: store the debug level
by Pino Toscano
---
src/ext2.ml | 2 +-
src/ext2fs-c.c | 7 ++++++-
src/ext2fs.ml | 2 +-
src/ext2fs.mli | 2 +-
4 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/ext2.ml b/src/ext2.ml
index bccf3a7..d5c26a7 100644
--- a/src/ext2.ml
+++ b/src/ext2.ml
@@ -52,7 +52,7 @@ let build_ext2 debug basedir files modpath kernel_version appliance =
(quote appliance) in
run_command cmd;
- let fs = ext2fs_open appliance in
+ let fs = ext2fs_open ~debug appliance in
ext2fs_read_bitmaps fs;
if debug >= 1 then
diff --git a/src/ext2fs-c.c b/src/ext2fs-c.c
index 8eab24c..c9d3994 100644
--- a/src/ext2fs-c.c
+++ b/src/ext2fs-c.c
@@ -55,6 +55,7 @@
struct ext2_data
{
ext2_filsys fs;
+ int debug;
};
static void initialize (void) __attribute__((constructor));
@@ -84,6 +85,8 @@ ext2_handle_closed (void)
}
#define Ext2fs_val(v) (*((struct ext2_data *)Data_custom_val(v)))
+#define Val_none Val_int(0)
+#define Some_val(v) Field(v,0)
static void
ext2_finalize (value fsv)
@@ -121,7 +124,7 @@ Val_ext2fs (struct ext2_data *data)
}
value
-supermin_ext2fs_open (value filev)
+supermin_ext2fs_open (value filev, value debugv)
{
CAMLparam1 (filev);
CAMLlocal1 (fsv);
@@ -138,6 +141,8 @@ supermin_ext2fs_open (value filev)
if (err != 0)
ext2_error_to_exception ("ext2fs_open", err, String_val (filev));
+ data.debug = debugv == Val_none ? 0 : Int_val (Some_val (debugv));
+
fsv = Val_ext2fs (&data);
CAMLreturn (fsv);
}
diff --git a/src/ext2fs.ml b/src/ext2fs.ml
index cf7c546..9f3580e 100644
--- a/src/ext2fs.ml
+++ b/src/ext2fs.ml
@@ -18,7 +18,7 @@
type t
-external ext2fs_open : string -> t = "supermin_ext2fs_open"
+external ext2fs_open : string -> ?debug:int -> t = "supermin_ext2fs_open"
external ext2fs_close : t -> unit = "supermin_ext2fs_close"
external ext2fs_read_bitmaps : t -> unit = "supermin_ext2fs_read_bitmaps"
diff --git a/src/ext2fs.mli b/src/ext2fs.mli
index ebcaf1b..2a59b2d 100644
--- a/src/ext2fs.mli
+++ b/src/ext2fs.mli
@@ -25,7 +25,7 @@
type t
-val ext2fs_open : string -> t
+val ext2fs_open : string -> ?debug:int -> t
val ext2fs_close : t -> unit
val ext2fs_read_bitmaps : t -> unit
--
1.9.3
10 years, 3 months
[PATCH 0/2] supermin: improve handling of memory
by Pino Toscano
Hi,
the two patches improve the way memory is handled in supermin, by
cleanly exiting on memory allocation failures, and free'ing memory when
not needed (to keep working and not run out of memory).
Pino Toscano (2):
Check for failures in memory allocations
Free memory buffers when not used
src/ext2fs-c.c | 13 +++++++++++--
src/init.c | 13 +++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
--
1.9.3
10 years, 3 months