From: Daniel Mack Date: Sun, 17 Aug 2014 19:36:22 +0000 (+0200) Subject: metadata: remove kdbus_meta_find_item() X-Git-Tag: upstream/0.20140911.160207utc~39 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7fff8595e870237cf02754697e81da1732ad8b26;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git metadata: remove kdbus_meta_find_item() Remove kdbus_meta_find_item(), and store offsets of items inside the metadata in the metadata itself. This is nicer than walking the list again in order to find a specific element. --- diff --git a/connection.c b/connection.c index 8f090a6..9b96647 100644 --- a/connection.c +++ b/connection.c @@ -489,7 +489,7 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, size_t dst_name_len = 0; size_t payloads = 0; size_t fds = 0; - size_t meta = 0; + size_t meta_off = 0; size_t vec_data; size_t want, have; int ret = 0; @@ -541,7 +541,7 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, /* space for metadata/credential items */ if (kmsg->meta && kmsg->meta->size > 0 && kmsg->meta->domain == conn->meta->domain) { - meta = msg_size; + meta_off = msg_size; msg_size += kmsg->meta->size; } @@ -616,16 +616,15 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, } /* append message metadata/credential items */ - if (meta > 0) { - struct kdbus_item *item; + if (meta_off > 0) { + struct kdbus_meta *meta = kmsg->meta; /* * If the receiver requested credential information, store the * offset to the item here, so we can patch in the namespace - * translated versions later. + * translated versions later. k */ - item = kdbus_meta_find_item(kmsg->meta, KDBUS_ITEM_CREDS); - if (item) { + if (meta->attached & KDBUS_ATTACH_CREDS) { /* store kernel-view of the credentials */ queue->uid = current_uid(); queue->gid = current_gid(); @@ -633,13 +632,13 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, queue->tid = get_task_pid(current->group_leader, PIDTYPE_PID); - queue->creds_item_offset = - ((u8 *) item - (u8 *) kmsg->meta->data) + meta; + queue->creds_item_offset = meta_off + + meta->creds_item_off; } - item = kdbus_meta_find_item(kmsg->meta, KDBUS_ITEM_AUXGROUPS); - if (item) { + if (meta->attached & KDBUS_ATTACH_AUXGROUPS) { struct group_info *info; + struct kdbus_item *item; size_t item_elements; int i; @@ -650,6 +649,8 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, * metadata element was composed, clamp the array * length. */ + item = (struct kdbus_item *) + ((u8 *) meta->data + meta->auxgrps_item_off); item_elements = KDBUS_ITEM_PAYLOAD_SIZE(item) / sizeof(__u64); queue->auxgrps_count = min_t(unsigned int, @@ -671,11 +672,11 @@ static int kdbus_conn_queue_alloc(struct kdbus_conn *conn, } put_group_info(info); - queue->auxgrp_item_offset = - ((u8 *) item - (u8 *) kmsg->meta->data) + meta; + queue->auxgrp_item_offset = meta_off + + meta->auxgrps_item_off; } - ret = kdbus_pool_slice_copy(queue->slice, meta, + ret = kdbus_pool_slice_copy(queue->slice, meta_off, kmsg->meta->data, kmsg->meta->size); if (ret < 0) diff --git a/metadata.c b/metadata.c index b0ce6ec..13e31ba 100644 --- a/metadata.c +++ b/metadata.c @@ -57,27 +57,6 @@ int kdbus_meta_new(struct kdbus_meta **meta) return 0; } -/** - * kdbus_meta_find_item() - return the offset of a meta data element - * @meta: Metadata object - * @type: The metadata type to look for (KDBUS_ITEM_*) - * - * This function will iterate over the given metadata and return the - * item of type @type, if it exists. - * - * Return: the first item of the requested type, if found. NULL otherwise. - */ -struct kdbus_item *kdbus_meta_find_item(struct kdbus_meta *meta, u64 type) -{ - struct kdbus_item *item; - - KDBUS_ITEMS_FOREACH(item, meta->data, meta->size) - if (item->type == type) - return item; - - return NULL; -} - /** * kdbus_meta_free() - release metadata * @meta: Metadata object @@ -92,7 +71,7 @@ void kdbus_meta_free(struct kdbus_meta *meta) } static struct kdbus_item * -kdbus_meta_append_item(struct kdbus_meta *meta, size_t extra_size) +kdbus_meta_append_item(struct kdbus_meta *meta, u64 type, size_t extra_size) { struct kdbus_item *item; size_t size; @@ -129,6 +108,17 @@ kdbus_meta_append_item(struct kdbus_meta *meta, size_t extra_size) /* insert new record */ item = (struct kdbus_item *)((u8 *)meta->data + meta->size); + item->type = type; + + switch (type) { + case KDBUS_ITEM_CREDS: + meta->creds_item_off = meta->size; + break; + case KDBUS_ITEM_AUXGROUPS: + meta->auxgrps_item_off = meta->size; + break; + } + meta->size += KDBUS_ALIGN8(extra_size); return item; @@ -153,11 +143,10 @@ int kdbus_meta_append_data(struct kdbus_meta *meta, u64 type, return 0; size = KDBUS_ITEM_SIZE(len); - item = kdbus_meta_append_item(meta, size); + item = kdbus_meta_append_item(meta, type, size); if (IS_ERR(item)) return PTR_ERR(item); - item->type = type; item->size = KDBUS_ITEM_HEADER_SIZE + len; if (data) memcpy(item->data, data, len); @@ -178,11 +167,10 @@ static int kdbus_meta_append_timestamp(struct kdbus_meta *meta, u64 size = KDBUS_ITEM_SIZE(sizeof(struct kdbus_timestamp)); struct timespec ts; - item = kdbus_meta_append_item(meta, size); + item = kdbus_meta_append_item(meta, KDBUS_ITEM_TIMESTAMP, size); if (IS_ERR(item)) return PTR_ERR(item); - item->type = KDBUS_ITEM_TIMESTAMP; item->size = size; if (seq > 0) @@ -239,13 +227,12 @@ static int kdbus_meta_append_src_names(struct kdbus_meta *meta, len = strlen(e->name) + 1; size = KDBUS_ITEM_SIZE(sizeof(struct kdbus_name) + len); - item = kdbus_meta_append_item(meta, size); + item = kdbus_meta_append_item(meta, KDBUS_ITEM_NAME, size); if (IS_ERR(item)) { ret = PTR_ERR(item); break; } - item->type = KDBUS_ITEM_NAME; item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_name) + len; item->name.flags = e->flags; diff --git a/metadata.h b/metadata.h index 096700e..a142aea 100644 --- a/metadata.h +++ b/metadata.h @@ -30,6 +30,9 @@ struct kdbus_meta { struct kdbus_item *data; size_t size; size_t allocated_size; + + off_t creds_item_off; + off_t auxgrps_item_off; }; struct kdbus_conn; @@ -41,6 +44,5 @@ int kdbus_meta_append(struct kdbus_meta *meta, struct kdbus_conn *conn, u64 seq, u64 which); -struct kdbus_item *kdbus_meta_find_item(struct kdbus_meta *meta, u64 type); void kdbus_meta_free(struct kdbus_meta *meta); #endif