bcachefs: bch2_prt_datetime()
Improved, better named version of pr_time(). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
bf61dcdfc1
commit
59154f2c66
@ -61,7 +61,6 @@ static void bch2_sb_errors_to_text(struct printbuf *out, struct bch_sb *sb,
|
|||||||
{
|
{
|
||||||
struct bch_sb_field_errors *e = field_to_type(f, errors);
|
struct bch_sb_field_errors *e = field_to_type(f, errors);
|
||||||
unsigned i, nr = bch2_sb_field_errors_nr_entries(e);
|
unsigned i, nr = bch2_sb_field_errors_nr_entries(e);
|
||||||
u64 now = ktime_get_real_seconds();
|
|
||||||
|
|
||||||
if (out->nr_tabstops <= 1)
|
if (out->nr_tabstops <= 1)
|
||||||
printbuf_tabstop_push(out, 16);
|
printbuf_tabstop_push(out, 16);
|
||||||
@ -71,9 +70,7 @@ static void bch2_sb_errors_to_text(struct printbuf *out, struct bch_sb *sb,
|
|||||||
prt_tab(out);
|
prt_tab(out);
|
||||||
prt_u64(out, BCH_SB_ERROR_ENTRY_NR(&e->entries[i]));
|
prt_u64(out, BCH_SB_ERROR_ENTRY_NR(&e->entries[i]));
|
||||||
prt_tab(out);
|
prt_tab(out);
|
||||||
bch2_pr_time_units(out, (now - le64_to_cpu(e->entries[i].last_error_time)) *
|
bch2_prt_datetime(out, le64_to_cpu(e->entries[i].last_error_time));
|
||||||
NSEC_PER_SEC);
|
|
||||||
prt_str(out, " ago");
|
|
||||||
prt_newline(out);
|
prt_newline(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ static void member_to_text(struct printbuf *out,
|
|||||||
prt_printf(out, "Last mount:");
|
prt_printf(out, "Last mount:");
|
||||||
prt_tab(out);
|
prt_tab(out);
|
||||||
if (m.last_mount)
|
if (m.last_mount)
|
||||||
pr_time(out, le64_to_cpu(m.last_mount));
|
bch2_prt_datetime(out, le64_to_cpu(m.last_mount));
|
||||||
else
|
else
|
||||||
prt_printf(out, "(never)");
|
prt_printf(out, "(never)");
|
||||||
prt_newline(out);
|
prt_newline(out);
|
||||||
|
@ -1183,7 +1183,7 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
|
|||||||
prt_printf(out, "Created:");
|
prt_printf(out, "Created:");
|
||||||
prt_tab(out);
|
prt_tab(out);
|
||||||
if (sb->time_base_lo)
|
if (sb->time_base_lo)
|
||||||
pr_time(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
|
bch2_prt_datetime(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
|
||||||
else
|
else
|
||||||
prt_printf(out, "(not set)");
|
prt_printf(out, "(not set)");
|
||||||
prt_newline(out);
|
prt_newline(out);
|
||||||
|
@ -467,6 +467,24 @@ static void bch2_pr_time_units_aligned(struct printbuf *out, u64 ns)
|
|||||||
prt_printf(out, "%s", u->name);
|
prt_printf(out, "%s", u->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __KERNEL__
|
||||||
|
#include <time.h>
|
||||||
|
void bch2_prt_datetime(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_datetime(struct printbuf *out, time64_t sec)
|
||||||
|
{
|
||||||
|
char buf[64];
|
||||||
|
snprintf(buf, sizeof(buf), "%ptT", &sec);
|
||||||
|
prt_u64(out, sec);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TABSTOP_SIZE 12
|
#define TABSTOP_SIZE 12
|
||||||
|
|
||||||
static inline void pr_name_and_units(struct printbuf *out, const char *name, u64 ns)
|
static inline void pr_name_and_units(struct printbuf *out, const char *name, u64 ns)
|
||||||
|
@ -245,26 +245,7 @@ do { \
|
|||||||
#define prt_bitflags(...) bch2_prt_bitflags(__VA_ARGS__)
|
#define prt_bitflags(...) bch2_prt_bitflags(__VA_ARGS__)
|
||||||
|
|
||||||
void bch2_pr_time_units(struct printbuf *, u64);
|
void bch2_pr_time_units(struct printbuf *, u64);
|
||||||
|
void bch2_prt_datetime(struct printbuf *, time64_t);
|
||||||
#ifdef __KERNEL__
|
|
||||||
static inline void pr_time(struct printbuf *out, u64 time)
|
|
||||||
{
|
|
||||||
prt_printf(out, "%llu", time);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <time.h>
|
|
||||||
static inline void pr_time(struct printbuf *out, u64 _time)
|
|
||||||
{
|
|
||||||
char time_str[64];
|
|
||||||
time_t time = _time;
|
|
||||||
struct tm *tm = localtime(&time);
|
|
||||||
size_t err = strftime(time_str, sizeof(time_str), "%c", tm);
|
|
||||||
if (!err)
|
|
||||||
prt_printf(out, "(formatting error)");
|
|
||||||
else
|
|
||||||
prt_printf(out, "%s", time_str);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
static inline void uuid_unparse_lower(u8 *uuid, char *out)
|
static inline void uuid_unparse_lower(u8 *uuid, char *out)
|
||||||
|
Loading…
Reference in New Issue
Block a user