]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - fs/ntfs/lcnalloc.c
Pull acpi-produce-consume into release branch
[mv-sheeva.git] / fs / ntfs / lcnalloc.c
index a4bc07616e5dd5afe4d6ede562b3dfff7f0d7169..5af3bf0b7eee15220a26841ad0812c6766720f38 100644 (file)
@@ -54,6 +54,8 @@ int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
        int ret = 0;
 
        ntfs_debug("Entering.");
+       if (!rl)
+               return 0;
        for (; rl->length; rl++) {
                int err;
 
@@ -163,17 +165,9 @@ runlist_element *ntfs_cluster_alloc(ntfs_volume *vol, const VCN start_vcn,
        BUG_ON(zone < FIRST_ZONE);
        BUG_ON(zone > LAST_ZONE);
 
-       /* Return empty runlist if @count == 0 */
-       // FIXME: Do we want to just return NULL instead? (AIA)
-       if (!count) {
-               rl = ntfs_malloc_nofs(PAGE_SIZE);
-               if (!rl)
-                       return ERR_PTR(-ENOMEM);
-               rl[0].vcn = start_vcn;
-               rl[0].lcn = LCN_RL_NOT_MAPPED;
-               rl[0].length = 0;
-               return rl;
-       }
+       /* Return NULL if @count is zero. */
+       if (!count)
+               return NULL;
        /* Take the lcnbmp lock for writing. */
        down_write(&vol->lcnbmp_lock);
        /*
@@ -785,13 +779,13 @@ out:
 
 /**
  * __ntfs_cluster_free - free clusters on an ntfs volume
- * @vi:                vfs inode whose runlist describes the clusters to free
- * @start_vcn: vcn in the runlist of @vi at which to start freeing clusters
+ * @ni:                ntfs inode whose runlist describes the clusters to free
+ * @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
- * @is_rollback:       if TRUE 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
- * 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
  * deallocated.  Thus, to completely free all clusters in a runlist, use
@@ -806,31 +800,28 @@ out:
  * Return the number of deallocated clusters (not counting sparse ones) on
  * success and -errno on error.
  *
- * Locking: - The runlist described by @vi must be unlocked on entry and is
- *           unlocked on return.
- *         - This function takes the runlist lock of @vi for reading and
- *           sometimes for writing and sometimes modifies the runlist.
+ * Locking: - The runlist described by @ni must be locked for writing on entry
+ *           and is locked on return.  Note the runlist may be modified when
+ *           needed runlist fragments need to be mapped.
  *         - The volume lcn bitmap must be unlocked on entry and is unlocked
  *           on return.
  *         - This function takes the volume lcn bitmap lock for writing and
  *           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 is_rollback)
 {
        s64 delta, to_free, total_freed, real_freed;
-       ntfs_inode *ni;
        ntfs_volume *vol;
        struct inode *lcnbmp_vi;
        runlist_element *rl;
        int err;
 
-       BUG_ON(!vi);
+       BUG_ON(!ni);
        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,
                        is_rollback ? " (rollback)" : "");
-       ni = NTFS_I(vi);
        vol = ni->vol;
        lcnbmp_vi = vol->lcnbmp_ino;
        BUG_ON(!lcnbmp_vi);
@@ -848,8 +839,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
 
        total_freed = real_freed = 0;
 
-       down_read(&ni->runlist.lock);
-       rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, FALSE);
+       rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, TRUE);
        if (IS_ERR(rl)) {
                if (!is_rollback)
                        ntfs_error(vol->sb, "Failed to find first runlist "
@@ -903,7 +893,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
 
                        /* Attempt to map runlist. */
                        vcn = rl->vcn;
-                       rl = ntfs_attr_find_vcn_nolock(ni, vcn, FALSE);
+                       rl = ntfs_attr_find_vcn_nolock(ni, vcn, TRUE);
                        if (IS_ERR(rl)) {
                                err = PTR_ERR(rl);
                                if (!is_rollback)
@@ -950,7 +940,6 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
                /* Update the total done clusters. */
                total_freed += to_free;
        }
-       up_read(&ni->runlist.lock);
        if (likely(!is_rollback))
                up_write(&vol->lcnbmp_lock);
 
@@ -960,7 +949,6 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
        ntfs_debug("Done.");
        return real_freed;
 err_out:
-       up_read(&ni->runlist.lock);
        if (is_rollback)
                return err;
        /* If no real clusters were freed, no need to rollback. */
@@ -973,7 +961,7 @@ err_out:
         * If rollback fails, set the volume errors flag, emit an error
         * message, and return the error code.
         */
-       delta = __ntfs_cluster_free(vi, start_vcn, total_freed, TRUE);
+       delta = __ntfs_cluster_free(ni, start_vcn, total_freed, TRUE);
        if (delta < 0) {
                ntfs_error(vol->sb, "Failed to rollback (error %i).  Leaving "
                                "inconsistent metadata!  Unmount and run "