Initialize for btrfsprogs

This commit is contained in:
zyppe 2024-02-06 16:32:39 +08:00
commit bb727004d7
15 changed files with 2860 additions and 0 deletions

1
.btrfsprogs.metadata Normal file
View file

@ -0,0 +1 @@
0cf779df2ec53b0065e06367e0e462c3b8f4a48a0bcfd6329f1620e8bb753b0a btrfs-progs-v5.14.tar.gz

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
btrfs-progs-v5.14.tar.gz

View file

@ -0,0 +1,68 @@
From c03a8cab17c22f03dfebe910a567c9d547d173e1 Mon Sep 17 00:00:00 2001
From: Nikolay Borisov <nborisov@suse.com>
Date: Thu, 30 Sep 2021 15:06:32 +0300
Subject: [PATCH 1/3] btrfs-progs: Add optional dependency on libudev
This is needed for future code which will make btrfs-progs' device
scanning logic a little smarter by filtering out path device in
multipath setups. libudev is added as an optional dependency since the
library doesn't have a static version so making it a hard dependency
means forfeiting static build support. To alleviate this a fallback code
will be added for the static build case which doesn't rely on libudev.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
Makefile | 2 +-
Makefile.inc.in | 2 +-
configure.ac | 9 +++++++++
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 93fe4c2b3e08..e96f66a36b46 100644
--- a/Makefile
+++ b/Makefile
@@ -129,7 +129,7 @@ LIBS = $(LIBS_BASE) $(LIBS_CRYPTO)
LIBBTRFS_LIBS = $(LIBS_BASE) $(LIBS_CRYPTO)
# Static compilation flags
-STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
+STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections -DSTATIC_BUILD
STATIC_LDFLAGS = -static -Wl,--gc-sections
STATIC_LIBS = $(STATIC_LIBS_BASE)
diff --git a/Makefile.inc.in b/Makefile.inc.in
index 9f49337147b8..c995aef97219 100644
--- a/Makefile.inc.in
+++ b/Makefile.inc.in
@@ -27,7 +27,7 @@ CRYPTO_CFLAGS = @GCRYPT_CFLAGS@ @SODIUM_CFLAGS@ @KCAPI_CFLAGS@
SUBST_CFLAGS = @CFLAGS@
SUBST_LDFLAGS = @LDFLAGS@
-LIBS_BASE = @UUID_LIBS@ @BLKID_LIBS@ -L. -pthread
+LIBS_BASE = @UUID_LIBS@ @BLKID_LIBS@ @LIBUDEV_LIBS@ -L. -pthread
LIBS_COMP = @ZLIB_LIBS@ @LZO2_LIBS@ @ZSTD_LIBS@
LIBS_PYTHON = @PYTHON_LIBS@
LIBS_CRYPTO = @GCRYPT_LIBS@ @SODIUM_LIBS@ @KCAPI_LIBS@
diff --git a/configure.ac b/configure.ac
index 038c2688421c..d0ceb0d70d16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -304,6 +304,15 @@ PKG_STATIC(UUID_LIBS_STATIC, [uuid])
PKG_CHECK_MODULES(ZLIB, [zlib])
PKG_STATIC(ZLIB_LIBS_STATIC, [zlib])
+PKG_CHECK_EXISTS([libudev], [pkg_config_libudev=yes], [pkg_config_libudev=no])
+if test "x$pkg_config_libudev" = xyes; then
+ PKG_CHECK_MODULES([LIBUDEV], [libudev])
+ AC_DEFINE([HAVE_LIBUDEV], [1], [Define to 1 if libudev is available])
+else
+ AC_MSG_CHECKING([for LIBUDEV])
+ AC_MSG_RESULT([no])
+fi
+
AC_ARG_ENABLE([zstd],
AS_HELP_STRING([--disable-zstd], [build without zstd support]),
[], [enable_zstd=yes]
--
2.25.1

View file

@ -0,0 +1,128 @@
From 39849d97765ed133e0e7ee6eb87ecf5e20eb0d0e Mon Sep 17 00:00:00 2001
From: Nikolay Borisov <nborisov@suse.com>
Date: Thu, 30 Sep 2021 15:06:33 +0300
Subject: [PATCH 2/3] btrfs-progs: Ignore devices representing paths in
multipath
Currently btrfs-progs will happily enumerate any device which has a
btrfs filesystem on it irrespective of its type. For the majority of
use cases that's fine and there haven't been any problems with that.
However, there was a recent report that in multipath scenario when
running "btrfs fi show" after a path flap (path going down and then
coming back up) instead of the multipath device being show the device
which represents the flapped path is shown. So a multipath filesystem
might look like:
Label: none uuid: d3c1261f-18be-4015-9fef-6b35759dfdba
Total devices 1 FS bytes used 192.00KiB
devid 1 size 10.00GiB used 536.00MiB path /dev/mapper/3600140501cc1f49e5364f0093869c763
/dev/mapper/xxx is actually backed by an arbitrary number of paths,
which in turn are presented to the system as ordinary scsi devices i.e
/dev/sdX. If a path flaps and a user re-runs 'btrfs fi show' the output
would look like:
Label: none uuid: d3c1261f-18be-4015-9fef-6b35759dfdba
Total devices 1 FS bytes used 192.00KiB
devid 1 size 10.00GiB used 536.00MiB path /dev/sdd
This only occurs on unmounted filesystems as those are enumerated by
btrfs-progs, for mounted filesystem the kernel properly deals only with
the actual multipath device.
Turns out the output of this command is consumed by libraries and the
presence of a path device rather than the actual multipath causes
issues.
Fix this by checking for the presence of DM_MULTIPATH_DEVICE_PATH
udev attribute as multipath path devices are tagged with this attribute
by the multipath udev scripts.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
common/device-scan.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/common/device-scan.c b/common/device-scan.c
index b5bfe844104b..311673e6b66e 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -14,6 +14,10 @@
* Boston, MA 021110-1307, USA.
*/
+#ifdef STATIC_BUILD
+#undef HAVE_LIBUDEV
+#endif
+
#include "kerncompat.h"
#include <sys/ioctl.h>
#include <stdlib.h>
@@ -39,6 +43,10 @@
#include "kernel-shared/zoned.h"
#include "ioctl.h"
+#ifdef HAVE_LIBUDEV
+#include <libudev.h>
+#endif
+
static int btrfs_scan_done = 0;
/*
@@ -364,6 +372,43 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[])
}
}
+#ifdef HAVE_LIBUDEV
+static bool is_path_device(char *device_path)
+{
+ struct udev *udev = NULL;
+ struct udev_device *dev = NULL;
+ struct stat dev_stat;
+ const char *val;
+ bool ret = false;
+
+ if (stat(device_path, &dev_stat) < 0)
+ return false;
+
+ udev = udev_new();
+ if (!udev)
+ goto out;
+
+ dev = udev_device_new_from_devnum(udev, 'b', dev_stat.st_rdev);
+ if (!dev)
+ goto out;
+
+ val = udev_device_get_property_value(dev, "DM_MULTIPATH_DEVICE_PATH");
+ if (val && atoi(val) > 0)
+ ret = true;
+out:
+ udev_device_unref(dev);
+ udev_unref(udev);
+
+ return ret;
+}
+#else
+static bool is_path_device(char *device_path)
+{
+ return false;
+}
+#endif
+
+
int btrfs_scan_devices(int verbose)
{
int fd = -1;
@@ -394,6 +439,9 @@ int btrfs_scan_devices(int verbose)
/* if we are here its definitely a btrfs disk*/
strncpy_null(path, blkid_dev_devname(dev));
+ if (is_path_device(path))
+ continue;
+
fd = open(path, O_RDONLY);
if (fd < 0) {
error("cannot open %s: %m", path);
--
2.25.1

View file

@ -0,0 +1,127 @@
From 9fdb0badef4317dc6e680504c0315cefb15b083f Mon Sep 17 00:00:00 2001
From: Nikolay Borisov <nborisov@suse.com>
Date: Thu, 30 Sep 2021 15:06:34 +0300
Subject: [PATCH] btrfs-progs: Add fallback code for path device ignore for
static build
Since libudev doesn't provide a static version of the library for static
build btrfs-progs will have to provide manual fallback. This change does
this by parsing the udev database files hosted at /run/udev/data/.
Under that directory every block device should have a file with the
following name: bMAJ:MIN. So implement the bare minimum code necessary
to parse this file and search for the presence of DM_MULTIPATH_DEVICE_PATH
udev attribute. This could likely be racy since access to the udev
database is done outside of libudev but that's the best that can be
done when implementing this manually.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
common/device-scan.c | 55 ++++++++++++++++++++++++++++++++++++--------
1 file changed, 46 insertions(+), 9 deletions(-)
diff --git a/common/device-scan.c b/common/device-scan.c
index 311673e6b66e..483831722b60 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -29,6 +29,7 @@
#include <dirent.h>
#include <blkid/blkid.h>
#include <uuid/uuid.h>
+#include <sys/sysmacros.h>
#include "kernel-lib/overflow.h"
#include "common/path-utils.h"
#include "common/device-scan.h"
@@ -372,23 +373,54 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[])
}
}
-#ifdef HAVE_LIBUDEV
-static bool is_path_device(char *device_path)
+#ifdef STATIC_BUILD
+static bool is_path_device(dev_t device)
+{
+ FILE *file;
+ char *line = NULL;
+ size_t len = 0;
+ ssize_t nread;
+ bool ret = false;
+ int ret2;
+ char path[PATH_MAX];
+
+ ret2 = snprintf(path, 100, "/run/udev/data/b%u:%u", major(device),
+ minor(device));
+
+ if (ret2 < 0)
+ return false;
+
+ file = fopen(path, "r");
+ if (file == NULL)
+ return false;
+
+ while ((nread = getline(&line, &len, file)) != -1) {
+ if (strstr(line, "DM_MULTIPATH_DEVICE_PATH=1")) {
+ ret = true;
+ break;
+ }
+ }
+
+ if (line)
+ free(line);
+
+ fclose(file);
+
+ return ret;
+}
+#elif defined(HAVE_LIBUDEV)
+static bool is_path_device(dev_t device)
{
struct udev *udev = NULL;
struct udev_device *dev = NULL;
- struct stat dev_stat;
const char *val;
bool ret = false;
- if (stat(device_path, &dev_stat) < 0)
- return false;
-
udev = udev_new();
if (!udev)
goto out;
- dev = udev_device_new_from_devnum(udev, 'b', dev_stat.st_rdev);
+ dev = udev_device_new_from_devnum(udev, 'b', device);
if (!dev)
goto out;
@@ -402,7 +434,7 @@ static bool is_path_device(char *device_path)
return ret;
}
#else
-static bool is_path_device(char *device_path)
+static bool is_path_device(dev_t device)
{
return false;
}
@@ -433,13 +465,18 @@ int btrfs_scan_devices(int verbose)
iter = blkid_dev_iterate_begin(cache);
blkid_dev_set_search(iter, "TYPE", "btrfs");
while (blkid_dev_next(iter, &dev) == 0) {
+ struct stat dev_stat;
+
dev = blkid_verify(cache, dev);
if (!dev)
continue;
/* if we are here its definitely a btrfs disk*/
strncpy_null(path, blkid_dev_devname(dev));
- if (is_path_device(path))
+ if (stat(path, &dev_stat) < 0)
+ continue;
+
+ if (is_path_device(dev_stat.st_rdev))
continue;
fd = open(path, O_RDONLY);
--
2.25.1

19
boot-btrfs.sh Normal file
View file

@ -0,0 +1,19 @@
#!/bin/bash -e
#%stage: filesystem
#%depends: dm dmraid lvm2 udev md luks
#%programs: btrfs
#%programs: btrfs-convert
#%programs: btrfs-find-root
#%programs: btrfs-image
#%programs: btrfs-select-super
#%programs: btrfsck
#%programs: btrfstune
# for fsck(8): listed twice so that a copy really ends up in /sbin
#%programs: /sbin/fsck.btrfs
#%programs: fsck.btrfs
#%programs: mkfs.btrfs
#%modules: btrfs
modprobe btrfs
btrfs dev scan >& /dev/null

View file

@ -0,0 +1,43 @@
From 61e00694e799e1d54c98124880ca03a08dd5d4a2 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.com>
Date: Sat, 18 Sep 2021 17:44:57 +0200
Subject: [PATCH] btrfs-progs: fix defrag -c option parsing
The refactoring f3a132fa1b8c ("btrfs-progs: factor out compression type
name parsing to common utils") caused a bug with parsing option -c with
defrag:
# btrfs fi defrag -v -czstd file
ERROR: unknown compression type: zstd
# btrfs fi defrag -v -clzo file
ERROR: unknown compression type: lzo
# btrfs fi defrag -v -czlib file
ERROR: unknown compression type: zlib
Fix it by properly checking the value representing unknown compression
algorithm.
Issue: #403
Signed-off-by: David Sterba <dsterba@suse.com>
---
cmds/filesystem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 9a41137d..c338571a 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -835,7 +835,7 @@ static int parse_compress_type_arg(char *s)
int ret;
ret = parse_compress_type(s);
- if (ret) {
+ if (ret < 0) {
error("unknown compression type: %s", s);
exit(1);
}
--
2.35.3

View file

@ -0,0 +1,123 @@
From 7781d1a2daa6564c3988dc268eb0680e057027f5 Mon Sep 17 00:00:00 2001
From: Li Zhang <zhanglikernel@gmail.com>
Date: Sun, 16 Jan 2022 16:52:43 +0800
Subject: [PATCH] btrfs-progs: props: don't translate value of compression=none
References: JSC#PED-1711
Currently, if user specifies value 'no' or 'none' on the command line,
it gets translated to an empty value that is passed to kernel. There was
a change in kernel 5.14 done by commit 5548c8c6f55b ("btrfs: props:
change how empty value is interpreted") that changes the behaviour
in that case.
The empty value is supposed to mean 'the default value' for any
property. For compression there is a need to distinguish resetting the
value and also setting the NOCOMPRESS property. The translation to empty
value makes that impossible.
The explanation and behaviour copied from the kernel patch:
Old behaviour:
$ lsattr file
---------------------- file
# the NOCOMPRESS bit is set
$ btrfs prop set file compression ''
$ lsattr file
---------------------m file
This is equivalent to 'btrfs prop set file compression no' in current
btrfs-progs as the 'no' or 'none' values are translated to an empty
string.
This is where the new behaviour is different: empty string drops the
compression flag (-c) and nocompress (-m):
$ lsattr file
---------------------- file
# No change
$ btrfs prop set file compression ''
$ lsattr file
---------------------- file
$ btrfs prop set file compression lzo
$ lsattr file
--------c------------- file
$ btrfs prop get file compression
compression=lzo
$ btrfs prop set file compression ''
# Reset to the initial state
$ lsattr file
---------------------- file
# Set NOCOMPRESS bit
$ btrfs prop set file compression no
$ lsattr file
---------------------m file
This obviously brings problems with backward compatibility, so this
patch should not be backported without making sure the updated
btrfs-progs are also used and that scripts have been updated to use the
new semantics.
Summary:
- old kernel:
no, none, "" - set NOCOMPRESS bit
- new kernel:
no, none - set NOCOMPRESS bit
"" - drop all compression flags, ie. COMPRESS and NOCOMPRESS
Signed-off-by: Li Zhang <zhanglikernel@gmail.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
---
Documentation/btrfs-property.8 | 11 +++++++++--
Documentation/btrfs-property.asciidoc | 3 ++-
cmds/property.c | 2 --
3 files changed, 11 insertions(+), 5 deletions(-)
--- a/Documentation/btrfs-property.8
+++ b/Documentation/btrfs-property.8
@@ -82,10 +82,17 @@
compression algorithm set for an inode, possible values:
\fIlzo\fR,
\fIzlib\fR,
-\fIzstd\fR\&. To disable compression use "" (empty string),
+\fIzstd\fR\&. To disable compression use
\fIno\fR
or
-\fInone\fR\&.
+\fInone\fR\&. Empty value resets the property and sets a default value.
+.br
+.PP
+.ps +1
+\fBNote\fR
+.ps -1
+.br
+An empty value resetting compression property has changed since kernel 5.14. Earlier versions would disable compression.
.RE
.RE
.PP
--- a/Documentation/btrfs-property.asciidoc
+++ b/Documentation/btrfs-property.asciidoc
@@ -47,7 +47,8 @@
device as object. For a mounted filesystem, specify a mount point.
compression::::
compression algorithm set for an inode, possible values: 'lzo', 'zlib', 'zstd'.
-To disable compression use "" (empty string), 'no' or 'none'.
+To disable compression use 'no' or 'none'. An empty string "" resets the property and sets a default value.
+'Note:' An empty value resetting compression property has changed since kernel 5.14. Earlier versions would disable compression.
*list* [-t <type>] <object>::
Lists available properties with their descriptions for the given object.
--- a/cmds/property.c
+++ b/cmds/property.c
@@ -126,8 +126,6 @@
xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0';
if (value) {
- if (strcmp(value, "no") == 0 || strcmp(value, "none") == 0)
- value = "";
sret = fsetxattr(fd, xattr_name, value, strlen(value), 0);
} else {
sret = fgetxattr(fd, xattr_name, NULL, 0);

1860
btrfsprogs.changes Normal file

File diff suppressed because it is too large Load diff

424
btrfsprogs.spec Normal file
View file

@ -0,0 +1,424 @@
#
# spec file for package btrfsprogs
#
# Copyright (c) 2022-2023 ZhuningOS
#
%define udev_with_btrfs_builtin 190
%define udev_version %(pkg-config --modversion udev)
%define package_udev_rules %{udev_version} >= %{udev_with_btrfs_builtin}
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
# enable building of btrfsprogs-static
%if 0%{?suse_version} <= 1310 || 0%{?suse_version} == 1315
%define build_static 0
%else
%define build_static 1
%endif
# the tarball contains prebuilt documentation
%define build_docs 1
%define _dracutmodulesdir %(pkg-config --variable dracutmodulesdir dracut)
Name: btrfsprogs
Version: 5.14
Release: 150500.10.3.1
Summary: Utilities for the Btrfs filesystem
License: GPL-2.0-only
Group: System/Filesystems
URL: https://btrfs.wiki.kernel.org/index.php/Main_Page
#Git-Web: http://git.kernel.org/cgit/linux/kernel/git/kdave/btrfs-progs.git
#Git-Clone: git://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs
Source: https://www.kernel.org/pub/linux/kernel/people/kdave/btrfs-progs/btrfs-progs-v%{version}.tar.gz
# support for mkinitrd in < 13.1
Source1: boot-btrfs.sh
Source2: module-setup.sh.in
Source3: dracut-fsck-help.txt
Source4: setup-btrfs.sh
Source5: sles11-defaults.h
Patch1: mkfs-default-features.patch
Patch2: 0001-btrfs-progs-Add-optional-dependency-on-libudev.patch
Patch3: 0002-btrfs-progs-Ignore-devices-representing-paths-in-mul.patch
Patch4: 0003-btrfs-progs-Add-fallback-code-for-path-device-ignore.patch
Patch5: btrfs-progs_props_dont_translate_value_of_compression_none.patch
Patch6: btrfs-progs-fix-defrag-c-option-parsing.patch
%if %build_docs
BuildRequires: asciidoc
%endif
BuildRequires: autoconf
BuildRequires: automake
%if 0%{?suse_version} > 1200
BuildRequires: dracut
%endif
BuildRequires: libattr-devel
BuildRequires: libblkid-devel
BuildRequires: libext2fs-devel
BuildRequires: libreiserfscore-devel >= 3.6.27
Requires: libreiserfscore0 >= 3.6.27
BuildRequires: libuuid-devel
%if 0%{?suse_version} > 1500
BuildRequires: libzstd-devel
%endif
BuildRequires: lzo-devel
BuildRequires: pkg-config
BuildRequires: python-rpm-macros
%if 0%{?suse_version} >= 1310
BuildRequires: suse-module-tools
%endif
BuildRequires: pkgconfig(udev)
BuildRequires: systemd-devel
%if %build_docs
BuildRequires: xmlto
%endif
BuildRequires: python-rpm-macros
BuildRequires: zlib-devel
%if 0%{?suse_version} >= 1310
Requires(post): coreutils
Requires(postun):coreutils
%endif
Supplements: filesystem(btrfs)
Recommends: btrfsmaintenance
%if %{package_udev_rules}
Requires: btrfsprogs-udev-rules
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
Utilities needed to create and maintain btrfs file systems under Linux.
%if %build_static
%package -n btrfsprogs-static
Summary: Static build of utilities for the Btrfs filesystem
Group: System/Filesystems
BuildRequires: glibc-devel-static
BuildRequires: libblkid-devel-static
BuildRequires: libcom_err-devel-static
BuildRequires: libext2fs-devel-static
BuildRequires: libuuid-devel-static
%if 0%{?suse_version} > 1500
BuildRequires: libzstd-devel-static
%endif
BuildRequires: lzo-devel-static
BuildRequires: zlib-devel-static
%description -n btrfsprogs-static
Static build of utilities needed to create and maintain btrfs file systems
under Linux. Suitable for limited or rescue environments.
Warning: the zlib and lzo libraries are statically linked in and may lack
important updates
%endif
%package -n libbtrfs0
Summary: Library for interacting with Btrfs
Group: System/Libraries
%description -n libbtrfs0
This package contains the libbtrfs.so shared library needed for some
applications to interface with btrfs.
%package -n libbtrfs-devel
Summary: Include Files and Libraries for developing with Btrfs
Group: Development/Libraries/C and C++
Requires: %{name} = %{version}-%{release}
Requires: libbtrfs0 = %{version}
%description -n libbtrfs-devel
This package contains the libraries and headers files for developers to
build applications to interface with Btrfs.
# rpm < 4.6.0 (SLE11 uses 4.4) doesn't support noarch subpackages.
# Fortunately, it doesn't use systemd either so we can just skip it.
%if %{package_udev_rules}
%package udev-rules
Summary: Udev rules for configuring btrfs file systems
Group: System/Kernel
Conflicts: udev < %{udev_with_btrfs_builtin}
BuildArch: noarch
%description udev-rules
This package contains the udev rule file for configuring device mapper
devices that are components of btrfs file systems. It is meant to be
used with versions of udev that contain the "built-in" btrfs command
(v190 and newer). Older versions of udev will call the version of
"btrfs ready" contained in the btrfsprogs package, which does the right
thing.
%endif
%package -n libbtrfsutil1
Summary: Utility library for interacting with Btrfs
Group: System/Libraries
%description -n libbtrfsutil1
This package contains the libbtrfsutil.so shared library. This library is
LGPL unlike libbtrfs.so and can be used by applications to interact with Btrfs
filesystems.
%package -n libbtrfsutil-devel
Summary: Include Files and Libraries for developing with libbtrfsutil
Group: Development/Libraries/C and C++
Requires: %{name} = %{version}-%{release}
Requires: libbtrfsutil1 = %{version}
%description -n libbtrfsutil-devel
This package contains the libraries and headers files for developers to
build applications to interface with Btrfs using libbtrfsutil.
%package -n python-btrfsutil
Summary: Python bindings for developing with libbtrfsutil
Group: Development/Languages/Python
Requires: %{name} = %{version}-%{release}
Requires: libbtrfsutil1 = %{version}
Requires: python3
BuildRequires: %{python_module setuptools}
BuildRequires: pkgconfig(python3)
%description -n python-btrfsutil
This package contains the python bindings to build applications to interface
with Btrfs using libbtrfsutil.
%prep
%setup -q -n btrfs-progs-v%{version}
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%build
./autogen.sh
%if 0%{?suse_version} == 1110
cp %{SOURCE5} .
export CFLAGS="%{optflags} -include sles11-defaults.h"
%endif
%configure \
--enable-python \
%if !%{build_docs}
--disable-documentation \
%endif
%if 0%{?suse_version} <= 1500
--disable-zoned \
--disable-zstd
%endif
make V=1 %{?_smp_mflags} all \
%if %{build_static}
static
%endif
%install
make install \
%if %{build_static}
install-static \
%endif
DESTDIR=%{buildroot} prefix=%{_prefix} bindir=%{_sbindir} mandir=%{_mandir} libdir=%{_libdir} \
install_python
%if !%{build_docs}
cd Documentation
install -m 0755 -d %{buildroot}/%{_mandir}/man5
install -m 0755 -d %{buildroot}/%{_mandir}/man8
install -m 0644 *.5 %{buildroot}/%{_mandir}/man5
install -m 0644 *.8 %{buildroot}/%{_mandir}/man8
cd ..
%endif
%if %{build_static}
make install-static DESTDIR=%{buildroot} prefix=%{_prefix} bindir=%{_sbindir} mandir=%{_mandir} libdir=%{_libdir}
%endif
install -m 0755 -d %{buildroot}/%{_sbindir}
install -m 0755 -d %{buildroot}/%{_bindir}
# move some utilities out of /usr/sbin
mv %{buildroot}/%{_sbindir}/btrfs-map-logical %{buildroot}/%{_bindir}
# initrd rescue utilities
install -m 0755 btrfs-select-super %{buildroot}/%{_sbindir}
install -m 0755 btrfs-image %{buildroot}/%{_sbindir}
install -m 0755 btrfstune %{buildroot}/%{_sbindir}
install -m 0755 btrfs-find-root %{buildroot}/%{_sbindir}
%if !0%{?usrmerged}
install -m 0755 -d %{buildroot}/sbin
ln -s %{_sbindir}/btrfs %{buildroot}/sbin
ln -s %{_sbindir}/btrfs-convert %{buildroot}/sbin
ln -s %{_sbindir}/btrfs-select-super %{buildroot}/sbin
ln -s %{_sbindir}/btrfs-image %{buildroot}/sbin
ln -s %{_sbindir}/btrfstune %{buildroot}/sbin
ln -s %{_sbindir}/btrfsck %{buildroot}/sbin
ln -s %{_sbindir}/btrfs-find-root %{buildroot}/sbin
ln -s %{_sbindir}/mkfs.btrfs %{buildroot}/sbin
ln -s %{_sbindir}/fsck.btrfs %{buildroot}/sbin
%endif
%if 0%{?suse_version} < 1310
install -d -m0755 %{buildroot}/lib/mkinitrd/scripts/
install -m 0755 %{SOURCE1} %{buildroot}/lib/mkinitrd/scripts/
install -m 0755 %{SOURCE4} %{buildroot}/lib/mkinitrd/scripts/
%endif
# don't install .a for now
rm -f %{buildroot}/%{_libdir}/*.a
# bash completion
install -m 0755 -d %{buildroot}/%{_datadir}/bash-completion/completions
install -m 0644 btrfs-completion %{buildroot}/%{_datadir}/bash-completion/completions/btrfs
%if 0%{?suse_version} > 1200
sed -e 's,@@INSTALLDIR@@,%{_datadir}/%{name}/,;' %{SOURCE2} > module-setup.sh
install -m 0755 -D module-setup.sh %{buildroot}/%{_dracutmodulesdir}/95suse-btrfs/module-setup.sh
rm -f module-setup.sh
install -m 0644 -D %{SOURCE3} %{buildroot}/%{_datadir}/%{name}/dracut-fsck-help.txt
%endif
%if 0%{!?for_debugging:1}
DEBUG_FILES="/sbin/btrfs-find-root
%{_sbindir}/btrfs-find-root
%{_mandir}/man8/btrfs-find-root.8
/sbin/btrfs-select-super
%{_sbindir}/btrfs-select-super"
for file in $DEBUG_FILES; do
rm -f %{buildroot}$file
done
%endif
%post -n libbtrfs0 -p /sbin/ldconfig
%postun -n libbtrfs0 -p /sbin/ldconfig
%post -n libbtrfsutil1 -p /sbin/ldconfig
%postun -n libbtrfsutil1 -p /sbin/ldconfig
%if 0%{?suse_version} >= 1310
%post
%{?regenerate_initrd_post}
%postun
%{?regenerate_initrd_post}
%posttrans
%{?regenerate_initrd_posttrans}
%endif
%files
%defattr(-, root, root)
%if 0%{?suse_version} < 1200
# SLE11 doesn't know about %license
%doc COPYING
%else
%license COPYING
%endif
%if 0%{?suse_version} > 1200
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/dracut-fsck-help.txt
%dir %{_dracutmodulesdir}/95suse-btrfs/
%{_dracutmodulesdir}/95suse-btrfs/module-setup.sh
%endif
%if !0%{?usrmerged}
/sbin/fsck.btrfs
# mkinitrd utils
/sbin/btrfs
/sbin/btrfs-convert
/sbin/btrfs-image
/sbin/btrfstune
/sbin/btrfsck
/sbin/mkfs.btrfs
%endif
%{_sbindir}/btrfs
%{_sbindir}/btrfs-convert
%{_sbindir}/btrfs-image
%{_sbindir}/btrfstune
%{_sbindir}/btrfsck
%{_sbindir}/fsck.btrfs
%{_sbindir}/mkfs.btrfs
%if 0%{?suse_version} < 1310
%dir /lib/mkinitrd
%dir /lib/mkinitrd/scripts
/lib/mkinitrd/scripts/boot-btrfs.sh
/lib/mkinitrd/scripts/setup-btrfs.sh
%endif
%{_bindir}/btrfs-map-logical
%{_mandir}/man8/btrfs-image.8%{?ext_man}
%{_mandir}/man8/btrfsck.8%{?ext_man}
%{_mandir}/man8/fsck.btrfs.8%{?ext_man}
%{_mandir}/man8/mkfs.btrfs.8%{?ext_man}
%{_mandir}/man8/btrfs.8%{?ext_man}
%{_mandir}/man5/btrfs.5%{?ext_man}
%{_mandir}/man8/btrfs-convert.8%{?ext_man}
%{_mandir}/man8/btrfs-map-logical.8%{?ext_man}
%{_mandir}/man8/btrfstune.8%{?ext_man}
%{_mandir}/man8/btrfs-balance.8%{?ext_man}
%{_mandir}/man8/btrfs-check.8%{?ext_man}
%{_mandir}/man8/btrfs-device.8%{?ext_man}
%{_mandir}/man8/btrfs-filesystem.8%{?ext_man}
%{_mandir}/man8/btrfs-inspect-internal.8%{?ext_man}
%{_mandir}/man8/btrfs-property.8%{?ext_man}
%{_mandir}/man8/btrfs-qgroup.8%{?ext_man}
%{_mandir}/man8/btrfs-quota.8%{?ext_man}
%{_mandir}/man8/btrfs-receive.8%{?ext_man}
%{_mandir}/man8/btrfs-replace.8%{?ext_man}
%{_mandir}/man8/btrfs-rescue.8%{?ext_man}
%{_mandir}/man8/btrfs-restore.8%{?ext_man}
%{_mandir}/man8/btrfs-scrub.8%{?ext_man}
%{_mandir}/man8/btrfs-send.8%{?ext_man}
%{_mandir}/man8/btrfs-subvolume.8%{?ext_man}
%{_mandir}/man8/btrfs-select-super.8%{?ext_man}
%dir %{_datadir}/bash-completion
%dir %{_datadir}/bash-completion/completions
%{_datadir}/bash-completion/completions/btrfs
%if 0%{?for_debugging:1}
/sbin/btrfs-find-root
%{_sbindir}/btrfs-find-root
%{_mandir}/man8/btrfs-find-root.8%{?ext_man}
/sbin/btrfs-select-super
%{_sbindir}/btrfs-select-super
%endif
%if %{build_static}
%files -n btrfsprogs-static
%defattr(-, root, root)
%{_sbindir}/btrfs.static
%{_sbindir}/btrfs-convert.static
%{_sbindir}/btrfs-image.static
%{_sbindir}/btrfstune.static
%{_sbindir}/btrfsck.static
%{_sbindir}/mkfs.btrfs.static
%{_sbindir}/btrfs-corrupt-block.static
%{_sbindir}/btrfs-find-root.static
%{_sbindir}/btrfs-map-logical.static
%{_sbindir}/btrfs-select-super.static
%endif
%files -n libbtrfs0
%defattr(-, root, root)
%{_libdir}/libbtrfs.so.*
%files -n libbtrfs-devel
%defattr(-, root, root)
%dir %{_includedir}/btrfs
%{_includedir}/btrfs/*
%{_libdir}/libbtrfs.so
%files -n libbtrfsutil1
%defattr(-, root, root)
%{_libdir}/libbtrfsutil.so.*
%files -n libbtrfsutil-devel
%defattr(-, root, root)
%{_includedir}/btrfsutil.h
%{_libdir}/libbtrfsutil.so
%{_libdir}/pkgconfig/libbtrfsutil.pc
%if %{package_udev_rules}
%files udev-rules
%defattr(-, root, root)
%dir %{_udevrulesdir}
%{_udevrulesdir}/64-btrfs-dm.rules
%endif
%files -n python-btrfsutil
%{python3_sitearch}/*
%changelog

6
dracut-fsck-help.txt Normal file
View file

@ -0,0 +1,6 @@
Recovery of btrfs file systems is not automated. We suggest you use
'btrfs check --readonly' first to see the if there's any damage and
what's the scope. Logging the output is a recommended for later analysis.
The option '--repair' must be used with care, be noted that it is
able to fix certain classes of errors but not all of them.

View file

@ -0,0 +1,32 @@
From: Jeff Mahoney <jeffm@suse.com>
Subject: mkfs: allow site to override defaults
Patch-mainline: Never, a real solution with a config file is required
References: FATE#320615
This is a simple method to allow us to set site defaults for mkfs by
adding -include <includefile> to cflags.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
utils.h | 4 ++++
1 file changed, 4 insertions(+)
Index: btrfs-progs-v5.12/common/fsfeatures.h
===================================================================
--- btrfs-progs-v5.12.orig/common/fsfeatures.h
+++ btrfs-progs-v5.12/common/fsfeatures.h
@@ -19,10 +19,14 @@
#include "kerncompat.h"
+#ifndef BTRFS_MKFS_DEFAULT_NODE_SIZE
#define BTRFS_MKFS_DEFAULT_NODE_SIZE SZ_16K
+#endif
+#ifndef BTRFS_MKFS_DEFAULT_FEATURES
#define BTRFS_MKFS_DEFAULT_FEATURES \
(BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF \
| BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
+#endif
/*
* Avoid multi-device features (RAID56), mixed block groups, and zoned mode

17
module-setup.sh.in Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
# called by dracut
check() {
return 0
}
# called by dracut
depends() {
return 0
}
# called by dracut
install() {
inst_fsck_help "btrfs" "@@INSTALLDIR@@/dracut-fsck-help.txt"
}

6
setup-btrfs.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
#
#%stage: filesystem
mkdir -p $tmp_mnt/etc/udev/rules.d
cp /usr/lib/udev/rules.d/64-btrfs.rules $tmp_mnt/etc/udev/rules.d

5
sles11-defaults.h Normal file
View file

@ -0,0 +1,5 @@
#ifndef _SLES11_DEFAULTS_H
#define _SLES11_DEFAULTS_H
#define BTRFS_MKFS_DEFAULT_NODE_SIZE sysconf(_SC_PAGESIZE)
#define BTRFS_MKFS_DEFAULT_FEATURES BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF
#endif