a5bd9f6
From 42aa5a0f3a2519102f5f925bd7147e93a641682a Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Fri, 22 Mar 2013 22:18:38 +0100
a5bd9f6
Subject: [PATCH 224/364] 	* grub-core/fs/zfs/zfs.c: Fix incorrect
a5bd9f6
 handling of special volumes.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog              |  4 ++++
a5bd9f6
 grub-core/fs/zfs/zfs.c | 59 ++++++++++++++++++++++++++++++++++++--------------
a5bd9f6
 2 files changed, 47 insertions(+), 16 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 5582e13..8175269 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,9 @@
a5bd9f6
 2013-03-22  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
+	* grub-core/fs/zfs/zfs.c: Fix incorrect handling of special volumes.
a5bd9f6
+
a5bd9f6
+2013-03-22  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
 	Add ability to generate newc additions on runtime.
a5bd9f6
 
a5bd9f6
 2013-03-22  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
a5bd9f6
index 822d65b..3d57978 100644
a5bd9f6
--- a/grub-core/fs/zfs/zfs.c
a5bd9f6
+++ b/grub-core/fs/zfs/zfs.c
a5bd9f6
@@ -3695,7 +3695,7 @@ grub_zfs_getmdnobj (grub_device_t dev, const char *fsfilename,
a5bd9f6
   return err;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-static void
a5bd9f6
+static grub_err_t
a5bd9f6
 fill_fs_info (struct grub_dirhook_info *info,
a5bd9f6
 	      dnode_end_t mdn, struct grub_zfs_data *data)
a5bd9f6
 {
a5bd9f6
@@ -3716,30 +3716,32 @@ fill_fs_info (struct grub_dirhook_info *info,
a5bd9f6
       if (err)
a5bd9f6
 	{
a5bd9f6
 	  grub_dprintf ("zfs", "failed here\n");
a5bd9f6
-	  return;
a5bd9f6
+	  return err;
a5bd9f6
 	}
a5bd9f6
     }
a5bd9f6
-  make_mdn (&mdn, data);
a5bd9f6
+  err = make_mdn (&mdn, data);
a5bd9f6
+  if (err)
a5bd9f6
+    return err;
a5bd9f6
   err = dnode_get (&mdn, MASTER_NODE_OBJ, DMU_OT_MASTER_NODE, 
a5bd9f6
 		   &dn, data);
a5bd9f6
   if (err)
a5bd9f6
     {
a5bd9f6
       grub_dprintf ("zfs", "failed here\n");
a5bd9f6
-      return;
a5bd9f6
+      return err;
a5bd9f6
     }
a5bd9f6
   
a5bd9f6
   err = zap_lookup (&dn, ZFS_ROOT_OBJ, &objnum, data, 0);
a5bd9f6
   if (err)
a5bd9f6
     {
a5bd9f6
       grub_dprintf ("zfs", "failed here\n");
a5bd9f6
-      return;
a5bd9f6
+      return err;
a5bd9f6
     }
a5bd9f6
   
a5bd9f6
   err = dnode_get (&mdn, objnum, 0, &dn, data);
a5bd9f6
   if (err)
a5bd9f6
     {
a5bd9f6
       grub_dprintf ("zfs", "failed here\n");
a5bd9f6
-      return;
a5bd9f6
+      return err;
a5bd9f6
     }
a5bd9f6
   
a5bd9f6
   if (dn.dn.dn_bonustype == DMU_OT_SA)
a5bd9f6
@@ -3757,12 +3759,12 @@ fill_fs_info (struct grub_dirhook_info *info,
a5bd9f6
 
a5bd9f6
 	  err = zio_read (bp, dn.endian, &sahdrp, NULL, data);
a5bd9f6
 	  if (err)
a5bd9f6
-	    return;
a5bd9f6
+	    return err;
a5bd9f6
 	}
a5bd9f6
       else
a5bd9f6
 	{
a5bd9f6
 	  grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt");
a5bd9f6
-	  return;
a5bd9f6
+	  return grub_errno;
a5bd9f6
 	}
a5bd9f6
 
a5bd9f6
       hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp));
a5bd9f6
@@ -3775,7 +3777,7 @@ fill_fs_info (struct grub_dirhook_info *info,
a5bd9f6
       info->mtimeset = 1;
a5bd9f6
       info->mtime = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_mtime[0], dn.endian);
a5bd9f6
     }
a5bd9f6
-  return;
a5bd9f6
+  return 0;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 /* Helper for grub_zfs_dir.  */
a5bd9f6
@@ -3846,11 +3848,19 @@ iterate_zap_fs (const char *name, grub_uint64_t val,
a5bd9f6
   dnode_end_t mdn;
a5bd9f6
   err = dnode_get (&(ctx->data->mos), val, 0, &mdn, ctx->data);
a5bd9f6
   if (err)
a5bd9f6
-    return 0;
a5bd9f6
+    {
a5bd9f6
+      grub_errno = 0;
a5bd9f6
+      return 0;
a5bd9f6
+    }
a5bd9f6
   if (mdn.dn.dn_type != DMU_OT_DSL_DIR)
a5bd9f6
     return 0;
a5bd9f6
 
a5bd9f6
-  fill_fs_info (&info, mdn, ctx->data);
a5bd9f6
+  err = fill_fs_info (&info, mdn, ctx->data);
a5bd9f6
+  if (err)
a5bd9f6
+    {
a5bd9f6
+      grub_errno = 0;
a5bd9f6
+      return 0;
a5bd9f6
+    }
a5bd9f6
   return ctx->hook (name, &info, ctx->hook_data);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
@@ -3868,12 +3878,20 @@ iterate_zap_snap (const char *name, grub_uint64_t val,
a5bd9f6
 
a5bd9f6
   err = dnode_get (&(ctx->data->mos), val, 0, &mdn, ctx->data);
a5bd9f6
   if (err)
a5bd9f6
-    return 0;
a5bd9f6
+    {
a5bd9f6
+      grub_errno = 0;
a5bd9f6
+      return 0;
a5bd9f6
+    }
a5bd9f6
 
a5bd9f6
   if (mdn.dn.dn_type != DMU_OT_DSL_DATASET)
a5bd9f6
     return 0;
a5bd9f6
 
a5bd9f6
-  fill_fs_info (&info, mdn, ctx->data);
a5bd9f6
+  err = fill_fs_info (&info, mdn, ctx->data);
a5bd9f6
+  if (err)
a5bd9f6
+    {
a5bd9f6
+      grub_errno = 0;
a5bd9f6
+      return 0;
a5bd9f6
+    }
a5bd9f6
 
a5bd9f6
   name2 = grub_malloc (grub_strlen (name) + 2);
a5bd9f6
   name2[0] = '@';
a5bd9f6
@@ -3913,9 +3931,18 @@ grub_zfs_dir (grub_device_t device, const char *path,
a5bd9f6
       dnode_end_t dn;
a5bd9f6
       struct grub_dirhook_info info;
a5bd9f6
 
a5bd9f6
-      fill_fs_info (&info, data->dnode, data);
a5bd9f6
-      hook ("@", &info, hook_data);
a5bd9f6
-      
a5bd9f6
+      err = fill_fs_info (&info, data->dnode, data);
a5bd9f6
+      if (err)
a5bd9f6
+	{
a5bd9f6
+	  zfs_unmount (data);
a5bd9f6
+	  return err;
a5bd9f6
+	}
a5bd9f6
+      if (hook ("@", &info, hook_data))
a5bd9f6
+	{
a5bd9f6
+	  zfs_unmount (data);
a5bd9f6
+	  return GRUB_ERR_NONE;
a5bd9f6
+	}
a5bd9f6
+
a5bd9f6
       childobj = grub_zfs_to_cpu64 (((dsl_dir_phys_t *) DN_BONUS (&data->dnode.dn))->dd_child_dir_zapobj, data->dnode.endian);
a5bd9f6
       headobj = grub_zfs_to_cpu64 (((dsl_dir_phys_t *) DN_BONUS (&data->dnode.dn))->dd_head_dataset_obj, data->dnode.endian);
a5bd9f6
       err = dnode_get (&(data->mos), childobj,
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6