Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/dm PR/52900: Tomohiro Kusumi: Fix kernel panic when ...



details:   https://anonhg.NetBSD.org/src/rev/64fa1f9aec65
branches:  trunk
changeset: 828820:64fa1f9aec65
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jan 05 14:22:05 2018 +0000

description:
PR/52900: Tomohiro Kusumi: Fix kernel panic when target's ->init() failed
Reliably unbusy the target in the *all* the destroy routines, so ioctl
does not need to do it.

diffstat:

 sys/dev/dm/dm_ioctl.c           |  19 ++++++++++++++--
 sys/dev/dm/dm_target_linear.c   |  30 ++++++++++++++++----------
 sys/dev/dm/dm_target_snapshot.c |  45 ++++++++++++++++++++++++----------------
 3 files changed, 61 insertions(+), 33 deletions(-)

diffs (truncated from 426 to 300 lines):

diff -r 38ae663400b2 -r 64fa1f9aec65 sys/dev/dm/dm_ioctl.c
--- a/sys/dev/dm/dm_ioctl.c     Fri Jan 05 13:20:45 2018 +0000
+++ b/sys/dev/dm/dm_ioctl.c     Fri Jan 05 14:22:05 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_ioctl.c,v 1.31 2017/06/01 02:45:09 chs Exp $      */
+/* $NetBSD: dm_ioctl.c,v 1.32 2018/01/05 14:22:05 christos Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -28,6 +28,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.32 2018/01/05 14:22:05 christos Exp $");
 
 /*
  * Locking is used to synchronise between ioctl calls and between dm_table's
@@ -158,6 +160,7 @@
 
        return 0;
 }
+
 /*
  * Get version ioctl call I do it as default therefore this
  * function is unused now.
@@ -168,6 +171,7 @@
 
        return 0;
 }
+
 /*
  * Get list of all available targets from global
  * target list and sent them back to libdevmapper.
@@ -190,6 +194,7 @@
 
        return 0;
 }
+
 /*
  * Create in-kernel entry for device. Device attributes such as name, uuid are
  * taken from proplib dictionary.
@@ -271,6 +276,7 @@
 
        return r;
 }
+
 /*
  * Get list of created device-mapper devices fromglobal list and
  * send it to kernel.
@@ -309,6 +315,7 @@
 
        return 0;
 }
+
 /*
  * Rename selected devices old name is in struct dm_ioctl.
  * newname is taken from dictionary
@@ -366,6 +373,7 @@
 
        return 0;
 }
+
 /*
  * Remove device from global list I have to remove active
  * and inactive tables first.
@@ -408,6 +416,7 @@
         */
        return config_detach(devt, DETACH_QUIET);
 }
+
 /*
  * Return actual state of device to libdevmapper.
  */
@@ -461,6 +470,7 @@
 
        return 0;
 }
+
 /*
  * Set only flag to suggest that device is suspended. This call is
  * not supported in NetBSD.
@@ -501,6 +511,7 @@
 
        return 0;
 }
+
 /*
  * Simulate Linux behaviour better and switch tables here and not in
  * dm_table_load_ioctl.
@@ -551,6 +562,7 @@
 
        return 0;
 }
+
 /*
  * Table management routines
  * lvm2tools doens't send name/uuid to kernel with table
@@ -596,6 +608,7 @@
 
        return 0;
 }
+
 /*
  * Get list of physical devices for active table.
  * Get dev_t from pdev vnode and insert it into cmd_array.
@@ -661,6 +674,7 @@
 
        return 0;
 }
+
 /*
  * Load new table/tables to device.
  * Call apropriate target init routine open all physical pdev's and
@@ -788,7 +802,6 @@
                        free(str, M_TEMP);
 
                        dm_dev_unbusy(dmv);
-                       dm_target_unbusy(target);
                        prop_object_iterator_release(iter);
                        return ret;
                }
@@ -804,6 +817,7 @@
        dm_dev_unbusy(dmv);
        return 0;
 }
+
 /*
  * Get description of all tables loaded to device from kernel
  * and send it to libdevmapper.
@@ -935,7 +949,6 @@
        return 0;
 }
 
-
 /*
  * For every call I have to set kernel driver version.
  * Because I can have commands supported only in other
diff -r 38ae663400b2 -r 64fa1f9aec65 sys/dev/dm/dm_target_linear.c
--- a/sys/dev/dm/dm_target_linear.c     Fri Jan 05 13:20:45 2018 +0000
+++ b/sys/dev/dm/dm_target_linear.c     Fri Jan 05 14:22:05 2018 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target_linear.c,v 1.16 2017/06/04 08:54:38 mbalmer Exp $      */
+/*        $NetBSD: dm_target_linear.c,v 1.17 2018/01/05 14:22:05 christos Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -28,7 +28,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: dm_target_linear.c,v 1.17 2018/01/05 14:22:05 christos Exp $");
 
 /*
  * This file implements initial version of device-mapper dklinear target.
@@ -95,6 +96,7 @@
 
        return 0;
 }
+
 /*
  * Status routine is called to get params string, which is target
  * specific. When dm_table_status_ioctl is called with flag
@@ -118,6 +120,7 @@
 
        return params;
 }
+
 /*
  * Do IO operation, called from dmstrategy routine.
  */
@@ -138,6 +141,7 @@
        return 0;
 
 }
+
 /*
  * Sync underlying disk caches.
  */
@@ -154,36 +158,35 @@
        return VOP_IOCTL(tlc->pdev->pdev_vnode,  DIOCCACHESYNC, &cmd,
            FREAD|FWRITE, kauth_cred_get());    
 }
+
 /*
  * Destroy target specific data. Decrement table pdevs.
  */
 int
 dm_target_linear_destroy(dm_table_entry_t * table_en)
 {
-       dm_target_linear_config_t *tlc;
 
        /*
         * Destroy function is called for every target even if it
         * doesn't have target_config.
         */
+       if (table_en->target_config == NULL)
+               goto out;
 
-       if (table_en->target_config == NULL)
-               return 0;
-
-       tlc = table_en->target_config;
+       dm_target_linear_config_t *tlc = table_en->target_config;
+       table_en->target_config = NULL;
 
        /* Decrement pdev ref counter if 0 remove it */
        dm_pdev_decr(tlc->pdev);
 
+       kmem_free(tlc, sizeof(*tlc));
+
+out:
        /* Unbusy target so we can unload it */
        dm_target_unbusy(table_en->target);
-
-       kmem_free(table_en->target_config, sizeof(dm_target_linear_config_t));
-
-       table_en->target_config = NULL;
-
        return 0;
 }
+
 /* Add this target pdev dependencies to prop_array_t */
 int
 dm_target_linear_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
@@ -200,6 +203,7 @@
 
        return 0;
 }
+
 /*
  * Register upcall device.
  * Linear target doesn't need any upcall devices but other targets like
@@ -210,6 +214,7 @@
 {
        return 0;
 }
+
 /*
  * Query physical block size of this target
  * For a linear target this is just the sector size of the underlying device
@@ -230,6 +235,7 @@
 
        return 0;
 }
+
 /*
  * Transform char s to uint64_t offset number.
  */
diff -r 38ae663400b2 -r 64fa1f9aec65 sys/dev/dm/dm_target_snapshot.c
--- a/sys/dev/dm/dm_target_snapshot.c   Fri Jan 05 13:20:45 2018 +0000
+++ b/sys/dev/dm/dm_target_snapshot.c   Fri Jan 05 14:22:05 2018 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target_snapshot.c,v 1.18 2017/06/04 08:54:38 mbalmer Exp $      */
+/*        $NetBSD: dm_target_snapshot.c,v 1.19 2018/01/05 14:22:05 christos Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -28,6 +28,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.19 2018/01/05 14:22:05 christos Exp $");
 
 /*
  * 1. Suspend my_data to temporarily stop any I/O while the snapshot is being
@@ -248,6 +250,7 @@
 
        return 0;
 }
+
 /*
  * Status routine is called to get params string, which is target
  * specific. When dm_table_status_ioctl is called with flag
@@ -296,6 +299,7 @@
 
        return params;
 }
+
 /* Strategy routine called from dm_strategy. */
 int
 dm_target_snapshot_strategy(dm_table_entry_t * table_en, struct buf * bp)
@@ -310,39 +314,37 @@
 
        return 0;
 }
+
 /* Doesn't do anything here. */
 int
 dm_target_snapshot_destroy(dm_table_entry_t * table_en)
 {
-       dm_target_snapshot_config_t *tsc;
 
        /*
         * Destroy function is called for every target even if it
         * doesn't have target_config.
         */



Home | Main Index | Thread Index | Old Index