[PATCH] notifyd: fix memory alignment

Jeremy Allison jra at samba.org
Fri Jul 17 18:12:46 UTC 2015


On Thu, Jul 16, 2015 at 09:47:53PM +0300, Uri Simchoni wrote:
> Best thing is to set up the DB fetching in a way that the data is
> aligned when fetched (the parse function can verify this). I'll look
> into it but xtdb experts can look into it without the learning curve.
> Second best option is to have an array that grows as-needed. This
> removes the allocations but not the copying.

Yeah, we can't avoid the memcpy I think (if you can
think of a way I'm very interested).

But we could re-structure notifyd_parse_entry()
and rename it notifyd_process_entries().

Pass in a pointer to a 'process_entry' function
that takes a void *private pointer, passed
in from the calling function as a state struct,
and then notifyd_process_entries() becomes
something like:

void notifyd_process_entries(uint8_t *buf, size_t buflen,
			void (*process_fn)(struct notifyd_instance *,
					   void *private),
			void *private)
{
	size_t num_instances = buflen / sizeof(struct notifyd_instance)
	for (i = 0; i < num_instances; i++) {
		struct notifyd_instance instance;
		memcpy(&instance, &buf[i*sizeof(struct notifyd_instance)],
			sizeof(struct notifyd_instance));
		(*process_fn)(&instance, private);
	}
}

Volker, is this what you had in mind ? Uri, does
that help in terms of modifying the patch for this ?



More information about the samba-technical mailing list