mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-12-24 00:00:04 +03:00
Merge pull request #12 from modelrockettier/real_mount_time
Set the last mount time using the realtime clock
This commit is contained in:
commit
ff2a414ccc
@ -1 +1 @@
|
|||||||
8bf4b038d41230504d3f0315a35e4d7a056e0a65
|
7227ff07f14b424e92b13dd5099aba9ece1ec43c
|
||||||
|
|||||||
@ -138,6 +138,15 @@ static inline u64 ktime_get_seconds(void)
|
|||||||
return ts.tv_sec;
|
return ts.tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline u64 ktime_get_real_seconds(void)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
|
||||||
|
return ts.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct timespec current_kernel_time(void)
|
static inline struct timespec current_kernel_time(void)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
|
|||||||
@ -403,6 +403,7 @@ static void bch2_sb_print_members(struct bch_sb *sb, struct bch_sb_field *f,
|
|||||||
char data_allowed_str[100];
|
char data_allowed_str[100];
|
||||||
char data_has_str[100];
|
char data_has_str[100];
|
||||||
char group[64];
|
char group[64];
|
||||||
|
char time_str[64];
|
||||||
|
|
||||||
if (!bch2_member_exists(m))
|
if (!bch2_member_exists(m))
|
||||||
continue;
|
continue;
|
||||||
@ -435,6 +436,15 @@ static void bch2_sb_print_members(struct bch_sb *sb, struct bch_sb_field *f,
|
|||||||
if (!data_has_str[0])
|
if (!data_has_str[0])
|
||||||
strcpy(data_has_str, "(none)");
|
strcpy(data_has_str, "(none)");
|
||||||
|
|
||||||
|
if (last_mount) {
|
||||||
|
struct tm *tm = localtime(&last_mount);
|
||||||
|
size_t err = strftime(time_str, sizeof(time_str), "%c", tm);
|
||||||
|
if (!err)
|
||||||
|
strcpy(time_str, "(formatting error)");
|
||||||
|
} else {
|
||||||
|
strcpy(time_str, "(never)");
|
||||||
|
}
|
||||||
|
|
||||||
printf(" Device %u:\n"
|
printf(" Device %u:\n"
|
||||||
" UUID: %s\n"
|
" UUID: %s\n"
|
||||||
" Size: %s\n"
|
" Size: %s\n"
|
||||||
@ -456,7 +466,7 @@ static void bch2_sb_print_members(struct bch_sb *sb, struct bch_sb_field *f,
|
|||||||
pr_units(le16_to_cpu(m->bucket_size), units),
|
pr_units(le16_to_cpu(m->bucket_size), units),
|
||||||
le16_to_cpu(m->first_bucket),
|
le16_to_cpu(m->first_bucket),
|
||||||
le64_to_cpu(m->nbuckets),
|
le64_to_cpu(m->nbuckets),
|
||||||
last_mount ? ctime(&last_mount) : "(never)",
|
time_str,
|
||||||
|
|
||||||
BCH_MEMBER_STATE(m) < BCH_MEMBER_STATE_NR
|
BCH_MEMBER_STATE(m) < BCH_MEMBER_STATE_NR
|
||||||
? bch2_dev_state[BCH_MEMBER_STATE(m)]
|
? bch2_dev_state[BCH_MEMBER_STATE(m)]
|
||||||
@ -558,15 +568,26 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
|
|||||||
char user_uuid_str[40], internal_uuid_str[40];
|
char user_uuid_str[40], internal_uuid_str[40];
|
||||||
char fields_have_str[200];
|
char fields_have_str[200];
|
||||||
char label[BCH_SB_LABEL_SIZE + 1];
|
char label[BCH_SB_LABEL_SIZE + 1];
|
||||||
|
char time_str[64];
|
||||||
struct bch_sb_field *f;
|
struct bch_sb_field *f;
|
||||||
u64 fields_have = 0;
|
u64 fields_have = 0;
|
||||||
unsigned nr_devices = 0;
|
unsigned nr_devices = 0;
|
||||||
|
time_t time_base = le64_to_cpu(sb->time_base_lo) / NSEC_PER_SEC;
|
||||||
|
|
||||||
memset(label, 0, sizeof(label));
|
memset(label, 0, sizeof(label));
|
||||||
memcpy(label, sb->label, sizeof(sb->label));
|
memcpy(label, sb->label, sizeof(sb->label));
|
||||||
uuid_unparse(sb->user_uuid.b, user_uuid_str);
|
uuid_unparse(sb->user_uuid.b, user_uuid_str);
|
||||||
uuid_unparse(sb->uuid.b, internal_uuid_str);
|
uuid_unparse(sb->uuid.b, internal_uuid_str);
|
||||||
|
|
||||||
|
if (time_base) {
|
||||||
|
struct tm *tm = localtime(&time_base);
|
||||||
|
size_t err = strftime(time_str, sizeof(time_str), "%c", tm);
|
||||||
|
if (!err)
|
||||||
|
strcpy(time_str, "(formatting error)");
|
||||||
|
} else {
|
||||||
|
strcpy(time_str, "(not set)");
|
||||||
|
}
|
||||||
|
|
||||||
mi = bch2_sb_get_members(sb);
|
mi = bch2_sb_get_members(sb);
|
||||||
if (mi) {
|
if (mi) {
|
||||||
struct bch_member *m;
|
struct bch_member *m;
|
||||||
@ -586,6 +607,7 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
|
|||||||
"Internal UUID: %s\n"
|
"Internal UUID: %s\n"
|
||||||
"Label: %s\n"
|
"Label: %s\n"
|
||||||
"Version: %llu\n"
|
"Version: %llu\n"
|
||||||
|
"Created: %s\n"
|
||||||
"Block_size: %s\n"
|
"Block_size: %s\n"
|
||||||
"Btree node size: %s\n"
|
"Btree node size: %s\n"
|
||||||
"Error action: %s\n"
|
"Error action: %s\n"
|
||||||
@ -614,6 +636,7 @@ void bch2_sb_print(struct bch_sb *sb, bool print_layout,
|
|||||||
internal_uuid_str,
|
internal_uuid_str,
|
||||||
label,
|
label,
|
||||||
le64_to_cpu(sb->version),
|
le64_to_cpu(sb->version),
|
||||||
|
time_str,
|
||||||
pr_units(le16_to_cpu(sb->block_size), units),
|
pr_units(le16_to_cpu(sb->block_size), units),
|
||||||
pr_units(BCH_SB_BTREE_NODE_SIZE(sb), units),
|
pr_units(BCH_SB_BTREE_NODE_SIZE(sb), units),
|
||||||
|
|
||||||
|
|||||||
@ -338,12 +338,17 @@ void bch2_fs_usage_apply(struct bch_fs *c,
|
|||||||
{
|
{
|
||||||
struct fs_usage_sum sum = __fs_usage_sum(*stats);
|
struct fs_usage_sum sum = __fs_usage_sum(*stats);
|
||||||
s64 added = sum.data + sum.reserved;
|
s64 added = sum.data + sum.reserved;
|
||||||
|
s64 should_not_have_added;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Not allowed to reduce sectors_available except by getting a
|
* Not allowed to reduce sectors_available except by getting a
|
||||||
* reservation:
|
* reservation:
|
||||||
*/
|
*/
|
||||||
BUG_ON(added > (s64) (disk_res ? disk_res->sectors : 0));
|
should_not_have_added = added - (s64) (disk_res ? disk_res->sectors : 0);
|
||||||
|
if (WARN_ON(should_not_have_added > 0)) {
|
||||||
|
atomic64_sub(should_not_have_added, &c->sectors_available);
|
||||||
|
added -= should_not_have_added;
|
||||||
|
}
|
||||||
|
|
||||||
if (added > 0) {
|
if (added > 0) {
|
||||||
disk_res->sectors -= added;
|
disk_res->sectors -= added;
|
||||||
@ -661,7 +666,7 @@ static void bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k,
|
|||||||
stats->replicas
|
stats->replicas
|
||||||
[!p.ptr.cached && replicas ? replicas - 1 : 0].data
|
[!p.ptr.cached && replicas ? replicas - 1 : 0].data
|
||||||
[!p.ptr.cached ? data_type : BCH_DATA_CACHED] +=
|
[!p.ptr.cached ? data_type : BCH_DATA_CACHED] +=
|
||||||
sectors;
|
disk_sectors;
|
||||||
|
|
||||||
bch2_mark_pointer(c, e, p, disk_sectors, data_type,
|
bch2_mark_pointer(c, e, p, disk_sectors, data_type,
|
||||||
stats, journal_seq, flags);
|
stats, journal_seq, flags);
|
||||||
|
|||||||
@ -235,7 +235,7 @@ unsigned bch2_extent_is_compressed(struct bkey_s_c k)
|
|||||||
if (!p.ptr.cached &&
|
if (!p.ptr.cached &&
|
||||||
p.crc.compression_type != BCH_COMPRESSION_NONE &&
|
p.crc.compression_type != BCH_COMPRESSION_NONE &&
|
||||||
p.crc.compressed_size < p.crc.live_size)
|
p.crc.compressed_size < p.crc.live_size)
|
||||||
ret = max_t(unsigned, ret, p.crc.compressed_size);
|
ret += p.crc.compressed_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1275,8 +1275,7 @@ bch2_extent_can_insert(struct btree_insert *trans,
|
|||||||
|
|
||||||
switch (bch2_disk_reservation_add(trans->c,
|
switch (bch2_disk_reservation_add(trans->c,
|
||||||
trans->disk_res,
|
trans->disk_res,
|
||||||
sectors * bch2_extent_nr_dirty_ptrs(k),
|
sectors, flags)) {
|
||||||
flags)) {
|
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case -ENOSPC:
|
case -ENOSPC:
|
||||||
|
|||||||
@ -12,7 +12,9 @@ struct { \
|
|||||||
#define DECLARE_FIFO(type, name) FIFO(type) name
|
#define DECLARE_FIFO(type, name) FIFO(type) name
|
||||||
|
|
||||||
#define fifo_buf_size(fifo) \
|
#define fifo_buf_size(fifo) \
|
||||||
(roundup_pow_of_two((fifo)->size) * sizeof((fifo)->data[0]))
|
((fifo)->size \
|
||||||
|
? roundup_pow_of_two((fifo)->size) * sizeof((fifo)->data[0]) \
|
||||||
|
: 0)
|
||||||
|
|
||||||
#define init_fifo(fifo, _size, _gfp) \
|
#define init_fifo(fifo, _size, _gfp) \
|
||||||
({ \
|
({ \
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "btree_gc.h"
|
#include "btree_gc.h"
|
||||||
#include "btree_update.h"
|
#include "btree_update.h"
|
||||||
#include "buckets.h"
|
#include "buckets.h"
|
||||||
|
#include "disk_groups.h"
|
||||||
#include "inode.h"
|
#include "inode.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "journal_reclaim.h"
|
#include "journal_reclaim.h"
|
||||||
@ -260,8 +261,26 @@ int bch2_migrate_write_init(struct bch_fs *c, struct migrate_write *m,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DATA_REWRITE:
|
case DATA_REWRITE: {
|
||||||
|
const union bch_extent_entry *entry;
|
||||||
|
struct extent_ptr_decoded p;
|
||||||
|
unsigned compressed_sectors = 0;
|
||||||
|
|
||||||
|
extent_for_each_ptr_decode(bkey_s_c_to_extent(k), p, entry)
|
||||||
|
if (!p.ptr.cached &&
|
||||||
|
p.crc.compression_type != BCH_COMPRESSION_NONE &&
|
||||||
|
bch2_dev_in_target(c, p.ptr.dev, data_opts.target))
|
||||||
|
compressed_sectors += p.crc.compressed_size;
|
||||||
|
|
||||||
|
if (compressed_sectors) {
|
||||||
|
ret = bch2_disk_reservation_add(c, &m->op.res,
|
||||||
|
compressed_sectors,
|
||||||
|
BCH_DISK_RESERVATION_NOFAIL);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DATA_PROMOTE:
|
case DATA_PROMOTE:
|
||||||
m->op.flags |= BCH_WRITE_ALLOC_NOWAIT;
|
m->op.flags |= BCH_WRITE_ALLOC_NOWAIT;
|
||||||
m->op.flags |= BCH_WRITE_CACHED;
|
m->op.flags |= BCH_WRITE_CACHED;
|
||||||
|
|||||||
@ -686,7 +686,7 @@ const char *bch2_fs_start(struct bch_fs *c)
|
|||||||
const char *err = "cannot allocate memory";
|
const char *err = "cannot allocate memory";
|
||||||
struct bch_sb_field_members *mi;
|
struct bch_sb_field_members *mi;
|
||||||
struct bch_dev *ca;
|
struct bch_dev *ca;
|
||||||
time64_t now = ktime_get_seconds();
|
time64_t now = ktime_get_real_seconds();
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
@ -1456,7 +1456,7 @@ have_slot:
|
|||||||
/* success: */
|
/* success: */
|
||||||
|
|
||||||
mi->members[dev_idx] = dev_mi;
|
mi->members[dev_idx] = dev_mi;
|
||||||
mi->members[dev_idx].last_mount = cpu_to_le64(ktime_get_seconds());
|
mi->members[dev_idx].last_mount = cpu_to_le64(ktime_get_real_seconds());
|
||||||
c->disk_sb.sb->nr_devices = nr_devices;
|
c->disk_sb.sb->nr_devices = nr_devices;
|
||||||
|
|
||||||
ca->disk_sb.sb->dev_idx = dev_idx;
|
ca->disk_sb.sb->dev_idx = dev_idx;
|
||||||
@ -1532,7 +1532,7 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
|
|||||||
mi = bch2_sb_get_members(c->disk_sb.sb);
|
mi = bch2_sb_get_members(c->disk_sb.sb);
|
||||||
|
|
||||||
mi->members[ca->dev_idx].last_mount =
|
mi->members[ca->dev_idx].last_mount =
|
||||||
cpu_to_le64(ktime_get_seconds());
|
cpu_to_le64(ktime_get_real_seconds());
|
||||||
|
|
||||||
bch2_write_super(c);
|
bch2_write_super(c);
|
||||||
mutex_unlock(&c->sb_lock);
|
mutex_unlock(&c->sb_lock);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user