summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Tricca <flihp@twobit.us>2015-06-17 15:30:57 -0700
committerJoe MacDonald <joe_macdonald@mentor.com>2015-08-08 16:43:23 -0400
commit5cb8ef7d0403954ec947e743c36015738652809c (patch)
tree1fafae26d4d137ea7b727ab036e850510168f547
parent22ade8fbe7f72bce1159fa645a246c84fe2195a2 (diff)
downloadmeta-selinux-5cb8ef7d0403954ec947e743c36015738652809c.tar.gz
e2fsprogs: Add stub functions for an xattr cache and struct to hold the header and block data.
Signed-off-by: Philip Tricca <flihp@twobit.us> Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
-rw-r--r--recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch175
-rw-r--r--recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend1
2 files changed, 176 insertions, 0 deletions
diff --git a/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch b/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch
new file mode 100644
index 0000000..f2e4582
--- /dev/null
+++ b/recipes-devtools/e2fsprogs/e2fsprogs/misc-xattr-create-xattr-block-node.patch
@@ -0,0 +1,175 @@
1Add two new functions to manage a cache of xattr blocks as well as a new struct
2to build a linked list of xattr blocks.
3
4xattr_add_block: Adds a block to the cache. This function is supplied with a
5pointer to the head of a linked list of xattr blocks and an xattr block to add.
6The purpose of this cache is to allow sharing of what would otherwise be
7duplicate xattr blocks and so duplicates are not allowed in this cache. If an
8identical block is already in the cache a pointer to this block will be
9returned.
10
11xattr_rm_block: Removes a block from the cache. This function is supplied with
12a pointer to the cache and a node that shall be removed from the cache. The
13cache is searched for the node and the node is removed if found.
14
15Both functions are integrated into the 'set_inode_xattr'. Here the logic is
16rearranged to cope with associating preexisting xattr blocks with inodes as
17well as creating new blocks when necessary.
18
19Signed-off-by: Philip Tricca <flihp@twobit.us>
20
21Index: e2fsprogs-1.42.9/misc/xattr.c
22===================================================================
23--- e2fsprogs-1.42.9.orig/misc/xattr.c
24+++ e2fsprogs-1.42.9/misc/xattr.c
25@@ -25,6 +25,19 @@
26 #define XATTR_STDERR(fmt, args...) do {} while (0)
27 #endif
28
29+/* nodes for simple linked list to track xattr blocks, calling it a cache
30+ * would be a stretch ...
31+ */
32+typedef struct xattr_node xattr_node_t;
33+
34+struct xattr_node {
35+ struct ext2_ext_attr_header *header;
36+ blk_t block;
37+ struct xattr_node *next;
38+};
39+
40+xattr_node_t *xattr_list_head = NULL;
41+
42 /* structure for mapping xattr name prefix data */
43 typedef struct xattr_prefix {
44 int index;
45@@ -48,6 +61,17 @@ xattr_prefix_t xattr_prefixes [] = {
46 { 0 },
47 };
48
49+/* free xattr node and the buffer holding the xattr block */
50+static void
51+xattr_free_node (xattr_node_t *node)
52+{
53+ if (node) {
54+ if (node->header)
55+ free (node->header);
56+ free (node);
57+ }
58+}
59+
60 /* Free remaining resources after all files have been processed. */
61 void
62 xattr_cleanup ()
63@@ -260,6 +284,28 @@ out:
64 return ret;
65 }
66
67+/* Add an xattr node to the list specified by head. This function will update
68+ * head as necessary. It will return a pointer to the xattr_node_t added to the
69+ * list. In the event that an identical xattr block is already on the list this
70+ * function will return a pointer to the pre-existing node.
71+ */
72+static xattr_node_t*
73+xattr_add_block (xattr_node_t **head, xattr_node_t *node)
74+{
75+ XATTR_STDERR ("Adding xattr to the the node list.\n");
76+ return node;
77+}
78+
79+/* Remove xattr node from list. Returns pointer to the node being removed.
80+ * NOTE: We're not comparing the xattr blocks, just the nodes.
81+ */
82+static xattr_node_t*
83+xattr_rm_block (xattr_node_t **head, xattr_node_t *node)
84+{
85+ XATTR_STDERR ("Removing xattr from the node list.\n");
86+ return node;
87+}
88+
89 /* This is the entry point to the xattr module. This function copies the xattrs
90 * from the file at 'path' to the file system object at 'ino'.
91 *
92@@ -274,16 +320,21 @@ set_inode_xattr (ext2_filsys fs, ext2_in
93 errcode_t ret = 0;
94 char *buf = NULL;
95 struct ext2_inode inode = { 0 };
96- blk_t block = 0;
97- struct ext2_ext_attr_header *header = NULL;
98+ xattr_node_t *node = NULL, *node_tmp = NULL;
99 uint32_t newcount = 0;
100
101 XATTR_STDERR ("Copying xattrs from %s to inode 0x%x.\n", path, ino);
102+ /* Create an xattr_node_t for it and add it to the cache if appropriate */
103+ if (!(node = calloc (1, sizeof (xattr_node_t)))) {
104+ com_err (__func__, errno, "calloc");
105+ ret = errno;
106+ goto out;
107+ }
108 /* Populate the xattr block for the file at path */
109- if (ret = xattr_build_block (path, &header, fs->blocksize)) {
110+ if (ret = xattr_build_block (path, &(node->header), fs->blocksize)) {
111 goto out;
112 }
113- if (header == NULL) {
114+ if (node->header == NULL) {
115 XATTR_STDERR ("set_inode_xattrs: no xattrs for %s\n", path);
116 goto out;
117 }
118@@ -291,23 +342,38 @@ set_inode_xattr (ext2_filsys fs, ext2_in
119 com_err(__func__, ret, "ext2fs_read_inode");
120 goto out;
121 }
122- if (ret = ext2fs_alloc_block (fs, 0, NULL, &block)) {
123- com_err(__func__, ret, "ext2fs_alloc_block: returned %d", ret);
124+ if (!(node_tmp = xattr_add_block (&xattr_list_head, node))) {
125+ fprintf (stderr, "Cannot add NULL node to xattr_block list.\n");
126 goto out;
127 }
128- ext2fs_mark_block_bitmap2 (fs->block_map, block);
129- XATTR_STDERR ("writing xattr block 0x%x to disk:\n", block);
130- if (ret = ext2fs_write_ext_attr (fs, block, header)) {
131- com_err(__func__, ret, "ext2fs_write_ext_attr: returned %d", ret);
132- goto out;
133+ if (node == node_tmp) {
134+ /* xattr block is new: add to list & write to disk */
135+ XATTR_STDERR ("no pre-existing xattr block, creating / adding\n");
136+ if (ret = ext2fs_alloc_block (fs, 0, NULL, &node->block)) {
137+ com_err(__func__, ret, "ext2fs_alloc_block: returned %d", ret);
138+ xattr_rm_block (&xattr_list_head, node);
139+ goto out;
140+ }
141+ ext2fs_mark_block_bitmap2 (fs->block_map, node->block);
142+ XATTR_STDERR ("writing xattr block 0x%x to disk:\n", node->block);
143+ if (ret = ext2fs_write_ext_attr (fs, node->block, node->header)) {
144+ com_err(__func__, ret, "ext2fs_write_ext_attr: returned %d", ret);
145+ xattr_rm_block (&xattr_list_head, node);
146+ goto out;
147+ }
148+ } else {
149+ /* already have an identical xattr block, free the one we just made */
150+ XATTR_STDERR ("using xattr from existing block: 0x%x\n", node_tmp->block);
151+ xattr_free_node (node);
152+ node = node_tmp;
153 }
154 /* point inode for current file to xattr block, update block count and
155 * write inode to disk
156 */
157- inode.i_file_acl = block;
158+ inode.i_file_acl = node->block;
159 if (ret = ext2fs_adjust_ea_refcount2(fs,
160- block,
161- (char*)header,
162+ node->block,
163+ (char*)(node->header),
164 1,
165 &newcount))
166 {
167@@ -321,7 +387,6 @@ set_inode_xattr (ext2_filsys fs, ext2_in
168 if (ret = ext2fs_write_inode (fs, ino, &inode))
169 com_err(__func__, ret, "ext2fs_write_inode: returned %d", ret);
170 out:
171- if (header)
172- free (header);
173+ xattr_free_node (node);
174 return ret;
175 }
diff --git a/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend b/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend
index edc94d8..0705ec4 100644
--- a/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend
+++ b/recipes-devtools/e2fsprogs/e2fsprogs_1.42.9.bbappend
@@ -5,4 +5,5 @@ SRC_URI += " \
5 file://mke2fs.c-create_inode.c-copy-xattrs.patch \ 5 file://mke2fs.c-create_inode.c-copy-xattrs.patch \
6 file://lib-ext2fs-ext2_ext_attr.h-add-xattr-index.patch \ 6 file://lib-ext2fs-ext2_ext_attr.h-add-xattr-index.patch \
7 file://misc-xattr-create-xattr-block.patch \ 7 file://misc-xattr-create-xattr-block.patch \
8 file://misc-xattr-create-xattr-block-node.patch \
8" 9"