From d7539fef2d8b161d89f9754252daf0ef4115febf Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 8 Sep 2012 11:19:45 -0700 Subject: [PATCH] FreeBSD support, better detection of usable iSCSI size --- iscsi-server/atboot.cgi | 2 ++ iscsi-server/config-freebsd | 4 +++ iscsi-server/index.cgi | 2 +- iscsi-server/iscsi-server-lib.pl | 45 +++++++++++++++++++++++++------- iscsi-server/module.info | 2 +- 5 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 iscsi-server/config-freebsd diff --git a/iscsi-server/atboot.cgi b/iscsi-server/atboot.cgi index a4117481a..6f24627d9 100644 --- a/iscsi-server/atboot.cgi +++ b/iscsi-server/atboot.cgi @@ -16,6 +16,8 @@ if ($old != 2 && $in{'boot'}) { "Start or stop the iSCSI server", "$config{'iscsi_server'} -f $config{'targets_file'}", "kill `cat $config{'pid_file'}`", + undef, + { 'fork' => 1 }, ); &webmin_log("atboot"); } diff --git a/iscsi-server/config-freebsd b/iscsi-server/config-freebsd new file mode 100644 index 000000000..144a8ef03 --- /dev/null +++ b/iscsi-server/config-freebsd @@ -0,0 +1,4 @@ +targets_file=/usr/local/etc/iscsi/targets +iscsi_server=/usr/local/bin/iscsi-target +pid_file=/var/run/iscsi-target.pid +init_name=iscsi_target diff --git a/iscsi-server/index.cgi b/iscsi-server/index.cgi index 582c17da2..41f2f558c 100644 --- a/iscsi-server/index.cgi +++ b/iscsi-server/index.cgi @@ -6,7 +6,7 @@ use warnings; require './iscsi-server-lib.pl'; our (%text, %config, $module_name); -&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1); +&ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1); my $err = &check_config(); if ($err) { diff --git a/iscsi-server/iscsi-server-lib.pl b/iscsi-server/iscsi-server-lib.pl index 1af886123..40d594881 100644 --- a/iscsi-server/iscsi-server-lib.pl +++ b/iscsi-server/iscsi-server-lib.pl @@ -114,9 +114,32 @@ elsif ($o && !$n) { } } elsif (!$o && $n) { - # Add a line - $n->{'line'} = scalar(@$lref); - push(@$lref, $line); + # Add a line. Extents should come before any devices, and devices + # before any targets + my @allsame = &find($conf, $n->{'type'}); + my $lastsame = @allsame ? pop(@allsame) : undef; + my $addline = scalar(@$lref); + if ($lastsame) { + # Add after last of the same type + $addline = $lastsame->{'line'}+1; + } + elsif ($n->{'type'} eq 'device') { + # Add before any targets + my $firsttarget = &find($conf, "target"); + $addline = $firsttarget->{'line'} if ($addline); + } + elsif ($n->{'type'} eq 'extent') { + # Add before any devices + my $firstdevice = &find($conf, "device"); + $addline = $firstdevice->{'line'} if ($addline); + } + $n->{'line'} = $addline; + splice(@$lref, $addline, 0, $line); + foreach my $c (@$conf) { + if ($c->{'line'} >= $addline) { + $c->{'line'}++; + } + } push(@$conf, $n); } &flush_file_lines($config{'targets_file'}); @@ -154,10 +177,10 @@ sub parse_bytes { my ($str) = @_; if ($str =~ /^(\d+)TB/i) { - return $1 * 1024 * 1204 * 1024 * 1024; + return $1 * 1024 * 1024 * 1024 * 1024; } elsif ($str =~ /^(\d+)GB/i) { - return $1 * 1204 * 1024 * 1024; + return $1 * 1024 * 1024 * 1024; } elsif ($str =~ /^(\d+)MB/i) { return $1 * 1024 * 1024; @@ -178,7 +201,10 @@ else { sub convert_bytes { my ($n) = @_; -if ($n % (1024*1024*1024*1024) == 0) { +if ($n == 0) { + return $n; + } +elsif ($n % (1024*1024*1024*1024) == 0) { return ($n / (1024*1024*1024*1024))."TB"; } elsif ($n % (1024*1024*1024) == 0) { @@ -268,17 +294,18 @@ elsif ($type eq "raid") { my $conf = &raid::get_raidtab(); foreach my $c (@$conf) { if ($c->{'value'} eq $dev) { - return $c->{'size'}*1024; + return $c->{'size'} * 1024; } } return undef; } elsif ($type eq "lvm") { - # LVM volume group + # LVM volume group. Leave 1 MB free, as it seems to be needed for + # some kind of overhead? foreach my $v (&lvm::list_volume_groups()) { foreach my $l (&lvm::list_logical_volumes($v->{'name'})) { if ($l->{'device'} eq $dev) { - return $l->{'size'} * 1024; + return ($l->{'size'} * 1024) - (1024 * 1024); } } } diff --git a/iscsi-server/module.info b/iscsi-server/module.info index 4c1d2e4b1..87d251e1f 100644 --- a/iscsi-server/module.info +++ b/iscsi-server/module.info @@ -1,5 +1,5 @@ desc=iSCSI Server category=hardware -os_support=*-linux +os_support=*-linux freebsd depends=fdisk lvm raid init longdesc=Share disk devices across the network using the iSCSI protocol.