Re: [PATCH 2/6] io_uring: add IORING_OP_PROVIDE_BUFFERS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 2020-03-09 11:17:46 -0600, Jens Axboe wrote:
> >> +static int io_add_buffers(struct io_provide_buf *pbuf, struct list_head *list)
> >> +{
> >> +	struct io_buffer *buf;
> >> +	u64 addr = pbuf->addr;
> >> +	int i, bid = pbuf->bid;
> >> +
> >> +	for (i = 0; i < pbuf->nbufs; i++) {
> >> +		buf = kmalloc(sizeof(*buf), GFP_KERNEL);
> >> +		if (!buf)
> >> +			break;
> >> +
> >> +		buf->addr = addr;
> >> +		buf->len = pbuf->len;
> >> +		buf->bid = bid;
> >> +		list_add(&buf->list, list);
> >> +		addr += pbuf->len;
> >> +		bid++;
> >> +	}
> >> +
> >> +	return i;
> >> +}
> > 
> > Hm, aren't you loosing an error here if you kmalloc fails for i > 0?
> > Afaict io_provide_buffes() only checks for ret != 0. I think userland
> > should know that a PROVIDE_BUFFERS failed, even if just partially (I'd
> > just make it fail wholesale).
> 
> The above one does have the issue that we're losing the error for i ==
> 0, current one does:
> 
> return i ? i : -ENOMEM;
> 
> But this is what most interfaces end up doing, return the number
> processed, if any, or error if none of them were added. Like a short
> read, for example, and you'd get EIO if you forwarded and tried again.
> So I tend to prefer doing it like that, at least to me it seems more
> logical than unwinding. The application won't know what buffer caused
> the error if you unwind, whereas it's perfectly clear if you asked to
> add 128 and we return 64 that the issue is with the 65th buffer.

Fair enough. I was/am thinking that this'd pretty much always be a fatal
error for the application. Which does seem a bit different from the
short read/write case, where there are plenty reasons to handle them
"silently" during normal operation.

But I can error out with the current interface, so ...

Greetings,

Andres Freund



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux