Commit 715dc636 authored by Anton Altaparmakov's avatar Anton Altaparmakov

NTFS: Change ntfs_cluster_free() to require a write locked runlist on entry

      since we otherwise get into a lock reversal deadlock if a read locked
      runlist is passed in. In the process also change it to take an ntfs
      inode instead of a vfs inode as parameter.
Signed-off-by: default avatarAnton Altaparmakov <aia21@cantab.net>
parent 91fbc6ed
...@@ -25,6 +25,10 @@ ToDo/Notes: ...@@ -25,6 +25,10 @@ ToDo/Notes:
2.1.25-WIP 2.1.25-WIP
- Fix sparse warnings that have crept in over time. - Fix sparse warnings that have crept in over time.
- Change ntfs_cluster_free() to require a write locked runlist on entry
since we otherwise get into a lock reversal deadlock if a read locked
runlist is passed in. In the process also change it to take an ntfs
inode instead of a vfs inode as parameter.
2.1.24 - Lots of bug fixes and support more clean journal states. 2.1.24 - Lots of bug fixes and support more clean journal states.
......
...@@ -6,7 +6,7 @@ ntfs-objs := aops.o attrib.o collate.o compress.o debug.o dir.o file.o \ ...@@ -6,7 +6,7 @@ ntfs-objs := aops.o attrib.o collate.o compress.o debug.o dir.o file.o \
index.o inode.o mft.o mst.o namei.o runlist.o super.o sysctl.o \ index.o inode.o mft.o mst.o namei.o runlist.o super.o sysctl.o \
unistr.o upcase.o unistr.o upcase.o
EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.24\" EXTRA_CFLAGS = -DNTFS_VERSION=\"2.1.25-WIP\"
ifeq ($(CONFIG_NTFS_DEBUG),y) ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG EXTRA_CFLAGS += -DDEBUG
......
...@@ -779,14 +779,13 @@ switch_to_data1_zone: search_zone = 2; ...@@ -779,14 +779,13 @@ switch_to_data1_zone: search_zone = 2;
/** /**
* __ntfs_cluster_free - free clusters on an ntfs volume * __ntfs_cluster_free - free clusters on an ntfs volume
* @vi: vfs inode whose runlist describes the clusters to free * @ni: ntfs inode whose runlist describes the clusters to free
* @start_vcn: vcn in the runlist of @vi at which to start freeing clusters * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters
* @count: number of clusters to free or -1 for all clusters * @count: number of clusters to free or -1 for all clusters
* @write_locked: true if the runlist is locked for writing
* @is_rollback: true if this is a rollback operation * @is_rollback: true if this is a rollback operation
* *
* Free @count clusters starting at the cluster @start_vcn in the runlist * Free @count clusters starting at the cluster @start_vcn in the runlist
* described by the vfs inode @vi. * described by the vfs inode @ni.
* *
* If @count is -1, all clusters from @start_vcn to the end of the runlist are * If @count is -1, all clusters from @start_vcn to the end of the runlist are
* deallocated. Thus, to completely free all clusters in a runlist, use * deallocated. Thus, to completely free all clusters in a runlist, use
...@@ -801,31 +800,28 @@ switch_to_data1_zone: search_zone = 2; ...@@ -801,31 +800,28 @@ switch_to_data1_zone: search_zone = 2;
* Return the number of deallocated clusters (not counting sparse ones) on * Return the number of deallocated clusters (not counting sparse ones) on
* success and -errno on error. * success and -errno on error.
* *
* Locking: - The runlist described by @vi must be locked on entry and is * Locking: - The runlist described by @ni must be locked for writing on entry
* locked on return. Note if the runlist is locked for reading the * and is locked on return. Note the runlist may be modified when
* lock may be dropped and reacquired. Note the runlist may be * needed runlist fragments need to be mapped.
* modified when needed runlist fragments need to be mapped.
* - The volume lcn bitmap must be unlocked on entry and is unlocked * - The volume lcn bitmap must be unlocked on entry and is unlocked
* on return. * on return.
* - This function takes the volume lcn bitmap lock for writing and * - This function takes the volume lcn bitmap lock for writing and
* modifies the bitmap contents. * modifies the bitmap contents.
*/ */
s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn, s64 count,
const BOOL write_locked, const BOOL is_rollback) const BOOL is_rollback)
{ {
s64 delta, to_free, total_freed, real_freed; s64 delta, to_free, total_freed, real_freed;
ntfs_inode *ni;
ntfs_volume *vol; ntfs_volume *vol;
struct inode *lcnbmp_vi; struct inode *lcnbmp_vi;
runlist_element *rl; runlist_element *rl;
int err; int err;
BUG_ON(!vi); BUG_ON(!ni);
ntfs_debug("Entering for i_ino 0x%lx, start_vcn 0x%llx, count " ntfs_debug("Entering for i_ino 0x%lx, start_vcn 0x%llx, count "
"0x%llx.%s", vi->i_ino, (unsigned long long)start_vcn, "0x%llx.%s", ni->mft_no, (unsigned long long)start_vcn,
(unsigned long long)count, (unsigned long long)count,
is_rollback ? " (rollback)" : ""); is_rollback ? " (rollback)" : "");
ni = NTFS_I(vi);
vol = ni->vol; vol = ni->vol;
lcnbmp_vi = vol->lcnbmp_ino; lcnbmp_vi = vol->lcnbmp_ino;
BUG_ON(!lcnbmp_vi); BUG_ON(!lcnbmp_vi);
...@@ -843,7 +839,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, ...@@ -843,7 +839,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
total_freed = real_freed = 0; total_freed = real_freed = 0;
rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, write_locked); rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, TRUE);
if (IS_ERR(rl)) { if (IS_ERR(rl)) {
if (!is_rollback) if (!is_rollback)
ntfs_error(vol->sb, "Failed to find first runlist " ntfs_error(vol->sb, "Failed to find first runlist "
...@@ -897,7 +893,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, ...@@ -897,7 +893,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
/* Attempt to map runlist. */ /* Attempt to map runlist. */
vcn = rl->vcn; vcn = rl->vcn;
rl = ntfs_attr_find_vcn_nolock(ni, vcn, write_locked); rl = ntfs_attr_find_vcn_nolock(ni, vcn, TRUE);
if (IS_ERR(rl)) { if (IS_ERR(rl)) {
err = PTR_ERR(rl); err = PTR_ERR(rl);
if (!is_rollback) if (!is_rollback)
...@@ -965,8 +961,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, ...@@ -965,8 +961,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
* If rollback fails, set the volume errors flag, emit an error * If rollback fails, set the volume errors flag, emit an error
* message, and return the error code. * message, and return the error code.
*/ */
delta = __ntfs_cluster_free(vi, start_vcn, total_freed, write_locked, delta = __ntfs_cluster_free(ni, start_vcn, total_freed, TRUE);
TRUE);
if (delta < 0) { if (delta < 0) {
ntfs_error(vol->sb, "Failed to rollback (error %i). Leaving " ntfs_error(vol->sb, "Failed to rollback (error %i). Leaving "
"inconsistent metadata! Unmount and run " "inconsistent metadata! Unmount and run "
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the
* Linux-NTFS project. * Linux-NTFS project.
* *
* Copyright (c) 2004 Anton Altaparmakov * Copyright (c) 2004-2005 Anton Altaparmakov
* *
* This program/include file is free software; you can redistribute it and/or * This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published * modify it under the terms of the GNU General Public License as published
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include "types.h" #include "types.h"
#include "inode.h"
#include "runlist.h" #include "runlist.h"
#include "volume.h" #include "volume.h"
...@@ -42,18 +43,17 @@ extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol, ...@@ -42,18 +43,17 @@ extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
const VCN start_vcn, const s64 count, const LCN start_lcn, const VCN start_vcn, const s64 count, const LCN start_lcn,
const NTFS_CLUSTER_ALLOCATION_ZONES zone); const NTFS_CLUSTER_ALLOCATION_ZONES zone);
extern s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
s64 count, const BOOL write_locked, const BOOL is_rollback); s64 count, const BOOL is_rollback);
/** /**
* ntfs_cluster_free - free clusters on an ntfs volume * ntfs_cluster_free - free clusters on an ntfs volume
* @vi: vfs inode whose runlist describes the clusters to free * @ni: ntfs inode whose runlist describes the clusters to free
* @start_vcn: vcn in the runlist of @vi at which to start freeing clusters * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters
* @count: number of clusters to free or -1 for all clusters * @count: number of clusters to free or -1 for all clusters
* @write_locked: true if the runlist is locked for writing
* *
* Free @count clusters starting at the cluster @start_vcn in the runlist * Free @count clusters starting at the cluster @start_vcn in the runlist
* described by the vfs inode @vi. * described by the ntfs inode @ni.
* *
* If @count is -1, all clusters from @start_vcn to the end of the runlist are * If @count is -1, all clusters from @start_vcn to the end of the runlist are
* deallocated. Thus, to completely free all clusters in a runlist, use * deallocated. Thus, to completely free all clusters in a runlist, use
...@@ -65,19 +65,18 @@ extern s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, ...@@ -65,19 +65,18 @@ extern s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn,
* Return the number of deallocated clusters (not counting sparse ones) on * Return the number of deallocated clusters (not counting sparse ones) on
* success and -errno on error. * success and -errno on error.
* *
* Locking: - The runlist described by @vi must be locked on entry and is * Locking: - The runlist described by @ni must be locked for writing on entry
* locked on return. Note if the runlist is locked for reading the * and is locked on return. Note the runlist may be modified when
* lock may be dropped and reacquired. Note the runlist may be * needed runlist fragments need to be mapped.
* modified when needed runlist fragments need to be mapped.
* - The volume lcn bitmap must be unlocked on entry and is unlocked * - The volume lcn bitmap must be unlocked on entry and is unlocked
* on return. * on return.
* - This function takes the volume lcn bitmap lock for writing and * - This function takes the volume lcn bitmap lock for writing and
* modifies the bitmap contents. * modifies the bitmap contents.
*/ */
static inline s64 ntfs_cluster_free(struct inode *vi, const VCN start_vcn, static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
s64 count, const BOOL write_locked) s64 count)
{ {
return __ntfs_cluster_free(vi, start_vcn, count, write_locked, FALSE); return __ntfs_cluster_free(ni, start_vcn, count, FALSE);
} }
extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol, extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
......
...@@ -1953,7 +1953,7 @@ static int ntfs_mft_data_extend_allocation_nolock(ntfs_volume *vol) ...@@ -1953,7 +1953,7 @@ static int ntfs_mft_data_extend_allocation_nolock(ntfs_volume *vol)
a = ctx->attr; a = ctx->attr;
a->data.non_resident.highest_vcn = cpu_to_sle64(old_last_vcn - 1); a->data.non_resident.highest_vcn = cpu_to_sle64(old_last_vcn - 1);
undo_alloc: undo_alloc:
if (ntfs_cluster_free(vol->mft_ino, old_last_vcn, -1, TRUE) < 0) { if (ntfs_cluster_free(mft_ni, old_last_vcn, -1) < 0) {
ntfs_error(vol->sb, "Failed to free clusters from mft data " ntfs_error(vol->sb, "Failed to free clusters from mft data "
"attribute.%s", es); "attribute.%s", es);
NVolSetErrors(vol); NVolSetErrors(vol);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment