#include "path-util.h"
#include "process-util.h"
#include "random-util.h"
+#include "ratelimit.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
return 1;
}
+
+int posix_fallocate_loop(int fd, uint64_t offset, uint64_t size) {
+ RateLimit rl;
+ int r;
+
+ r = posix_fallocate(fd, offset, size); /* returns positive errnos on error */
+ if (r != EINTR)
+ return -r; /* Let's return negative errnos, like common in our codebase */
+
+ /* On EINTR try a couple of times more, but protect against busy looping
+ * (not more than 16 times per 10s) */
+ rl = (RateLimit) { 10 * USEC_PER_SEC, 16 };
+ while (ratelimit_below(&rl)) {
+ r = posix_fallocate(fd, offset, size);
+ if (r != EINTR)
+ return -r;
+ }
+
+ return -EINTR;
+}
static inline int conservative_rename(const char *oldpath, const char *newpath) {
return conservative_renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
}
+
+int posix_fallocate_loop(int fd, uint64_t offset, uint64_t size);
#include "escape.h"
#include "fd-util.h"
#include "format-util.h"
+#include "fs-util.h"
#include "io-util.h"
#include "journald-kmsg.h"
#include "journald-server.h"
return 0;
}
- r = posix_fallocate(fd, 0, sizeof(uint64_t));
- if (r != 0) {
+ r = posix_fallocate_loop(fd, 0, sizeof(uint64_t));
+ if (r < 0) {
log_error_errno(r, "Failed to allocate sequential number file, ignoring: %m");
return 0;
}
/* Note that the glibc fallocate() fallback is very
inefficient, hence we try to minimize the allocation area
as we can. */
- r = posix_fallocate(f->fd, old_size, new_size - old_size);
- if (r != 0)
- return -r;
+ r = posix_fallocate_loop(f->fd, old_size, new_size - old_size);
+ if (r < 0)
+ return r;
f->header->arena_size = htole64(new_size - old_header_size);
#endif
#include "fd-util.h"
+#include "fs-util.h"
#include "memory-util.h"
#include "sigbus.h"
#include "tests.h"
assert_se((fd = mkostemp(template, O_RDWR|O_CREAT|O_EXCL)) >= 0);
assert_se(unlink(template) >= 0);
- assert_se(posix_fallocate(fd, 0, page_size() * 8) >= 0);
+ assert_se(posix_fallocate_loop(fd, 0, page_size() * 8) >= 0);
p = mmap(NULL, page_size() * 16, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
assert_se(p != MAP_FAILED);