linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans van Kranenburg <hans.van.kranenburg@mendix.com>
To: linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Hello world, python-btrfs
Date: Sat, 18 Jun 2016 00:01:53 +0200	[thread overview]
Message-ID: <57647351.4010603@mendix.com> (raw)

Hi!

After playing around a bit for a few months with a bunch of
proof-of-concept level scripts to be able to debug my btrfs file
systems, the inevitable happened:

https://github.com/knorrie/python-btrfs/

Currently, the primary goal of this module is to be able to inspect the
internals of an existing filesystem for educational purposes.

In the last week I started sorting out the puzzle pieces I already
assembled, and put most of them together into a proper python library to
query a btrfs filesystem.

The python module acts as a wrapper around the low level kernel calls
and btrfs data structures, presenting them as python objects with
interesting attributes and references to other objects.

Using these helpers, it should be fairly easy to reimplement the same
functionality as for example btrfs fi df, btrfs fi show and btrfs
inspect-internal provide.

For example:

import btrfs
fs = btrfs.FileSystem('/')
for space in fs.space_info():
     print("{0}, {1}: total={2}, used={3}".format(
           btrfs.utils.block_group_type_str(space.flags),
           btrfs.utils.block_group_profile_str(space.flags),
           btrfs.utils.pretty_size(space.total_bytes),
           btrfs.utils.pretty_size(space.used_bytes)))

results in:

Data, single: total=15.94GiB, used=6.30GiB
System, DUP: total=32.00MiB, used=16.00KiB
Metadata, DUP: total=768.00MiB, used=158.72MiB
GlobalReserve, single: total=64.00MiB, used=0.00B

The btrfs directory in the source is the python module which is to be
imported as btrfs.

The examples directory contains example programs that use the library.
For all functionality that's added in the lib, there must be an example
program that uses it.

Currently, the code can look at devices, chunks, block groups with their
usage and lists of data extents. I usually write quite elaborate git
commit messages, so when looking through my commits or doing a git blame
on code, you should (now and later) find a nice description about the
hows whys etc of the code.

Why?!

* Because it's fun!
* Because I get sick of using horrible ducttape regex solutions to
programmatically parse human readable output of external tools to
implement monitoring tools~~!11one.
* Because I might to be able to help other people that also want to
learn the internals of btrfs.
* Much more...

How?

* It's a python library, so the code will have a decent level of
pythonicity. The ioctl search returns a generator, the search key is a
nice object you can just increment etc...
* This is a work in progress. I can only add support for parts of btrfs
that I understand myself first.

Moo!

Hans van Kranenburg

-- 
Hans van Kranenburg - System / Network Engineer
T +31 (0)10 2760434 | hans.van.kranenburg@mendix.com | www.mendix.com

             reply	other threads:[~2016-06-17 22:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-17 22:01 Hans van Kranenburg [this message]
2016-06-23 14:26 ` Hello world, python-btrfs David Sterba
2016-06-23 23:29   ` Hans van Kranenburg
2016-07-12 16:47     ` David Sterba
2016-07-13 20:10 ` Juan Orti Alcaine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57647351.4010603@mendix.com \
    --to=hans.van.kranenburg@mendix.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).