linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Mamedov <rm@romanrm.ru>
To: dima <dolenin@parallels.com>
Cc: <linux-btrfs@vger.kernel.org>
Subject: Re: Set nodatacow per file?
Date: Mon, 13 Feb 2012 14:09:21 +0600	[thread overview]
Message-ID: <20120213140921.5a009404@natsu> (raw)
In-Reply-To: <4F38BE53.4080204@parallels.com>


[-- Attachment #1.1: Type: text/plain, Size: 1104 bytes --]

On Mon, 13 Feb 2012 16:40:03 +0900
dima <dolenin@parallels.com> wrote:

> Hello Ralf-Peter,
> 
> Actually it is possible. Check out David's response to my question from 
> some time ago:
> http://permalink.gmane.org/gmane.comp.file-systems.btrfs/14227
> 
> The nocow.c script he attached does just the thing you want. The script 
> is really working. I needed nocow for different purpose but it did not 
> occur to me to try it on VM image and see if the performance would 
> improve. Sounds like a great idea. If you get around to try it, pls. 
> post your impressions here.

Thanks for the link, this is indeed interesting.

I made a couple of small changes, i.e. I wanted a way to unset nocow and to
check that changing flags really worked.

gcc -o /usr/local/bin/nocow nocow.c
ln -sf /usr/local/bin/nocow /usr/local/bin/cow

Perhaps the support for setting this flag should be added to the 'btrfs'
utility.

-- 
With respect,
Roman

~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Stallman had a printer,
with code he could not see.
So he began to tinker,
and set the software free."

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: nocow.c --]
[-- Type: text/x-csrc, Size: 1622 bytes --]

#include <fcntl.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <string.h>

#include <linux/types.h>
#include <stdio.h>
#include <errno.h>

#ifndef FS_IOC_SETFLAGS
#define FS_IOC_SETFLAGS                 _IOW('f', 2, long)
#warning defining SETFLAGS locally
#endif

#ifndef FS_IOC_GETFLAGS
#define FS_IOC_GETFLAGS                 _IOR('f', 1, long)
#warning defining GETFLAGS locally
#endif

#ifndef FS_NOCOW_FL
#define FS_NOCOW_FL                     0x00800000 /* Do not cow file */
#endif

int main(int argc, char **argv)
{
        int fd;
        int r;
  long flags;

  if (argc < 2) {
    printf("usage: %s file\n", argv[0]);
    exit(1);
  }

  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("open()");
    return 1;
  }
  printf("GETFLAGS ioctl 0x%x\n", FS_IOC_GETFLAGS);
  printf("SETFLAGS ioctl 0x%x\n", FS_IOC_SETFLAGS);

  r = ioctl(fd, FS_IOC_GETFLAGS, &flags);
  if (r == -1) {
    perror("ioctl(GETFLAGS)");
    return 1;
  } else {
    printf("file flags before: 0x%lx\n", flags);
  }

  if(strcmp(argv[0], "cow")==0) {
    printf("Remove NOCOW flag for %s\n", argv[1]);
    flags ^= FS_NOCOW_FL;
  } else {
    printf("Set NOCOW flag for %s\n", argv[1]);    
    flags |= FS_NOCOW_FL;
  }
  r = ioctl(fd, FS_IOC_SETFLAGS, &flags);
  printf("ioctl returned: %d\n", r);
  if (r == -1) {
    perror("ioctl()");
    return 1;
  }

  r = ioctl(fd, FS_IOC_GETFLAGS, &flags);
  if (r == -1) {
    perror("ioctl(GETFLAGS)");
    return 1;
  } else {
    printf("file flags after:  0x%lx\n", flags);
  }  

  return 0;
}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2012-02-13  8:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-13  7:17 Set nodatacow per file? Ralf-Peter Rohbeck
2012-02-13  7:34 ` Chester
2012-02-13  8:10   ` Liu Bo
2012-02-13  7:40 ` dima
2012-02-13  8:09   ` Roman Mamedov [this message]
2012-02-13  8:40     ` dima
2012-02-13 13:42     ` dima
2012-02-13 13:51       ` Roman Mamedov
2012-02-13 14:31         ` Dmitry Olenin
2012-02-13 14:10   ` David Sterba
2012-02-13 14:21     ` Timo Witte
2012-02-13 15:10     ` dima
2012-02-16 13:55     ` NOCOW + compress-force = bug Roman Mamedov
2012-02-16 14:30       ` David Sterba
2012-02-16 17:58       ` Chris Mason
2012-03-13 18:11         ` Jeff Mahoney
2012-03-13 18:36           ` Jeff Mahoney
2012-02-29 15:09     ` Set nodatacow per file? Kyle Gates
2012-02-29 15:34       ` cwillu
2012-02-24  5:22 ` dima
2012-02-27 13:54   ` dima
2012-02-27 22:10     ` Chester
2012-02-28  0:51       ` dima
2012-03-02  3:28         ` dima

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=20120213140921.5a009404@natsu \
    --to=rm@romanrm.ru \
    --cc=dolenin@parallels.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).