Hello community, here is the log from the commit of package bcache-tools for openSUSE:Factory checked in at 2013-08-12 10:15:49 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/bcache-tools (Old) and /work/SRC/openSUSE:Factory/.bcache-tools.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "bcache-tools" Changes: -------- --- /work/SRC/openSUSE:Factory/bcache-tools/bcache-tools.changes 2013-07-02 06:44:08.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.bcache-tools.new/bcache-tools.changes 2013-08-12 10:15:51.000000000 +0200 @@ -1,0 +2,6 @@ +Wed Aug 7 22:02:31 UTC 2013 - jeng...@inai.de + +- Update to new snapshot 0.1.g71 +* Support for superblocks up to version 4 + +------------------------------------------------------------------- Old: ---- bcache-tools-0.1.g45.tar.xz New: ---- bcache-tools-0.1.g71.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ bcache-tools.spec ++++++ --- /var/tmp/diff_new_pack.gXTj4x/_old 2013-08-12 10:15:52.000000000 +0200 +++ /var/tmp/diff_new_pack.gXTj4x/_new 2013-08-12 10:15:52.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package bcache-tools # -# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -15,19 +15,22 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # + Name: bcache-tools Summary: Configuration utilities for bcache -Version: 0.1.g45 -#Snapshot: 42c182c6ab1530b5e3b18893f284da3eaec46e74 -Release: 0 -Group: System/Base License: GPL-2.0 +Group: System/Base +Version: 0.1.g71 +Release: 0 +#Snapshot: 0b57e166ae86d525ef42842cabf7692fc7c44039 Url: http://bcache.evilpiepirate.org/ #Git-Clone: http://evilpiepirate.org/git/bcache-tools.git Source: %name-%version.tar.xz BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildRequires: openssl-devel libuuid-devel xz +BuildRequires: libuuid-devel +BuildRequires: openssl-devel +BuildRequires: xz %description This package contains utilities for configuring the bcache Module. @@ -46,16 +49,16 @@ mkdir -p "$b/%_sysconfdir/initramfs-tools/hooks" make install DESTDIR="$b" rm -Rf "$b/%_sysconfdir/initramfs-tools" -mkdir -p "$b/%_prefix/lib/udev/rules.d" -mv "$b/lib/udev/rules.d"/* "$b/%_prefix/lib/udev/rules.d/" +mkdir -p "$b/%_prefix/lib" +mv "$b/lib/udev" "$b/%_prefix/lib/" %files %defattr(-,root,root) +%_sbindir/bcache-super-show %_sbindir/make-bcache /sbin/probe-bcache -%dir %_prefix/lib/udev -%dir %_prefix/lib/udev/rules.d -%_prefix/lib/udev/rules.d/61-bcache.rules +%_prefix/lib/udev %_mandir/man8/*.8* +%doc COPYING %changelog ++++++ bcache-tools-0.1.g45.tar.xz -> bcache-tools-0.1.g71.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/.gitignore new/bcache-tools/.gitignore --- old/bcache-tools/.gitignore 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/.gitignore 2013-08-08 00:00:49.000000000 +0200 @@ -1,3 +1,4 @@ +bcache-super-show make-bcache probe-bcache .* diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/61-bcache.rules new/bcache-tools/61-bcache.rules --- old/bcache-tools/61-bcache.rules 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/61-bcache.rules 2013-08-08 00:00:49.000000000 +0200 @@ -1,3 +1,25 @@ -KERNEL=="sd*", ENV{DEVTYPE}=="disk", IMPORT{program}="/sbin/probe-bcache -o udev $tempnode" +# register bcache devices as they come up +# man 7 udev for syntax +SUBSYSTEM!="block", GOTO="bcache_end" +ACTION=="remove", GOTO="bcache_end" + +# Backing devices: scan, symlink, register +IMPORT{program}="/sbin/blkid -o udev $tempnode" +# blkid and probe-bcache can disagree, in which case don't register +ENV{ID_FS_TYPE}=="?*", ENV{ID_FS_TYPE}!="bcache", GOTO="bcache_backing_end" + +IMPORT{program}="/sbin/probe-bcache -o udev $tempnode" ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" +SUBSYSTEM=="block", ACTION=="add|change", ENV{ID_FS_TYPE}=="bcache", \ + RUN+="bcache-register $tempnode" +LABEL="bcache_backing_end" + +# Cached devices: symlink +DRIVER=="bcache", ENV{CACHED_UUID}=="?*", \ + SYMLINK+="bcache/by-uuid/$env{CACHED_UUID}" +DRIVER=="bcache", ENV{CACHED_LABEL}=="?*", \ + SYMLINK+="bcache/by-label/$env{CACHED_LABEL}" + +LABEL="bcache_end" + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/COPYING new/bcache-tools/COPYING --- old/bcache-tools/COPYING 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/COPYING 2013-08-08 00:00:49.000000000 +0200 @@ -1,4 +1,3 @@ - GNU GENERAL PUBLIC LICENSE Version 2, June 1991 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/Makefile new/bcache-tools/Makefile --- old/bcache-tools/Makefile 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/Makefile 2013-08-08 00:00:49.000000000 +0200 @@ -2,21 +2,23 @@ PREFIX=/usr CFLAGS+=-O2 -Wall -g -all: make-bcache probe-bcache +all: make-bcache probe-bcache bcache-super-show -install: make-bcache probe-bcache - install -m0755 make-bcache $(DESTDIR)${PREFIX}/sbin/ +install: make-bcache probe-bcache bcache-super-show + install -m0755 make-bcache bcache-super-show $(DESTDIR)${PREFIX}/sbin/ install -m0755 probe-bcache $(DESTDIR)/sbin/ install -m0644 61-bcache.rules $(DESTDIR)/lib/udev/rules.d/ - -install -m0755 initramfs/script $(DESTDIR)/etc/initramfs-tools/scripts/init-premount/bcache + install -m0755 bcache-register $(DESTDIR)/lib/udev/ -install -m0755 initramfs/hook $(DESTDIR)/etc/initramfs-tools/hooks/bcache - install -m0644 *.8 $(DESTDIR)${PREFIX}/share/man/man8 + install -m0644 -- *.8 $(DESTDIR)${PREFIX}/share/man/man8 # install -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ clean: - $(RM) -f make-bcache probe-bcache bcache-test *.o + $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test *.o bcache-test: LDLIBS += -lm -lssl -lcrypto make-bcache: LDLIBS += -luuid make-bcache: bcache.o probe-bcache: LDLIBS += -luuid +bcache-super-show: LDLIBS += -luuid +bcache-super-show: bcache.o diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/README new/bcache-tools/README --- old/bcache-tools/README 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/README 2013-08-08 00:00:49.000000000 +0200 @@ -22,3 +22,6 @@ in blkid; in the meantime, provides just enough functionality for a udev script to create the /dev/disk/by-uuid symlink. The arguments it does support are the same as for blkid. + +bcache-super-show +Prints the bcache superblock of a cache device or a backing device. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/bcache-register new/bcache-tools/bcache-register --- old/bcache-tools/bcache-register 1970-01-01 01:00:00.000000000 +0100 +++ new/bcache-tools/bcache-register 2013-08-08 00:00:49.000000000 +0200 @@ -0,0 +1,4 @@ +#!/bin/sh +modprobe -qba bcache +test -f /sys/fs/bcache/register && echo "$1" > /sys/fs/bcache/register + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/bcache-super-show.8 new/bcache-tools/bcache-super-show.8 --- old/bcache-tools/bcache-super-show.8 1970-01-01 01:00:00.000000000 +0100 +++ new/bcache-tools/bcache-super-show.8 2013-08-08 00:00:49.000000000 +0200 @@ -0,0 +1,11 @@ +.TH bcache-super-show 8 +.SH NAME +bcache-super-show \- Print the bcache superblock +.SH SYNOPSIS +.B bcache-super-show +[\fB \-f] +.I device +.SH OPTIONS +.TP +.BR \-f +Keep going if the superblock crc is invalid diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/bcache-super-show.c new/bcache-tools/bcache-super-show.c --- old/bcache-tools/bcache-super-show.c 1970-01-01 01:00:00.000000000 +0100 +++ new/bcache-tools/bcache-super-show.c 2013-08-08 00:00:49.000000000 +0200 @@ -0,0 +1,205 @@ +/* + * Author: Gabriel de Perthuis <g2p.c...@gmail.com> + * + * GPLv2 + */ + +#define _FILE_OFFSET_BITS 64 +#define __USE_FILE_OFFSET64 +#define _XOPEN_SOURCE 500 + +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <linux/fs.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <uuid/uuid.h> + +#include "bcache.h" + + +static void usage() +{ + fprintf(stderr, "Usage: bcache-super-show [-f] <device>\n"); +} + + +int main(int argc, char **argv) +{ + bool force_csum = false; + int o; + extern char *optarg; + struct cache_sb sb; + char uuid[40]; + uint64_t expected_csum; + + while ((o = getopt(argc, argv, "f")) != EOF) + switch (o) { + case 'f': + force_csum = 1; + break; + + default: + usage(); + exit(1); + } + + argv += optind; + argc -= optind; + + if (argc != 1) { + usage(); + exit(1); + } + + int fd = open(argv[0], O_RDONLY); + if (fd < 0) { + printf("Can't open dev %s: %s\n", argv[0], strerror(errno)); + exit(2); + } + + if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) { + fprintf(stderr, "Couldn't read\n"); + exit(2); + } + + printf("sb.magic\t\t"); + if (!memcmp(sb.magic, bcache_magic, 16)) { + printf("ok\n"); + } else { + printf("bad magic\n"); + fprintf(stderr, "Invalid superblock (bad magic)\n"); + exit(2); + } + + printf("sb.first_sector\t\t%" PRIu64, sb.offset); + if (sb.offset == SB_SECTOR) { + printf(" [match]\n"); + } else { + printf(" [expected %ds]\n", SB_SECTOR); + fprintf(stderr, "Invalid superblock (bad sector)\n"); + exit(2); + } + + printf("sb.csum\t\t\t%" PRIX64, sb.csum); + expected_csum = csum_set(&sb); + if (sb.csum == expected_csum) { + printf(" [match]\n"); + } else { + printf(" [expected %" PRIX64 "]\n", expected_csum); + if (!force_csum) { + fprintf(stderr, "Corrupt superblock (bad csum)\n"); + exit(2); + } + } + + printf("sb.version\t\t%" PRIu64, sb.version); + switch (sb.version) { + // These are handled the same by the kernel + case BCACHE_SB_VERSION_CDEV: + case BCACHE_SB_VERSION_CDEV_WITH_UUID: + printf(" [cache device]\n"); + break; + + // The second adds data offset support + case BCACHE_SB_VERSION_BDEV: + case BCACHE_SB_VERSION_BDEV_WITH_OFFSET: + printf(" [backing device]\n"); + break; + + default: + printf(" [unknown]\n"); + // exit code? + return 0; + } + + putchar('\n'); + + uuid_unparse(sb.uuid, uuid); + printf("dev.uuid\t\t%s\n", uuid); + + printf("dev.sectors_per_block\t%u\n" + "dev.sectors_per_bucket\t%u\n", + sb.block_size, + sb.bucket_size); + + if (!SB_IS_BDEV(&sb)) { + // total_sectors includes the superblock; + printf("dev.cache.first_sector\t%u\n" + "dev.cache.cache_sectors\t%ju\n" + "dev.cache.total_sectors\t%ju\n" + "dev.cache.discard\t%s\n" + "dev.cache.pos\t\t%u\n", + sb.bucket_size * sb.first_bucket, + sb.bucket_size * (sb.nbuckets - sb.first_bucket), + sb.bucket_size * sb.nbuckets, + CACHE_DISCARD(&sb) ? "yes" : "no", + sb.nr_this_dev); + } else { + uint64_t first_sector; + if (sb.version == BCACHE_SB_VERSION_BDEV) { + first_sector = BDEV_DATA_START_DEFAULT; + } else { + if (sb.keys == 1 || sb.d[0]) { + fprintf(stderr, + "Possible experimental format detected, bailing\n"); + exit(3); + } + first_sector = sb.data_offset; + } + + printf("dev.data.first_sector\t%ju\n" + "dev.data.cache_mode\t%ju", + first_sector, + BDEV_CACHE_MODE(&sb)); + switch (BDEV_CACHE_MODE(&sb)) { + case CACHE_MODE_WRITETHROUGH: + printf(" [writethrough]\n"); + break; + case CACHE_MODE_WRITEBACK: + printf(" [writeback]\n"); + break; + case CACHE_MODE_WRITEAROUND: + printf(" [writearound]\n"); + break; + case CACHE_MODE_NONE: + printf(" [no caching]\n"); + break; + default: + putchar('\n'); + } + + printf("dev.data.cache_state\t%ju", + BDEV_STATE(&sb)); + switch (BDEV_STATE(&sb)) { + case BDEV_STATE_NONE: + printf(" [detached]\n"); + break; + case BDEV_STATE_CLEAN: + printf(" [clean]\n"); + break; + case BDEV_STATE_DIRTY: + printf(" [dirty]\n"); + break; + case BDEV_STATE_STALE: + printf(" [inconsistent]\n"); + break; + default: + putchar('\n'); + } + } + putchar('\n'); + + uuid_unparse(sb.set_uuid, uuid); + printf("cset.uuid\t\t%s\n", uuid); + + return 0; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/bcache-test.c new/bcache-tools/bcache-test.c --- old/bcache-tools/bcache-test.c 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/bcache-test.c 2013-08-08 00:00:49.000000000 +0200 @@ -1,3 +1,9 @@ +/* + * Author: Kent Overstreet <k...@daterainc.com> + * + * GPLv2 + */ + #define _FILE_OFFSET_BITS 64 #define _XOPEN_SOURCE 500 #define _GNU_SOURCE diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/bcache.h new/bcache-tools/bcache.h --- old/bcache-tools/bcache.h 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/bcache.h 2013-08-08 00:00:49.000000000 +0200 @@ -1,3 +1,9 @@ +/* + * Author: Kent Overstreet <k...@daterainc.com> + * + * GPLv2 + */ + #ifndef _BCACHE_H #define _BCACHE_H @@ -15,22 +21,29 @@ 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 }; -/* Version 1: Backing dev +/* + * Version 0: Cache device + * Version 1: Backing device * Version 2: Seed pointer into btree node checksum - * Version 3: Backing dev superblock has offset of start of data + * Version 3: Cache device with new UUID format + * Version 4: Backing device with data offset */ - -#define BCACHE_SB_BDEV_VERSION 3 -#define BCACHE_SB_MAX_VERSION 3 +#define BCACHE_SB_VERSION_CDEV 0 +#define BCACHE_SB_VERSION_BDEV 1 +#define BCACHE_SB_VERSION_CDEV_WITH_UUID 3 +#define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4 +#define BCACHE_SB_MAX_VERSION 4 #define SB_SECTOR 8 #define SB_LABEL_SIZE 32 +#define SB_JOURNAL_BUCKETS 256U +#define BDEV_DATA_START_DEFAULT 16 /* sectors */ +#define SB_START (SB_SECTOR * 512) struct cache_sb { uint64_t csum; uint64_t offset; /* sector where this sb was written */ uint64_t version; -#define CACHE_BACKING_DEV 1 uint8_t magic[16]; @@ -45,26 +58,62 @@ uint64_t seq; uint64_t pad[8]; - uint64_t nbuckets; /* device size */ - uint16_t block_size; /* sectors */ - uint16_t bucket_size; /* sectors */ + union { + struct { + /* Cache devices */ + uint64_t nbuckets; /* device size */ + + uint16_t block_size; /* sectors */ + uint16_t bucket_size; /* sectors */ - uint16_t nr_in_set; - uint16_t nr_this_dev; + uint16_t nr_in_set; + uint16_t nr_this_dev; + }; + struct { + /* Backing devices */ + uint64_t data_offset; + + /* + * block_size from the cache device section is still used by + * backing devices, so don't add anything here until we fix + * things to not need it for backing devices anymore + */ + }; + }; uint32_t last_mount; /* time_t */ uint16_t first_bucket; - uint16_t keys; /* number of journal buckets */ - uint64_t d[]; /* journal buckets */ + union { + uint16_t njournal_buckets; + uint16_t keys; + }; + uint64_t d[SB_JOURNAL_BUCKETS]; /* journal buckets */ }; -BITMASK(SB_BDEV, struct cache_sb, version, 0, 1); - -BITMASK(BDEV_WRITEBACK, struct cache_sb, flags, 0, 1); +static inline bool SB_IS_BDEV(const struct cache_sb *sb) +{ + return sb->version == BCACHE_SB_VERSION_BDEV + || sb->version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET; +} -BITMASK(CACHE_DISCARD, struct cache_sb, flags, 1, 1); -BITMASK(CACHE_REPLACEMENT, struct cache_sb, flags, 2, 3); +BITMASK(CACHE_SYNC, struct cache_sb, flags, 0, 1); +BITMASK(CACHE_DISCARD, struct cache_sb, flags, 1, 1); +BITMASK(CACHE_REPLACEMENT, struct cache_sb, flags, 2, 3); +#define CACHE_REPLACEMENT_LRU 0U +#define CACHE_REPLACEMENT_FIFO 1U +#define CACHE_REPLACEMENT_RANDOM 2U + +BITMASK(BDEV_CACHE_MODE, struct cache_sb, flags, 0, 4); +#define CACHE_MODE_WRITETHROUGH 0U +#define CACHE_MODE_WRITEBACK 1U +#define CACHE_MODE_WRITEAROUND 2U +#define CACHE_MODE_NONE 3U +BITMASK(BDEV_STATE, struct cache_sb, flags, 61, 2); +#define BDEV_STATE_NONE 0U +#define BDEV_STATE_CLEAN 1U +#define BDEV_STATE_DIRTY 2U +#define BDEV_STATE_STALE 3U inline uint64_t crc64(const void *_data, size_t len); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/initramfs/hook new/bcache-tools/initramfs/hook --- old/bcache-tools/initramfs/hook 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/initramfs/hook 2013-08-08 00:00:49.000000000 +0200 @@ -16,5 +16,7 @@ . /usr/share/initramfs-tools/hook-functions -copy_exec /bin/mknod +cp -pt "${DESTDIR}/lib/udev/rules.d" /lib/udev/rules.d/61-bcache.rules +copy_exec /lib/udev/bcache-register +copy_exec /sbin/probe-bcache manual_add_modules bcache diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/initramfs/script new/bcache-tools/initramfs/script --- old/bcache-tools/initramfs/script 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/initramfs/script 1970-01-01 01:00:00.000000000 +0100 @@ -1,32 +0,0 @@ -#!/bin/sh - -mountroot_fail() -{ - for i in `ls /dev/sd*`; do - echo $i > /sys/fs/bcache/register_quiet - done - -# for i in `ls /sys/dev/block/`; do -# DEV=/bcache_dev -# -# mknod $DEV b `echo $i|sed -e 's/:/ /'` -# echo $DEV > /sys/fs/bcache/register_quiet -# rm $DEV -# done -} - -case $1 in -prereqs) - exit 0 - ;; -mountfail) - mountroot_fail - exit 0 - ;; -esac - -. /scripts/functions - -add_mountroot_fail_hook "30-bcache" - -exit 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/make-bcache.c new/bcache-tools/make-bcache.c --- old/bcache-tools/make-bcache.c 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/make-bcache.c 2013-08-08 00:00:49.000000000 +0200 @@ -1,3 +1,9 @@ +/* + * Author: Kent Overstreet <k...@daterainc.com> + * + * GPLv2 + */ + #define _FILE_OFFSET_BITS 64 #define __USE_FILE_OFFSET64 #define _XOPEN_SOURCE 600 @@ -21,6 +27,12 @@ #include "bcache.h" +#define max(x, y) ({ \ + typeof(x) _max1 = (x); \ + typeof(y) _max2 = (y); \ + (void) (&_max1 == &_max2); \ + _max1 > _max2 ? _max1 : _max2; }) + uint64_t getblocks(int fd) { uint64_t ret; @@ -136,7 +148,9 @@ " -B, --bdev Format a backing device\n" " -b, --bucket bucket size\n" " -w, --block block size (hard sector size of SSD, often 2k)\n" - " -U UUID\n" + " -o, --data-offset data offset in sectors\n" + " --cset-uuid UUID for the cache set\n" +// " -U UUID\n" " --writeback enable writeback\n" " --discard enable discards\n" " --cache_replacement_policy=(lru|fifo)\n" @@ -151,145 +165,212 @@ NULL }; -int writeback; -int discard; -unsigned cache_replacement_policy; -uint64_t data_offset = 16; - -struct option opts[] = { - { "cache", 0, NULL, 'C' }, - { "bdev", 0, NULL, 'B' }, - { "bucket", 1, NULL, 'b' }, - { "block", 1, NULL, 'w' }, - { "writeback", 0, &writeback, 1 }, - { "discard", 0, &discard, 1 }, - { "cache_replacement_policy", 1, NULL, 'p' }, -// { "data_offset", 1, NULL, 'o' }, - { "help", 0, NULL, 'h' }, - { NULL, 0, NULL, 0 }, -}; - -void write_sb(char *dev, struct cache_sb *sb) +static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, + bool writeback, bool discard, + unsigned cache_replacement_policy, + uint64_t data_offset, + uuid_t set_uuid, bool bdev) { int fd; - char uuid[40], set_uuid[40]; - - if (sb->version > BCACHE_SB_MAX_VERSION) { - printf("Must specify one of -C or -B\n"); - usage(); - } - - if (sb->bucket_size < sb->block_size) { - printf("Bucket size cannot be smaller than block size\n"); - exit(EXIT_FAILURE); - } + char uuid_str[40], set_uuid_str[40]; + struct cache_sb sb; if ((fd = open(dev, O_RDWR|O_EXCL)) == -1) { printf("Can't open dev %s: %s\n", dev, strerror(errno)); exit(EXIT_FAILURE); } - sb->flags = 0; + memset(&sb, 0, sizeof(struct cache_sb)); + + sb.offset = SB_SECTOR; + sb.version = bdev + ? BCACHE_SB_VERSION_BDEV + : BCACHE_SB_VERSION_CDEV; - if (SB_BDEV(sb)) { - SET_BDEV_WRITEBACK(sb, writeback); + memcpy(sb.magic, bcache_magic, 16); + uuid_generate(sb.uuid); + memcpy(sb.set_uuid, set_uuid, sizeof(sb.set_uuid)); + + sb.bucket_size = bucket_size; + sb.block_size = block_size; + + uuid_unparse(sb.uuid, uuid_str); + uuid_unparse(sb.set_uuid, set_uuid_str); + + if (SB_IS_BDEV(&sb)) { + SET_BDEV_CACHE_MODE( + &sb, writeback ? CACHE_MODE_WRITEBACK : CACHE_MODE_WRITETHROUGH); - if (data_offset != 16) { - sb->version = BCACHE_SB_BDEV_VERSION; - sb->keys = 1; - sb->d[0] = data_offset; + if (data_offset != BDEV_DATA_START_DEFAULT) { + sb.version = BCACHE_SB_VERSION_BDEV_WITH_OFFSET; + sb.data_offset = data_offset; } + + printf("UUID: %s\n" + "Set UUID: %s\n" + "version: %u\n" + "block_size: %u\n" + "data_offset: %ju\n", + uuid_str, set_uuid_str, + (unsigned) sb.version, + sb.block_size, + data_offset); } else { - SET_CACHE_DISCARD(sb, discard); - SET_CACHE_REPLACEMENT(sb, cache_replacement_policy); - } + sb.nbuckets = getblocks(fd) / sb.bucket_size; + sb.nr_in_set = 1; + sb.first_bucket = (23 / sb.bucket_size) + 1; + + if (sb.nbuckets < 1 << 7) { + printf("Not enough buckets: %ju, need %u\n", + sb.nbuckets, 1 << 7); + exit(EXIT_FAILURE); + } - sb->offset = SB_SECTOR; - memcpy(sb->magic, bcache_magic, 16); - sb->nbuckets = getblocks(fd) / sb->bucket_size; - sb->nr_in_set = 1; - sb->first_bucket = (23 / sb->bucket_size) + 1; - uuid_unparse(sb->uuid, uuid); - uuid_unparse(sb->set_uuid, set_uuid); - sb->csum = csum_set(sb); - - if (sb->nbuckets < 1 << 7) { - printf("Not enough buckets: %ju, need %u\n", - sb->nbuckets, 1 << 7); - exit(EXIT_FAILURE); + SET_CACHE_DISCARD(&sb, discard); + SET_CACHE_REPLACEMENT(&sb, cache_replacement_policy); + + printf("UUID: %s\n" + "Set UUID: %s\n" + "version: %u\n" + "nbuckets: %ju\n" + "block_size: %u\n" + "bucket_size: %u\n" + "nr_in_set: %u\n" + "nr_this_dev: %u\n" + "first_bucket: %u\n", + uuid_str, set_uuid_str, + (unsigned) sb.version, + sb.nbuckets, + sb.block_size, + sb.bucket_size, + sb.nr_in_set, + sb.nr_this_dev, + sb.first_bucket); } - printf("UUID: %s\n" - "Set UUID: %s\n" - "nbuckets: %ju\n" - "block_size: %u\n" - "bucket_size: %u\n" - "nr_in_set: %u\n" - "nr_this_dev: %u\n" - "first_bucket: %u\n", - uuid, set_uuid, - sb->nbuckets, - sb->block_size, - sb->bucket_size, - sb->nr_in_set, - sb->nr_this_dev, - sb->first_bucket); + sb.csum = csum_set(&sb); - if (pwrite(fd, sb, sizeof(*sb), SB_SECTOR << 9) != sizeof(*sb)) { + if (pwrite(fd, &sb, sizeof(sb), SB_SECTOR << 9) != sizeof(sb)) { perror("write error\n"); exit(EXIT_FAILURE); } fsync(fd); close(fd); - - uuid_generate(sb->uuid); } -int main(int argc, char **argv) +static unsigned get_blocksize(const char *path) { - bool written = false; - int c; - struct cache_sb sb; + struct stat statbuf; - memset(&sb, 0, sizeof(struct cache_sb)); - sb.version = -1; - sb.block_size = 1; - sb.bucket_size = 1024; + if (stat(path, &statbuf)) { + fprintf(stderr, "Error statting %s: %s\n", + path, strerror(errno)); + exit(EXIT_FAILURE); + } - uuid_generate(sb.uuid); - uuid_generate(sb.set_uuid); + if (S_ISBLK(statbuf.st_mode)) { + /* check IO limits: + * BLKALIGNOFF: alignment_offset + * BLKPBSZGET: physical_block_size + * BLKSSZGET: logical_block_size + * BLKIOMIN: minimum_io_size + * BLKIOOPT: optimal_io_size + * + * It may be tempting to use physical_block_size, + * or even minimum_io_size. + * But to be as transparent as possible, + * we want to use logical_block_size. + */ + unsigned int logical_block_size; + int fd = open(path, O_RDONLY); + + if (fd < 0) { + fprintf(stderr, "open(%s) failed: %m\n", path); + exit(EXIT_FAILURE); + } + if (ioctl(fd, BLKSSZGET, &logical_block_size)) { + fprintf(stderr, "ioctl(%s, BLKSSZGET) failed: %m\n", path); + exit(EXIT_FAILURE); + } + close(fd); + return logical_block_size / 512; + + } + /* else: not a block device. + * Why would we even want to write a bcache super block there? */ + + return statbuf.st_blksize / 512; +} + +int main(int argc, char **argv) +{ + int c, bdev = -1; + unsigned i, ncache_devices = 0, nbacking_devices = 0; + char *cache_devices[argc]; + char *backing_devices[argc]; + + unsigned block_size = 0, bucket_size = 1024; + int writeback = 0, discard = 0; + unsigned cache_replacement_policy = 0; + uint64_t data_offset = BDEV_DATA_START_DEFAULT; + uuid_t set_uuid; + + uuid_generate(set_uuid); + + struct option opts[] = { + { "cache", 0, NULL, 'C' }, + { "bdev", 0, NULL, 'B' }, + { "bucket", 1, NULL, 'b' }, + { "block", 1, NULL, 'w' }, + { "writeback", 0, &writeback, 1 }, + { "discard", 0, &discard, 1 }, + { "cache_replacement_policy", 1, NULL, 'p' }, + { "data_offset", 1, NULL, 'o' }, + { "cset-uuid", 1, NULL, 'u' }, + { "help", 0, NULL, 'h' }, + { NULL, 0, NULL, 0 }, + }; while ((c = getopt_long(argc, argv, "-hCBU:w:b:", opts, NULL)) != -1) switch (c) { case 'C': - sb.version = 0; + bdev = 0; break; case 'B': - sb.version = CACHE_BACKING_DEV; + bdev = 1; break; case 'b': - sb.bucket_size = hatoi_validate(optarg, "bucket size"); + bucket_size = hatoi_validate(optarg, "bucket size"); break; case 'w': - sb.block_size = hatoi_validate(optarg, "block size"); + block_size = hatoi_validate(optarg, "block size"); break; +#if 0 case 'U': if (uuid_parse(optarg, sb.uuid)) { printf("Bad uuid\n"); exit(EXIT_FAILURE); } break; +#endif case 'p': cache_replacement_policy = read_string_list(optarg, cache_replacement_policies); break; case 'o': data_offset = atoll(optarg); - if (sb.d[0] < 16) { - printf("Bad data offset; minimum 16 sectors\n"); + if (data_offset < BDEV_DATA_START_DEFAULT) { + printf("Bad data offset; minimum %d sectors\n", + BDEV_DATA_START_DEFAULT); + exit(EXIT_FAILURE); + } + break; + case 'u': + if (uuid_parse(optarg, set_uuid)) { + printf("Bad uuid\n"); exit(EXIT_FAILURE); } break; @@ -297,15 +378,47 @@ usage(); break; case 1: - write_sb(optarg, &sb); - written = true; + if (bdev == -1) { + printf("Please specify -C or -B\n"); + exit(EXIT_FAILURE); + } + + if (bdev) + backing_devices[nbacking_devices++] = optarg; + else + cache_devices[ncache_devices++] = optarg; break; } - if (!written) { + if (!ncache_devices && !nbacking_devices) { printf("Please supply a device\n"); usage(); } + if (bucket_size < block_size) { + printf("Bucket size cannot be smaller than block size\n"); + exit(EXIT_FAILURE); + } + + if (!block_size) { + for (i = 0; i < ncache_devices; i++) + block_size = max(block_size, + get_blocksize(cache_devices[i])); + + for (i = 0; i < nbacking_devices; i++) + block_size = max(block_size, + get_blocksize(backing_devices[i])); + } + + for (i = 0; i < ncache_devices; i++) + write_sb(cache_devices[i], block_size, bucket_size, + writeback, discard, cache_replacement_policy, + data_offset, set_uuid, false); + + for (i = 0; i < nbacking_devices; i++) + write_sb(backing_devices[i], block_size, bucket_size, + writeback, discard, cache_replacement_policy, + data_offset, set_uuid, true); + return 0; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcache-tools/probe-bcache.c new/bcache-tools/probe-bcache.c --- old/bcache-tools/probe-bcache.c 2013-03-22 13:11:31.000000000 +0100 +++ new/bcache-tools/probe-bcache.c 2013-08-08 00:00:49.000000000 +0200 @@ -1,3 +1,9 @@ +/* + * Author: Kent Overstreet <k...@daterainc.com> + * + * GPLv2 + */ + #define _FILE_OFFSET_BITS 64 #define __USE_FILE_OFFSET64 #define _XOPEN_SOURCE 500 -- To unsubscribe, e-mail: opensuse-commit+unsubscr...@opensuse.org For additional commands, e-mail: opensuse-commit+h...@opensuse.org