Unlock the record.
********************************************************************/
-static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
+static void byte_range_lock_flush(struct byte_range_lock *br_lck)
{
if (br_lck->read_only) {
SMB_ASSERT(!br_lck->modified);
done:
- SAFE_FREE(br_lck->lock_data);
+ br_lck->read_only = true;
+ br_lck->modified = false;
+
TALLOC_FREE(br_lck->record);
+}
+
+static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
+{
+ byte_range_lock_flush(br_lck);
+ SAFE_FREE(br_lck->lock_data);
return 0;
}
{
TDB_DATA key, data;
struct byte_range_lock *br_lck = TALLOC_P(mem_ctx, struct byte_range_lock);
+ bool do_read_only = read_only;
if (br_lck == NULL) {
return NULL;
if (!fsp->lockdb_clean) {
/* We must be read/write to clean
the dead entries. */
- read_only = False;
+ do_read_only = false;
}
- if (read_only) {
+ if (do_read_only) {
if (brlock_db->fetch(brlock_db, br_lck, key, &data) == -1) {
DEBUG(3, ("Could not fetch byte range lock record\n"));
TALLOC_FREE(br_lck);
return NULL;
}
br_lck->record = NULL;
- }
- else {
+ } else {
br_lck->record = brlock_db->fetch_locked(brlock_db, br_lck, key);
if (br_lck->record == NULL) {
data = br_lck->record->value;
}
- br_lck->read_only = read_only;
+ br_lck->read_only = do_read_only;
br_lck->lock_data = NULL;
talloc_set_destructor(br_lck, byte_range_lock_destructor);
print_lock_struct(i, &locks[i]);
}
}
+
+ if (do_read_only != read_only) {
+ /*
+ * this stores the record and gets rid of
+ * the write lock that is needed for a cleanup
+ */
+ byte_range_lock_flush(br_lck);
+ }
+
return br_lck;
}