]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/util.c
Update bcachefs sources to b9bd69421f73 bcachefs: x-macro-ify inode flags enum
[bcachefs-tools-debian] / libbcachefs / util.c
index ae4f6de3c27435609cd7b7f009c710683b88893c..7ba5df4e828608cb8c4e00597bdb460d2b78517e 100644 (file)
@@ -112,10 +112,10 @@ got_unit:
 
 #define parse_or_ret(cp, _f)                   \
 do {                                           \
-       int ret = _f;                           \
-       if (ret < 0)                            \
-               return ret;                     \
-       cp += ret;                              \
+       int _ret = _f;                          \
+       if (_ret < 0)                           \
+               return _ret;                    \
+       cp += _ret;                             \
 } while (0)
 
 static int __bch2_strtou64_h(const char *cp, u64 *res)
@@ -216,6 +216,7 @@ u64 bch2_read_flag_list(char *opt, const char * const list[])
 
        while ((p = strsep(&s, ","))) {
                int flag = match_string(list, -1, p);
+
                if (flag < 0) {
                        ret = -1;
                        break;
@@ -268,6 +269,7 @@ void bch2_print_string_as_lines(const char *prefix, const char *lines)
 
 int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task)
 {
+#ifdef CONFIG_STACKTRACE
        unsigned nr_entries = 0;
        int ret = 0;
 
@@ -288,6 +290,9 @@ int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task)
        up_read(&task->signal->exec_update_lock);
 
        return ret;
+#else
+       return 0;
+#endif
 }
 
 void bch2_prt_backtrace(struct printbuf *out, bch_stacktrace *stack)
@@ -462,6 +467,24 @@ static void bch2_pr_time_units_aligned(struct printbuf *out, u64 ns)
        prt_printf(out, "%s", u->name);
 }
 
+#ifndef __KERNEL__
+#include <time.h>
+void bch2_prt_date_seconds(struct printbuf *out, time64_t sec)
+{
+       time_t t = sec;
+       char buf[64];
+       ctime_r(&t, buf);
+       prt_str(out, buf);
+}
+#else
+void bch2_prt_date_seconds(struct printbuf *out, time64_t sec)
+{
+       char buf[64];
+       snprintf(buf, sizeof(buf), "%ptT", &sec);
+       prt_u64(out, sec);
+}
+#endif
+
 #define TABSTOP_SIZE 12
 
 static inline void pr_name_and_units(struct printbuf *out, const char *name, u64 ns)
@@ -600,11 +623,9 @@ void bch2_time_stats_init(struct bch2_time_stats *stats)
 
 /**
  * bch2_ratelimit_delay() - return how long to delay until the next time to do
- * some work
- *
- * @d - the struct bch_ratelimit to update
- *
- * Returns the amount of time to delay by, in jiffies
+ *             some work
+ * @d:         the struct bch_ratelimit to update
+ * Returns:    the amount of time to delay by, in jiffies
  */
 u64 bch2_ratelimit_delay(struct bch_ratelimit *d)
 {
@@ -617,9 +638,8 @@ u64 bch2_ratelimit_delay(struct bch_ratelimit *d)
 
 /**
  * bch2_ratelimit_increment() - increment @d by the amount of work done
- *
- * @d - the struct bch_ratelimit to update
- * @done - the amount of work done, in arbitrary units
+ * @d:         the struct bch_ratelimit to update
+ * @done:      the amount of work done, in arbitrary units
  */
 void bch2_ratelimit_increment(struct bch_ratelimit *d, u64 done)
 {
@@ -756,10 +776,10 @@ void bch2_bio_map(struct bio *bio, void *base, size_t size)
        }
 }
 
-int bch2_bio_alloc_pages_noprof(struct bio *bio, size_t size, gfp_t gfp_mask)
+int bch2_bio_alloc_pages(struct bio *bio, size_t size, gfp_t gfp_mask)
 {
        while (size) {
-               struct page *page = alloc_pages_noprof(gfp_mask, 0);
+               struct page *page = alloc_pages(gfp_mask, 0);
                unsigned len = min_t(size_t, PAGE_SIZE, size);
 
                if (!page)
@@ -797,9 +817,10 @@ void memcpy_to_bio(struct bio *dst, struct bvec_iter dst_iter, const void *src)
        struct bvec_iter iter;
 
        __bio_for_each_segment(bv, dst, iter, dst_iter) {
-               void *dstp = kmap_atomic(bv.bv_page);
+               void *dstp = kmap_local_page(bv.bv_page);
+
                memcpy(dstp + bv.bv_offset, src, bv.bv_len);
-               kunmap_atomic(dstp);
+               kunmap_local(dstp);
 
                src += bv.bv_len;
        }
@@ -811,9 +832,10 @@ void memcpy_from_bio(void *dst, struct bio *src, struct bvec_iter src_iter)
        struct bvec_iter iter;
 
        __bio_for_each_segment(bv, src, iter, src_iter) {
-               void *srcp = kmap_atomic(bv.bv_page);
+               void *srcp = kmap_local_page(bv.bv_page);
+
                memcpy(dst, srcp + bv.bv_offset, bv.bv_len);
-               kunmap_atomic(srcp);
+               kunmap_local(srcp);
 
                dst += bv.bv_len;
        }