[PATCH] Do not ignore the block size of the dfree command - brc #11403

Andreas Schneider asn at samba.org
Fri Jul 17 09:45:15 UTC 2015


On Friday 17 July 2015 09:54:38 Andreas Schneider wrote:
> Hi,
> 
> attached find a patch to fix
> https://bugzilla.samba.org/show_bug.cgi?id=11403

New version with a simple test for the dfree command.


-- 
Andreas Schneider                   GPG-ID: CC014E3D
Samba Team                             asn at samba.org
www.samba.org
-------------- next part --------------
>From ecf052f776f628859bc88b8019cd170a3f5a9236 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Fri, 17 Jul 2015 09:35:11 +0200
Subject: [PATCH 1/3] s3-smbd: Leave sys_disk_free() if dfree command is used

If we have a broken system which reports incorrect sizes we provide the
'dfree command'. This command makes sure Samba gets the correct values.
However after that we call the quota command which then reports the
broken values. The dfree command should take care to provide the correct
values and in case of quota's it should also calculate the quote
correctly.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11403

Pair-Programmed-With: Michael Adam <obnox at samba.org>
Signed-off-by: Andreas Schneider <asn at samba.org>
Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/smbd/dfree.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/source3/smbd/dfree.c b/source3/smbd/dfree.c
index bcefea5..7b462e4 100644
--- a/source3/smbd/dfree.c
+++ b/source3/smbd/dfree.c
@@ -117,12 +117,14 @@ uint64_t sys_disk_free(connection_struct *conn, const char *path,
 				return (uint64_t)-1;
 			}
 		}
-	} else {
-		if (sys_fsusage(path, dfree, dsize) != 0) {
-			DEBUG (0, ("disk_free: sys_fsusage() failed. Error was : %s\n",
-				strerror(errno) ));
-			return (uint64_t)-1;
-		}
+
+		goto dfree_done;
+	}
+
+	if (sys_fsusage(path, dfree, dsize) != 0) {
+		DEBUG (0, ("disk_free: sys_fsusage() failed. Error was : %s\n",
+			strerror(errno) ));
+		return (uint64_t)-1;
 	}
 
 	if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) {
@@ -146,6 +148,7 @@ uint64_t sys_disk_free(connection_struct *conn, const char *path,
 		*dfree = MAX(1,*dfree);
 	}
 
+dfree_done:
 	disk_norm(bsize, dfree, dsize);
 
 	if ((*bsize) < 1024) {
-- 
2.4.5


>From 693b6a95951c61867c11eb3b5b3a1ca35558ac3a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Fri, 17 Jul 2015 09:37:52 +0200
Subject: [PATCH 2/3] s3-smbd: Remove the global dfree_broken variable

Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
---
 source3/smbd/dfree.c   | 1 +
 source3/smbd/globals.c | 3 ---
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/source3/smbd/dfree.c b/source3/smbd/dfree.c
index 7b462e4..0b89a29 100644
--- a/source3/smbd/dfree.c
+++ b/source3/smbd/dfree.c
@@ -57,6 +57,7 @@ uint64_t sys_disk_free(connection_struct *conn, const char *path,
 	uint64_t bsize_q = 0;
 	uint64_t dsize_q = 0;
 	const char *dfree_command;
+	static bool dfree_broken = false;
 
 	(*dfree) = (*dsize) = 0;
 	(*bsize) = 512;
diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c
index 03339b7..a501234 100644
--- a/source3/smbd/globals.c
+++ b/source3/smbd/globals.c
@@ -31,9 +31,6 @@ int outstanding_aio_calls = 0;
 struct smbd_dmapi_context *dmapi_ctx = NULL;
 #endif
 
-
-bool dfree_broken = false;
-
 /* how many write cache buffers have been allocated */
 unsigned int allocated_write_caches = 0;
 
-- 
2.4.5


>From e399dc56c8dac6371a08b86d3d026c7a6554e567 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Tue, 14 Jul 2015 16:30:35 +0200
Subject: [PATCH 3/3] selftest: Add test for the dfree command

Signed-off-by: Andreas Schneider <asn at samba.org>
---
 selftest/target/Samba3.pm                  |  8 +++++
 source3/script/tests/test_dfree_command.sh | 51 ++++++++++++++++++++++++++++++
 source3/selftest/tests.py                  |  1 +
 testprogs/blackbox/dfree.sh                |  2 ++
 4 files changed, 62 insertions(+)
 create mode 100755 source3/script/tests/test_dfree_command.sh
 create mode 100755 testprogs/blackbox/dfree.sh

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 03c78f2..9af8faa 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -563,6 +563,7 @@ sub setup_fileserver($$)
 {
 	my ($self, $path) = @_;
 	my $prefix_abs = abs_path($path);
+	my $srcdir_abs = abs_path($self->{srcdir});
 
 	print "PROVISIONING file server ...\n";
 
@@ -579,6 +580,9 @@ sub setup_fileserver($$)
 	my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
 	push(@dirs, $lower_case_share_dir_30000);
 
+	my $dfree_share_dir="$share_dir/dfree";
+	push(@dirs, $dfree_share_dir);
+
 	my $fileserver_options = "
 [lowercase]
 	path = $lower_case_share_dir
@@ -594,6 +598,10 @@ sub setup_fileserver($$)
 	default case = lower
 	preserve case = no
 	short preserve case = no
+[dfree]
+	path = $dfree_share_dir
+	comment = smb username is [%U]
+	dfree command = $srcdir_abs/testprogs/blackbox/dfree.sh
 	";
 
 	my $vars = $self->provision($path,
diff --git a/source3/script/tests/test_dfree_command.sh b/source3/script/tests/test_dfree_command.sh
new file mode 100755
index 0000000..c9c3aa6
--- /dev/null
+++ b/source3/script/tests/test_dfree_command.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# Blackbox test for 'dfree command'
+#
+
+if [ $# -lt 6 ]; then
+cat <<EOF
+Usage: test_dfree_command.sh SERVER DOMAIN USERNAME PASSWORD PREFIX SMBCLIENT
+EOF
+exit 1;
+fi
+
+SERVER=$1
+DOMAIN=$2
+USERNAME=$3
+PASSWORD=$4
+PREFIX=$5
+smbclient=$6
+shift 6
+failed=0
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+test_smbclient_dfree() {
+	name="$1"
+	share="$2"
+	cmd="$3"
+	shift
+	shift
+	subunit_start_test "$name"
+	output=$($VALGRIND $smbclient //$SERVER/$share -c "$cmd" $@ 2>&1)
+	status=$?
+	if [ x$status = x0 ]; then
+		echo "$output" | grep "2000 blocks of size 1024. 20 blocks available" >/dev/null
+		status=$?
+		if [ x$status = x0 ]; then
+			subunit_pass_test "$name"
+		else
+			echo "$output" | subunit_fail_test "$name"
+		fi
+	else
+		echo "$output" | subunit_fail_test "$name"
+	fi
+	return $status
+}
+
+
+test_smbclient_dfree "Test dfree command" dfree "l" -U$USERNAME%$PASSWORD || failed=`expr $failed + 1`
+
+exit $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 1f6174c..1833b9f 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -176,6 +176,7 @@ for env in ["nt4_dc"]:
 
 for env in ["fileserver"]:
     plantestsuite("samba3.blackbox.preserve_case (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_preserve_case.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$PREFIX', smbclient3])
+    plantestsuite("samba3.blackbox.dfree_command (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_dfree_command.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$PREFIX', smbclient3])
 
     #
     # tar command tests
diff --git a/testprogs/blackbox/dfree.sh b/testprogs/blackbox/dfree.sh
new file mode 100755
index 0000000..2da3cbd
--- /dev/null
+++ b/testprogs/blackbox/dfree.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "1000 10 2048"
-- 
2.4.5



More information about the samba-technical mailing list