tdb: Write zero data using 8k buffer in transaction_expand_file()
authorAndreas Schneider <asn@samba.org>
Wed, 9 Aug 2017 08:53:12 +0000 (10:53 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 9 Aug 2017 20:34:17 +0000 (22:34 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/tdb/common/transaction.c

index 9b975eaa0476ed783caf2b201efcc195a4e9cfe7..c570cee48da980ae0adccaf83e6c0e884dd8a99b 100644 (file)
@@ -393,10 +393,20 @@ static int transaction_oob(struct tdb_context *tdb, tdb_off_t off,
 static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size,
                                   tdb_off_t addition)
 {
-       /* add a write to the transaction elements, so subsequent
-          reads see the zero data */
-       if (transaction_write(tdb, size, NULL, addition) != 0) {
-               return -1;
+       const char buf_zero[8192] = {0};
+       size_t buf_len = sizeof(buf_zero);
+
+       while (addition > 0) {
+               size_t n = MIN(addition, buf_len);
+               int ret;
+
+               ret = transaction_write(tdb, size, buf_zero, n);
+               if (ret != 0) {
+                       return ret;
+               }
+
+               addition -= n;
+               size += n;
        }
 
        tdb->transaction->expanded = true;