Skip to content

Commit 59154f2

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_prt_datetime()
Improved, better named version of pr_time(). Signed-off-by: Kent Overstreet <[email protected]>
1 parent bf61dcd commit 59154f2

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

fs/bcachefs/sb-errors.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static void bch2_sb_errors_to_text(struct printbuf *out, struct bch_sb *sb,
6161
{
6262
struct bch_sb_field_errors *e = field_to_type(f, errors);
6363
unsigned i, nr = bch2_sb_field_errors_nr_entries(e);
64-
u64 now = ktime_get_real_seconds();
6564

6665
if (out->nr_tabstops <= 1)
6766
printbuf_tabstop_push(out, 16);
@@ -71,9 +70,7 @@ static void bch2_sb_errors_to_text(struct printbuf *out, struct bch_sb *sb,
7170
prt_tab(out);
7271
prt_u64(out, BCH_SB_ERROR_ENTRY_NR(&e->entries[i]));
7372
prt_tab(out);
74-
bch2_pr_time_units(out, (now - le64_to_cpu(e->entries[i].last_error_time)) *
75-
NSEC_PER_SEC);
76-
prt_str(out, " ago");
73+
bch2_prt_datetime(out, le64_to_cpu(e->entries[i].last_error_time));
7774
prt_newline(out);
7875
}
7976
}

fs/bcachefs/sb-members.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static void member_to_text(struct printbuf *out,
235235
prt_printf(out, "Last mount:");
236236
prt_tab(out);
237237
if (m.last_mount)
238-
pr_time(out, le64_to_cpu(m.last_mount));
238+
bch2_prt_datetime(out, le64_to_cpu(m.last_mount));
239239
else
240240
prt_printf(out, "(never)");
241241
prt_newline(out);

fs/bcachefs/super-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
11831183
prt_printf(out, "Created:");
11841184
prt_tab(out);
11851185
if (sb->time_base_lo)
1186-
pr_time(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
1186+
bch2_prt_datetime(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
11871187
else
11881188
prt_printf(out, "(not set)");
11891189
prt_newline(out);

fs/bcachefs/util.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,24 @@ static void bch2_pr_time_units_aligned(struct printbuf *out, u64 ns)
467467
prt_printf(out, "%s", u->name);
468468
}
469469

470+
#ifndef __KERNEL__
471+
#include <time.h>
472+
void bch2_prt_datetime(struct printbuf *out, time64_t sec)
473+
{
474+
time_t t = sec;
475+
char buf[64];
476+
ctime_r(&t, buf);
477+
prt_str(out, buf);
478+
}
479+
#else
480+
void bch2_prt_datetime(struct printbuf *out, time64_t sec)
481+
{
482+
char buf[64];
483+
snprintf(buf, sizeof(buf), "%ptT", &sec);
484+
prt_u64(out, sec);
485+
}
486+
#endif
487+
470488
#define TABSTOP_SIZE 12
471489

472490
static inline void pr_name_and_units(struct printbuf *out, const char *name, u64 ns)

fs/bcachefs/util.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,7 @@ do { \
245245
#define prt_bitflags(...) bch2_prt_bitflags(__VA_ARGS__)
246246

247247
void bch2_pr_time_units(struct printbuf *, u64);
248-
249-
#ifdef __KERNEL__
250-
static inline void pr_time(struct printbuf *out, u64 time)
251-
{
252-
prt_printf(out, "%llu", time);
253-
}
254-
#else
255-
#include <time.h>
256-
static inline void pr_time(struct printbuf *out, u64 _time)
257-
{
258-
char time_str[64];
259-
time_t time = _time;
260-
struct tm *tm = localtime(&time);
261-
size_t err = strftime(time_str, sizeof(time_str), "%c", tm);
262-
if (!err)
263-
prt_printf(out, "(formatting error)");
264-
else
265-
prt_printf(out, "%s", time_str);
266-
}
267-
#endif
248+
void bch2_prt_datetime(struct printbuf *, time64_t);
268249

269250
#ifdef __KERNEL__
270251
static inline void uuid_unparse_lower(u8 *uuid, char *out)

0 commit comments

Comments
 (0)