zfs-0.6.1-fix-zvol-initialization-r1.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. diff --git a/module/zfs/spa.c b/module/zfs/spa.c
  2. index e986e92..65f78b7 100644
  3. --- a/module/zfs/spa.c
  4. +++ b/module/zfs/spa.c
  5. @@ -64,6 +64,7 @@
  6. #include <sys/zfs_ioctl.h>
  7. #include <sys/dsl_scan.h>
  8. #include <sys/zfeature.h>
  9. +#include <sys/zvol.h>
  10. #ifdef _KERNEL
  11. #include <sys/bootprops.h>
  12. @@ -2856,6 +2857,7 @@ spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t *nvpolicy,
  13. spa_load_state_t state = SPA_LOAD_OPEN;
  14. int error;
  15. int locked = B_FALSE;
  16. + int firstopen = B_FALSE;
  17. *spapp = NULL;
  18. @@ -2879,6 +2881,8 @@ spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t *nvpolicy,
  19. if (spa->spa_state == POOL_STATE_UNINITIALIZED) {
  20. zpool_rewind_policy_t policy;
  21. + firstopen = B_TRUE;
  22. +
  23. zpool_get_rewind_policy(nvpolicy ? nvpolicy : spa->spa_config,
  24. &policy);
  25. if (policy.zrp_request & ZPOOL_DO_REWIND)
  26. @@ -2953,6 +2957,11 @@ spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t *nvpolicy,
  27. mutex_exit(&spa_namespace_lock);
  28. }
  29. +#ifdef _KERNEL
  30. + if (firstopen)
  31. + zvol_create_minors(spa->spa_name);
  32. +#endif
  33. +
  34. *spapp = spa;
  35. return (0);
  36. @@ -4010,6 +4019,10 @@ spa_import(const char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags)
  37. mutex_exit(&spa_namespace_lock);
  38. spa_history_log_version(spa, LOG_POOL_IMPORT);
  39. +#ifdef _KERNEL
  40. + zvol_create_minors(pool);
  41. +#endif
  42. +
  43. return (0);
  44. }
  45. diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c
  46. index 1226b2c..a9184a1 100644
  47. --- a/module/zfs/zfs_ioctl.c
  48. +++ b/module/zfs/zfs_ioctl.c
  49. @@ -1268,9 +1268,6 @@ zfs_ioc_pool_import(zfs_cmd_t *zc)
  50. error = err;
  51. }
  52. - if (error == 0)
  53. - zvol_create_minors(zc->zc_name);
  54. -
  55. nvlist_free(config);
  56. if (props)
  57. diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c
  58. index 43a7bb6..e35c91b 100644
  59. --- a/module/zfs/zvol.c
  60. +++ b/module/zfs/zvol.c
  61. @@ -1215,6 +1215,9 @@ zvol_alloc(dev_t dev, const char *name)
  62. zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);
  63. + spin_lock_init(&zv->zv_lock);
  64. + list_link_init(&zv->zv_next);
  65. +
  66. zv->zv_queue = blk_init_queue(zvol_request, &zv->zv_lock);
  67. if (zv->zv_queue == NULL)
  68. goto out_kmem;
  69. @@ -1248,9 +1251,6 @@ zvol_alloc(dev_t dev, const char *name)
  70. sizeof (rl_t), offsetof(rl_t, r_node));
  71. zv->zv_znode.z_is_zvol = TRUE;
  72. - spin_lock_init(&zv->zv_lock);
  73. - list_link_init(&zv->zv_next);
  74. -
  75. zv->zv_disk->major = zvol_major;
  76. zv->zv_disk->first_minor = (dev & MINORMASK);
  77. zv->zv_disk->fops = &zvol_ops;
  78. @@ -1561,30 +1561,36 @@ zvol_init(void)
  79. {
  80. int error;
  81. + list_create(&zvol_state_list, sizeof (zvol_state_t),
  82. + offsetof(zvol_state_t, zv_next));
  83. + mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL);
  84. +
  85. zvol_taskq = taskq_create(ZVOL_DRIVER, zvol_threads, maxclsyspri,
  86. zvol_threads, INT_MAX, TASKQ_PREPOPULATE);
  87. if (zvol_taskq == NULL) {
  88. printk(KERN_INFO "ZFS: taskq_create() failed\n");
  89. - return (-ENOMEM);
  90. + error = -ENOMEM;
  91. + goto out1;
  92. }
  93. error = register_blkdev(zvol_major, ZVOL_DRIVER);
  94. if (error) {
  95. printk(KERN_INFO "ZFS: register_blkdev() failed %d\n", error);
  96. - taskq_destroy(zvol_taskq);
  97. - return (error);
  98. + goto out2;
  99. }
  100. blk_register_region(MKDEV(zvol_major, 0), 1UL << MINORBITS,
  101. THIS_MODULE, zvol_probe, NULL, NULL);
  102. - mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL);
  103. - list_create(&zvol_state_list, sizeof (zvol_state_t),
  104. - offsetof(zvol_state_t, zv_next));
  105. + return (0);
  106. - (void) zvol_create_minors(NULL);
  107. +out2:
  108. + taskq_destroy(zvol_taskq);
  109. +out1:
  110. + mutex_destroy(&zvol_state_lock);
  111. + list_destroy(&zvol_state_list);
  112. - return (0);
  113. + return (error);
  114. }
  115. void
  116. diff --git a/scripts/zconfig.sh b/scripts/zconfig.sh
  117. index 141348c..281166c 100755
  118. --- a/scripts/zconfig.sh
  119. +++ b/scripts/zconfig.sh
  120. @@ -264,8 +264,9 @@ test_4() {
  121. zconfig_zvol_device_stat 0 ${POOL_NAME} ${FULL_ZVOL_NAME} \
  122. ${FULL_SNAP_NAME} ${FULL_CLONE_NAME} || fail 9
  123. - # Load the modules, wait 1 second for udev
  124. + # Load the modules, list the pools to ensure they are opened
  125. ${ZFS_SH} zfs="spa_config_path=${TMP_CACHE}" || fail 10
  126. + ${ZPOOL} list &>/dev/null
  127. # Verify the devices were created
  128. zconfig_zvol_device_stat 10 ${POOL_NAME} ${FULL_ZVOL_NAME} \
  129. diff --git a/udev/rules.d/90-zfs.rules.in b/udev/rules.d/90-zfs.rules.in
  130. index 52e1d63..a2715d2 100644
  131. --- a/udev/rules.d/90-zfs.rules.in
  132. +++ b/udev/rules.d/90-zfs.rules.in
  133. @@ -1,4 +1,4 @@
  134. -SUBSYSTEM!="block", GOTO="zfs_end"
  135. +SUBSYSTEM!="block|misc", GOTO="zfs_end"
  136. ACTION!="add|change", GOTO="zfs_end"
  137. ENV{ID_FS_TYPE}=="zfs", RUN+="/sbin/modprobe zfs"
  138. @@ -7,4 +7,6 @@ ENV{ID_FS_TYPE}=="zfs_member", RUN+="/sbin/modprobe zfs"
  139. KERNEL=="null", SYMLINK+="root"
  140. SYMLINK=="null", SYMLINK+="root"
  141. +SUBSYSTEM=="misc", KERNEL=="zfs", RUN+="@sbindir@/zpool list"
  142. +
  143. LABEL="zfs_end"