The Gluster Blog

Gluster blog stories provide high-level spotlights on our users all over the world

Quick and dirty python script to check the dirty status of files in a GlusterFS brick

Gluster
2011-09-06

This is a quick and dirty script I threw together to list files with dirty flags from a GlusterFS brick.

#!/bin/env python
#
# (C) 2011, Joe Julian 
#
# License: GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
#

import os,socket,xattr,sys,time
from stat import *

def scandirs(arg, dirname, fnames):
    for fn in fnames:
        filename = os.path.join(dirname,fn)
        fmode = os.lstat(filename).st_mode
        if S_ISREG(fmode) and os.path.getsize(filename) > 0:
            try:
                attributes = xattr.listxattr(filename)
                status = [ xattr.getxattr(filename,x) for x in attributes if x.startswith("trusted.afr.") ]
                if len([ x for x in status if not x == '\x00'*12]) > 0:
                    if S_IMODE(fmode) == 512:
                        os.remove(filename)
                        status = []
                    else:
                        time.sleep(0.2)
                        status = [ xattr.getxattr(filename,x) for x in attributes if x.startswith("trusted.afr.") ]
                if len([ x for x in status if not x == '\x00'*12]) > 0:
                    for x in attributes: 
                        if x.startswith("trusted.afr") and not xattr.getxattr(filename,x) == '\x00'*12:
                            print filename
                            print "\t%s=0x%s" % (x,"".join(["%02x" % ord(y) for y in list(xattr.getxattr(filename,x))]))
            except:
                status = ""

if not len(sys.argv) == 2:
    print """Usage:
        %s {brick directory}
    """ % sys.argv[0]
else:
    os.path.walk(sys.argv[1],scandirs, None)

Download

BLOG

  • 06 Dec 2020
    Looking back at 2020 – with g...

    2020 has not been a year we would have been able to predict. With a worldwide pandemic and lives thrown out of gear, as we head into 2021, we are thankful that our community and project continued to receive new developers, users and make small gains. For that and a...

    Read more
  • 27 Apr 2020
    Update from the team

    It has been a while since we provided an update to the Gluster community. Across the world various nations, states and localities have put together sets of guidelines around shelter-in-place and quarantine. We request our community members to stay safe, to care for their loved ones, to continue to be...

    Read more
  • 03 Feb 2020
    Building a longer term focus for Gl...

    The initial rounds of conversation around the planning of content for release 8 has helped the project identify one key thing – the need to stagger out features and enhancements over multiple releases. Thus, while release 8 is unlikely to be feature heavy as previous releases, it will be the...

    Read more