From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] Btrfs-progs: fix bus error on sparc
Date: Mon, 2 Dec 2013 15:22:27 +0800 [thread overview]
Message-ID: <1385968947-8630-1-git-send-email-bo.li.liu@oracle.com> (raw)
A type punning from (void *) to (u64 *) plus reading its value will cause
bus error on the Linux OS installed on sparc arch, because sparc core will
do a misaligned access and we don't have an option like -misalign or -xmemalign
in gcc.
Instead we introduce a struct to avoid the memory misalignment.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
disk-io.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/disk-io.c b/disk-io.c
index 0af3898..eed7d7e 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -650,10 +650,14 @@ insert:
return root;
}
+struct root_obj {
+ u64 objectid;
+};
+
static int btrfs_fs_roots_compare_objectids(struct rb_node *node,
void *data)
{
- u64 objectid = *((u64 *)data);
+ u64 objectid = ((struct root_obj *)data)->objectid;
struct btrfs_root *root;
root = rb_entry(node, struct btrfs_root, rb_node);
@@ -669,9 +673,11 @@ static int btrfs_fs_roots_compare_roots(struct rb_node *node1,
struct rb_node *node2)
{
struct btrfs_root *root;
+ struct root_obj obj;
root = rb_entry(node2, struct btrfs_root, rb_node);
- return btrfs_fs_roots_compare_objectids(node1, (void *)&root->objectid);
+ obj.objectid = root->objectid;
+ return btrfs_fs_roots_compare_objectids(node1, (void *)&obj);
}
struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
@@ -680,6 +686,7 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
struct btrfs_root *root;
struct rb_node *node;
int ret;
+ struct root_obj obj;
if (location->objectid == BTRFS_ROOT_TREE_OBJECTID)
return fs_info->tree_root;
@@ -695,7 +702,8 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
BUG_ON(location->objectid == BTRFS_TREE_RELOC_OBJECTID ||
location->offset != (u64)-1);
- node = rb_search(&fs_info->fs_root_tree, (void *)&location->objectid,
+ obj.objectid = location->objectid;
+ node = rb_search(&fs_info->fs_root_tree, (void *)&obj,
btrfs_fs_roots_compare_objectids, NULL);
if (node)
return container_of(node, struct btrfs_root, rb_node);
--
1.8.1.4
next reply other threads:[~2013-12-02 7:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-02 7:22 Liu Bo [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-01-17 2:22 [PATCH] Btrfs-progs: Fix bus error on sparc Ivan Jager
2014-01-17 13:58 ` David Sterba
2014-01-17 16:47 ` Ivan Jager
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385968947-8630-1-git-send-email-bo.li.liu@oracle.com \
--to=bo.li.liu@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).