[Mesa-dev] [PATCH 6/7] util/disk_cache: add a write helper

Timothy Arceri tarceri at itsqueeze.com
Thu Mar 16 13:11:58 UTC 2017



On 16/03/17 23:53, Grazvydas Ignotas wrote:
> On Thu, Mar 16, 2017 at 3:00 AM, Timothy Arceri <tarceri at itsqueeze.com> wrote:
>>
>>
>> On 16/03/17 10:09, Grazvydas Ignotas wrote:
>>>
>>> Simplifies the write code a bit and handles EINTR.
>>>
>>> Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
>>> ---
>>>  src/util/disk_cache.c | 40 ++++++++++++++++++++++++++--------------
>>>  1 file changed, 26 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
>>> index 904aa66..ad591be 100644
>>> --- a/src/util/disk_cache.c
>>> +++ b/src/util/disk_cache.c
>>> @@ -650,6 +650,24 @@ disk_cache_remove(struct disk_cache *cache, const
>>> cache_key key)
>>>        p_atomic_add(cache->size, - (uint64_t)sb.st_size);
>>>  }
>>>
>>> +static ssize_t
>>> +write_all(int fd, const void *buf, size_t count)
>>> +{
>>> +   const char *out = buf;
>>> +   ssize_t written;
>>> +   size_t done;
>>> +
>>> +   for (done = 0; done < count; done += written) {
>>> +      written = write(fd, out + done, count - done);
>>> +      if (written == -1) {
>>> +         if (errno != EINTR)
>>> +            return -1;
>>> +         written = 0;
>>
>>
>> I considered doing this but it didn't seem worth it. Also should you add a
>> retry limit? It's probably unlikely but I guess we could get stuck in a loop
>> here in theory?
>
> After this series there are 3 users which is enough I'd say. As for
> looping check, it wasn't there before so I've not bothered, on resend
> I can add it.

The helper is fine, I meant it didn't seem worth retrying on EINTR. 
There was no loop check before because we just exited when write() 
returned -1.


More information about the mesa-dev mailing list