It 'pops' out to user space through some protocol defined between a
relayfs kernel client and the user space program. relayfs doesn't say
anything about the protocol, but does provide the kernel client enough
information about the state of the channel via relay_info(), which
supplies among other things (these aren't the real names, they're
changed here to make things maybe a little clearer):
n_subbufs - number of sub-buffers
subbuf_size - size of each sub-bufer
subbuf_complete[] - array of booleans basically the result of
fillcount[subbuf_no] == subbuf_size
subbufs_produced - by the channel
subbufs_consumed - by userspace client, maybe
This is enough information for a userspace client to figure out what
to log. How it gets there and when is up to the client. For
instance, the kernel client could send a signal whenever a sub-buffer
is full (which it's notified of, if it chooses to be, by a delivery
callback). The user client could then do something like
buf = mmap(fd, n_bufs * bufsize); /* whole channel is mapped */
sighandler()
{
get_channel_info_from_kernel(&info); /* ioctl/procfs/sysfs/... */
subbufs_ready = subbufs_produced - subbufs_consumed;
for(i=0; i<subbufs_ready; i++) {
subbuf_no = (subbufs_consumed + i) % n_subbufs;
if(!buffer_complete[subbuf_no])
break; /* Try again next sig */
write(log_fd, buf + subbufno * subbuf_size, subbuf_size);
}
}
> And then, once I have this, next time I read I don't want to read
> what I already did; I guess I can advance my buf pointer to
> buf+real_size, but then how do I wrap around - meaning, how do I
> detect when do I have to wrap?
>
Wrapping is taken care of automatically in the above code.
-- Regards,Tom Zanussi <zanussi@us.ibm.com> IBM Linux Technology Center/RAS
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/