]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/io.c
tdb2: remove looping for read on normal files.
[ccan] / ccan / tdb2 / io.c
index ae09597ec4eecacaf362f7c9af616103d9857f1f..999922b12e517c63be16ce1b20d7d22d077f9acc 100644 (file)
@@ -225,44 +225,6 @@ bool tdb_pwrite_all(int fd, const void *buf, size_t len, tdb_off_t off)
        return true;
 }
 
-/* Even on files, we can get partial reads due to signals. */
-bool tdb_pread_all(int fd, void *buf, size_t len, tdb_off_t off)
-{
-       while (len) {
-               ssize_t ret;
-               ret = pread(fd, buf, len, off);
-               if (ret < 0)
-                       return false;
-               if (ret == 0) {
-                       /* ETOOSHORT? */
-                       errno = EWOULDBLOCK;
-                       return false;
-               }
-               buf = (char *)buf + ret;
-               off += ret;
-               len -= ret;
-       }
-       return true;
-}
-
-bool tdb_read_all(int fd, void *buf, size_t len)
-{
-       while (len) {
-               ssize_t ret;
-               ret = read(fd, buf, len);
-               if (ret < 0)
-                       return false;
-               if (ret == 0) {
-                       /* ETOOSHORT? */
-                       errno = EWOULDBLOCK;
-                       return false;
-               }
-               buf = (char *)buf + ret;
-               len -= ret;
-       }
-       return true;
-}
-
 /* write a lump of data at a specified offset */
 static int tdb_write(struct tdb_context *tdb, tdb_off_t off, 
                     const void *buf, tdb_len_t len)
@@ -305,13 +267,14 @@ static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
        if (tdb->map_ptr) {
                memcpy(buf, off + (char *)tdb->map_ptr, len);
        } else {
-               if (!tdb_pread_all(tdb->fd, buf, len, off)) {
+               ssize_t r = pread(tdb->fd, buf, len, off);
+               if (r != len) {
                        tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
-                                  "tdb_read failed at %zu "
+                                  "tdb_read failed with %zi at %zu "
                                   "len=%zu (%s) map_size=%zu",
-                                (size_t)off, (size_t)len,
-                                strerror(errno),
-                                (size_t)tdb->map_size);
+                                  r, (size_t)off, (size_t)len,
+                                  strerror(errno),
+                                  (size_t)tdb->map_size);
                        return -1;
                }
        }
@@ -552,7 +515,7 @@ int tdb_access_commit(struct tdb_context *tdb, void *p)
 }
 
 static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
-                       bool write)
+                       bool write_mode)
 {
        if (unlikely(!tdb->map_ptr))
                return NULL;
@@ -562,10 +525,10 @@ static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
        return (char *)tdb->map_ptr + off;
 }
 
-void add_stat_(struct tdb_context *tdb, uint64_t *stat, size_t val)
+void add_stat_(struct tdb_context *tdb, uint64_t *s, size_t val)
 {
-       if ((uintptr_t)stat < (uintptr_t)tdb->stats + tdb->stats->size)
-               *stat += val;
+       if ((uintptr_t)s < (uintptr_t)tdb->stats + tdb->stats->size)
+               *s += val;
 }
 
 static const struct tdb_methods io_methods = {