Whamcloud - gitweb
e2fsck/revoke.c: sync changes from kernel
authorTheodore Ts'o <tytso@mit.edu>
Sat, 9 Nov 2019 00:00:30 +0000 (19:00 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 9 Nov 2019 06:55:14 +0000 (01:55 -0500)
Sync up the revoke.c specific changes from kernel commits 9bcf976cb8b8
("jbd2: remove unnecessary arguments of jbd2_journal_write_revoke_records"),
32ab671599a8 ("jbd2: factor out common descriptor block initialization"),
70fd76140a6c ("block,fs: use REQ_* flags directly"), cd9cb405e0b9
("jbd2: don't leak memory if setting up journal fails"), 8bdd5b60e027
("jbd2: remove NULL check before calling kmem_cache_destroy()"),
547b9ad698b4 ("jbd2: flush_descriptor(): Do not decrease buffer head's
ref count"), and fdc3ef882a5d ("jbd2: Reserve space for revoke descriptor
blocks").

Nearly all of the changes is in code under an #ifdef __KERNEL__.  The
changes that will actually affect e2fprogs compilation are trivial and
easy to hand verify.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/revoke.c

index 44b3033..83b23fd 100644 (file)
@@ -119,11 +119,11 @@ struct jbd2_revoke_table_s
 
 
 #ifdef __KERNEL__
-static void write_one_revoke_record(journal_t *, transaction_t *,
+static void write_one_revoke_record(transaction_t *,
                                    struct list_head *,
                                    struct buffer_head **, int *,
-                                   struct jbd2_revoke_record_s *, int);
-static void flush_descriptor(journal_t *, struct buffer_head *, int, int);
+                                   struct jbd2_revoke_record_s *);
+static void flush_descriptor(journal_t *, struct buffer_head *, int);
 #endif
 
 /* Utility functions to maintain the revoke table */
@@ -185,14 +185,10 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal,
 
 void jbd2_journal_destroy_revoke_caches(void)
 {
-       if (jbd2_revoke_record_cache) {
-               kmem_cache_destroy(jbd2_revoke_record_cache);
-               jbd2_revoke_record_cache = NULL;
-       }
-       if (jbd2_revoke_table_cache) {
-               kmem_cache_destroy(jbd2_revoke_table_cache);
-               jbd2_revoke_table_cache = NULL;
-       }
+       kmem_cache_destroy(jbd2_revoke_record_cache);
+       jbd2_revoke_record_cache = NULL;
+       kmem_cache_destroy(jbd2_revoke_table_cache);
+       jbd2_revoke_table_cache = NULL;
 }
 
 int __init jbd2_journal_init_revoke_caches(void)
@@ -282,6 +278,7 @@ int jbd2_journal_init_revoke(journal_t *journal, int hash_size)
 
 fail1:
        jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]);
+       journal->j_revoke_table[0] = NULL;
 fail0:
        return -ENOMEM;
 }
@@ -371,6 +368,11 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr,
        }
 #endif
 
+       if (WARN_ON_ONCE(handle->h_revoke_credits <= 0)) {
+               if (!bh_in)
+                       brelse(bh);
+               return -EIO;
+       }
        /* We really ought not ever to revoke twice in a row without
            first having the revoke cancelled: it's illegal to free a
            block twice without allocating it in between! */
@@ -391,6 +393,7 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr,
                        __brelse(bh);
                }
        }
+       handle->h_revoke_credits--;
 
        jbd_debug(2, "insert revoke for block %llu, bh_in=%p\n",blocknr, bh_in);
        err = insert_revoke_hash(journal, blocknr,
@@ -521,11 +524,10 @@ void jbd2_journal_switch_revoke_table(journal_t *journal)
  * Write revoke records to the journal for all entries in the current
  * revoke hash, deleting the entries as we go.
  */
-void jbd2_journal_write_revoke_records(journal_t *journal,
-                                      transaction_t *transaction,
-                                      struct list_head *log_bufs,
-                                      int write_op)
+void jbd2_journal_write_revoke_records(transaction_t *transaction,
+                                      struct list_head *log_bufs)
 {
+       journal_t *journal = transaction->t_journal;
        struct buffer_head *descriptor;
        struct jbd2_revoke_record_s *record;
        struct jbd2_revoke_table_s *revoke;
@@ -546,16 +548,15 @@ void jbd2_journal_write_revoke_records(journal_t *journal,
                while (!list_empty(hash_list)) {
                        record = (struct jbd2_revoke_record_s *)
                                hash_list->next;
-                       write_one_revoke_record(journal, transaction, log_bufs,
-                                               &descriptor, &offset,
-                                               record, write_op);
+                       write_one_revoke_record(transaction, log_bufs,
+                                               &descriptor, &offset, record);
                        count++;
                        list_del(&record->hash);
                        kmem_cache_free(jbd2_revoke_record_cache, record);
                }
        }
        if (descriptor)
-               flush_descriptor(journal, descriptor, offset, write_op);
+               flush_descriptor(journal, descriptor, offset);
        jbd_debug(1, "Wrote %d revoke records\n", count);
 }
 
@@ -564,18 +565,16 @@ void jbd2_journal_write_revoke_records(journal_t *journal,
  * block if the old one is full or if we have not already created one.
  */
 
-static void write_one_revoke_record(journal_t *journal,
-                                   transaction_t *transaction,
+static void write_one_revoke_record(transaction_t *transaction,
                                    struct list_head *log_bufs,
                                    struct buffer_head **descriptorp,
                                    int *offsetp,
-                                   struct jbd2_revoke_record_s *record,
-                                   int write_op)
+                                   struct jbd2_revoke_record_s *record)
 {
+       journal_t *journal = transaction->t_journal;
        int csum_size = 0;
        struct buffer_head *descriptor;
        int sz, offset;
-       journal_header_t *header;
 
        /* If we are already aborting, this all becomes a noop.  We
            still need to go round the loop in
@@ -599,19 +598,16 @@ static void write_one_revoke_record(journal_t *journal,
        /* Make sure we have a descriptor with space left for the record */
        if (descriptor) {
                if (offset + sz > journal->j_blocksize - csum_size) {
-                       flush_descriptor(journal, descriptor, offset, write_op);
+                       flush_descriptor(journal, descriptor, offset);
                        descriptor = NULL;
                }
        }
 
        if (!descriptor) {
-               descriptor = jbd2_journal_get_descriptor_buffer(journal);
+               descriptor = jbd2_journal_get_descriptor_buffer(transaction,
+                                                       JBD2_REVOKE_BLOCK);
                if (!descriptor)
                        return;
-               header = (journal_header_t *)descriptor->b_data;
-               header->h_magic     = ext2fs_cpu_to_be32(JBD2_MAGIC_NUMBER);
-               header->h_blocktype = ext2fs_cpu_to_be32(JBD2_REVOKE_BLOCK);
-               header->h_sequence  = ext2fs_cpu_to_be32(transaction->t_tid);
 
                /* Record it so that we can wait for IO completion later */
                BUFFER_TRACE(descriptor, "file in log_bufs");
@@ -656,14 +652,12 @@ static void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
 
 static void flush_descriptor(journal_t *journal,
                             struct buffer_head *descriptor,
-                            int offset, int write_op)
+                            int offset)
 {
        jbd2_journal_revoke_header_t *header;
 
-       if (is_journal_aborted(journal)) {
-               put_bh(descriptor);
+       if (is_journal_aborted(journal))
                return;
-       }
 
        header = (jbd2_journal_revoke_header_t *)descriptor->b_data;
        header->r_count = ext2fs_cpu_to_be32(offset);
@@ -672,7 +666,7 @@ static void flush_descriptor(journal_t *journal,
        set_buffer_jwrite(descriptor);
        BUFFER_TRACE(descriptor, "write");
        set_buffer_dirty(descriptor);
-       write_dirty_buffer(descriptor, write_op);
+       write_dirty_buffer(descriptor, REQ_SYNC);
 }
 #endif