From vel.indira at gmail.com Tue Jun 1 07:43:08 2010 From: vel.indira at gmail.com (Indira ramasamy) Date: Tue, 1 Jun 2010 13:13:08 +0530 Subject: File system structure difference between cp and mv linux commands Message-ID: Hi, I am facing one problem only with mv command not with cp command. I have a test program #include #include #include #include #include #include #include int sync_file(char *file) { FILE *fp=NULL; int fd; printf("file is %s\n",file); fp = fopen(file, "r"); if(!fp) return -1; fd = fileno(fp); fflush(fp); fsync(fd); ioctl (fd, BLKFLSBUF, 0); fclose(fp); return 0; } int main() { int len=0; FILE *fp = NULL; char buf[1024]; char *fname = "/etc/test.conf"; char fname_tmp[129] = ""; len = sprintf(buf, "%s\n", "Newly added Line is there"); snprintf(fname_tmp, 128, "%s.tmp", fname); if( (fp = fopen(fname_tmp,"a")) == NULL ) printf(" ERROR: open(), error - %s\n",strerror(errno)); fprintf(fp,"%s",buf); fflush(fp); fsync(fileno(fp)); fclose(fp); system("cp -f /etc/test.conf.tmp /etc/test.conf"); // system("mv -f /etc/test.conf.tmp /etc/test.conf"); sync_file(fname); return 0; } Here i am opening a tmp file for writing. Then i am copying/moving for original file. Then i do a fflush, fsync(), ioctl() to the original file. Then i run this binary in linux machine(ext2 file system, 2.6.23.5 kernel) after that immediately power off the machine. Then power on machine, the file is disappeared or written data lost or file gets corrupted if i move the tmp file to the original file. And there is a no problem if i copy the tmp file to original file. So i want to know the difference between the cp and mv command. Can you please give me suggestion on it? Thanks, Indira. -------------- next part -------------- An HTML attachment was scrubbed... URL: From samuel at bcgreen.com Tue Jun 1 14:35:43 2010 From: samuel at bcgreen.com (Stephen Samuel) Date: Tue, 1 Jun 2010 07:35:43 -0700 Subject: File system structure difference between cp and mv linux commands In-Reply-To: References: Message-ID: Reading the man page for fsync: Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed. The difference between cp and mv is that mv simply adds a directory entry for the existing file in the destination directory. If the destination is on the same filesystem (mount point) then no file data is moved. The source directory entry is then deleted. cp, on the other hand will create a new file, and copy the data into there. So, with fsync on mv, there is no buffered data to be written. With fsync on cp, there IS data to be written, and it looks like the directory entry just happens to get flushed with the file data. It looks like there MAY be a bit of a bug with fsync not recognizing buffered data by a different name, but it should be written to recognize it by inode&device numbers, not name. On Tue, Jun 1, 2010 at 12:43 AM, Indira ramasamy wrote: > Hi, > > I am facing one problem only with mv command not with cp command. I have > a test program > > #include > #include > #include > #include > #include > #include > #include > > int sync_file(char *file) > { > FILE *fp=NULL; > int fd; > > printf("file is %s\n",file); > fp = fopen(file, "r"); > if(!fp) > return -1; > > fd = fileno(fp); > fflush(fp); > fsync(fd); > ioctl (fd, BLKFLSBUF, 0); > fclose(fp); > return 0; > > } > > int main() > { > int len=0; > FILE *fp = NULL; > char buf[1024]; > char *fname = "/etc/test.conf"; > char fname_tmp[129] = ""; > > > len = sprintf(buf, "%s\n", "Newly added Line is there"); > > snprintf(fname_tmp, 128, "%s.tmp", fname); > > if( (fp = fopen(fname_tmp,"a")) == NULL ) > printf(" ERROR: open(), error - %s\n",strerror(errno)); > > fprintf(fp,"%s",buf); > fflush(fp); > > fsync(fileno(fp)); > fclose(fp); > system("cp -f /etc/test.conf.tmp /etc/test.conf"); > // system("mv -f /etc/test.conf.tmp /etc/test.conf"); > sync_file(fname); > return 0; > } > > Here i am opening a tmp file for writing. Then i am copying/moving for > original file. Then i do a fflush, fsync(), ioctl() to the original file. > Then i run this binary in linux machine(ext2 file system, 2.6.23.5 kernel) > after that immediately power off the machine. Then power on machine, the > file is disappeared or written data lost or file gets corrupted if i move > the tmp file to the original file. And there is a no problem if i copy the > tmp file to original file. So i want to know the difference between the cp > and mv command. Can you please give me suggestion on it? > > Thanks, > Indira. > > _______________________________________________ > Ext3-users mailing list > Ext3-users at redhat.com > https://www.redhat.com/mailman/listinfo/ext3-users > -- Stephen Samuel http://www.bcgreen.com Software, like love, 778-861-7641 grows when you give it away -------------- next part -------------- An HTML attachment was scrubbed... URL: From lakshmipathi.g at gmail.com Wed Jun 2 04:57:32 2010 From: lakshmipathi.g at gmail.com (Lakshmipathi.G) Date: Wed, 2 Jun 2010 10:27:32 +0530 Subject: File system structure difference between cp and mv linux commands In-Reply-To: References: Message-ID: If you don't have any issue- in using system calls directly ,then instead of system("mv source target"). use - link ("source","target") // creat hard link unlink ("source") // remove old link [check "man 2 link" and "man 2 unlink" for more details] HTH On Tue, Jun 1, 2010 at 8:05 PM, Stephen Samuel wrote: > Reading the man page for fsync: > Calling fsync() does not necessarily ensure that the entry in the > directory containing the file has also reached disk. For that an explicit > fsync() on a file descriptor for the directory is also needed. > > > The difference between cp and mv is that mv simply adds a directory entry > for the existing file in the destination directory. If the destination is > on the same filesystem (mount point) then no file data is moved. The source > directory entry is then deleted. > > cp, on the other hand will create a new file, and copy the data into there. > > So, with fsync on mv, there is no buffered data to be written. > With fsync on cp, there IS data to be written, and it looks like the > directory entry just happens to get flushed with the file data. > > It looks like there MAY be a bit of a bug with fsync not recognizing > buffered data by a different name, but it should be written to recognize it > by inode&device numbers, not name. > > On Tue, Jun 1, 2010 at 12:43 AM, Indira ramasamy wrote: > >> Hi, >> >> I am facing one problem only with mv command not with cp command. I have >> a test program >> >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> >> int sync_file(char *file) >> { >> FILE *fp=NULL; >> int fd; >> >> printf("file is %s\n",file); >> fp = fopen(file, "r"); >> if(!fp) >> return -1; >> >> fd = fileno(fp); >> fflush(fp); >> fsync(fd); >> ioctl (fd, BLKFLSBUF, 0); >> fclose(fp); >> return 0; >> >> } >> >> int main() >> { >> int len=0; >> FILE *fp = NULL; >> char buf[1024]; >> char *fname = "/etc/test.conf"; >> char fname_tmp[129] = ""; >> >> >> len = sprintf(buf, "%s\n", "Newly added Line is there"); >> >> snprintf(fname_tmp, 128, "%s.tmp", fname); >> >> if( (fp = fopen(fname_tmp,"a")) == NULL ) >> printf(" ERROR: open(), error - %s\n",strerror(errno)); >> >> fprintf(fp,"%s",buf); >> fflush(fp); >> >> fsync(fileno(fp)); >> fclose(fp); >> system("cp -f /etc/test.conf.tmp /etc/test.conf"); >> // system("mv -f /etc/test.conf.tmp /etc/test.conf"); >> sync_file(fname); >> return 0; >> } >> >> Here i am opening a tmp file for writing. Then i am copying/moving for >> original file. Then i do a fflush, fsync(), ioctl() to the original file. >> Then i run this binary in linux machine(ext2 file system, 2.6.23.5 kernel) >> after that immediately power off the machine. Then power on machine, the >> file is disappeared or written data lost or file gets corrupted if i move >> the tmp file to the original file. And there is a no problem if i copy the >> tmp file to original file. So i want to know the difference between the cp >> and mv command. Can you please give me suggestion on it? >> >> Thanks, >> Indira. >> >> _______________________________________________ >> Ext3-users mailing list >> Ext3-users at redhat.com >> https://www.redhat.com/mailman/listinfo/ext3-users >> > > > > -- > Stephen Samuel http://www.bcgreen.com Software, like love, > 778-861-7641 grows when you give it away > > _______________________________________________ > Ext3-users mailing list > Ext3-users at redhat.com > https://www.redhat.com/mailman/listinfo/ext3-users > -- ---- Cheers, Lakshmipathi.G FOSS Programmer. www.giis.co.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From samuel at bcgreen.com Thu Jun 3 14:51:23 2010 From: samuel at bcgreen.com (Stephen Samuel) Date: Thu, 3 Jun 2010 07:51:23 -0700 Subject: File system structure difference between cp and mv linux commands In-Reply-To: References: Message-ID: If you do that, then you should probably be ready to use a 'cp', if the source and destination aren't on the same device (e.g. just in case /tmp becomes a separate filesystem) On Tue, Jun 1, 2010 at 9:57 PM, Lakshmipathi.G wrote: > If you don't have any issue- in using system calls directly ,then instead > of > system("mv source target"). > use - > link ("source","target") // creat hard link > unlink ("source") // remove old link > > [check "man 2 link" and "man 2 unlink" for more details] > -- Stephen Samuel http://www.bcgreen.com Software, like love, 778-861-7641 grows when you give it away -------------- next part -------------- An HTML attachment was scrubbed... URL: From dsh.mobyle at gmail.com Thu Jun 17 11:36:31 2010 From: dsh.mobyle at gmail.com (daniel-henry Ertzscheid) Date: Thu, 17 Jun 2010 13:36:31 +0200 Subject: Problem EXT3-fs error Message-ID: I have the following message in my / var / log / messages file system is on a SAN Redhat kernel: 2.6.9-78.0.1.ELsmp Jun 17 12:00:59 hostname kernel: EXT3-fs error (device dm-2): ext3_readdir: bad entry in directory #5293714: directory entry across blocks - offset=12, inode=2, rec_len=13732, name_len=2 Jun 17 12:00:59 hostname kernel: Aborting journal on device dm-2. Jun 17 12:00:59 hostname kernel: ext3_abort called. Jun 17 12:00:59 hostname kernel: EXT3-fs error (device dm-2): ext3_journal_start_sb: Detected aborted journal Jun 17 12:00:59 hostname kernel: Remounting filesystem read-only Jun 17 12:01:00 hostname kernel: EXT3-fs error (device dm-2) in start_transaction: Journal has aborted -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ralf.Hildebrandt at charite.de Thu Jun 17 11:43:14 2010 From: Ralf.Hildebrandt at charite.de (Ralf Hildebrandt) Date: Thu, 17 Jun 2010 13:43:14 +0200 Subject: Problem EXT3-fs error In-Reply-To: References: Message-ID: <20100617114314.GP18029@charite.de> * daniel-henry Ertzscheid : > I have the following message in my / var / log / messages > > file system is on a SAN > Redhat > kernel: 2.6.9-78.0.1.ELsmp > > Jun 17 12:00:59 hostname kernel: EXT3-fs error (device dm-2): ext3_readdir: > bad entry in directory #5293714: directory entry across blocks - offset=12, > inode=2, rec_len=13732, name_len=2 > Jun 17 12:00:59 hostname kernel: Aborting journal on device dm-2. > Jun 17 12:00:59 hostname kernel: ext3_abort called. > Jun 17 12:00:59 hostname kernel: EXT3-fs error (device dm-2): > ext3_journal_start_sb: Detected aborted journal > Jun 17 12:00:59 hostname kernel: Remounting filesystem read-only > Jun 17 12:01:00 hostname kernel: EXT3-fs error (device dm-2) in > start_transaction: Journal has aborted And what did fsck /dev/dm-2 report? -- Ralf Hildebrandt Gesch?ftsbereich IT | Abteilung Netzwerk Charit? - Universit?tsmedizin Berlin Campus Benjamin Franklin Hindenburgdamm 30 | D-12203 Berlin Tel. +49 30 450 570 155 | Fax: +49 30 450 570 962 ralf.hildebrandt at charite.de | http://www.charite.de From dsh.mobyle at gmail.com Thu Jun 17 12:44:21 2010 From: dsh.mobyle at gmail.com (daniel-henry Ertzscheid) Date: Thu, 17 Jun 2010 14:44:21 +0200 Subject: Problem EXT3-fs error In-Reply-To: <20100617114314.GP18029@charite.de> References: <20100617114314.GP18029@charite.de> Message-ID: The / dev/dm-2 corresponds to a fitting on a SAN Why the system puts the file system in read only? 2010/6/17 Ralf Hildebrandt > * daniel-henry Ertzscheid : > > I have the following message in my / var / log / messages > > > > file system is on a SAN > > Redhat > > kernel: 2.6.9-78.0.1.ELsmp > > > > Jun 17 12:00:59 hostname kernel: EXT3-fs error (device dm-2): > ext3_readdir: > > bad entry in directory #5293714: directory entry across blocks - > offset=12, > > inode=2, rec_len=13732, name_len=2 > > Jun 17 12:00:59 hostname kernel: Aborting journal on device dm-2. > > Jun 17 12:00:59 hostname kernel: ext3_abort called. > > Jun 17 12:00:59 hostname kernel: EXT3-fs error (device dm-2): > > ext3_journal_start_sb: Detected aborted journal > > Jun 17 12:00:59 hostname kernel: Remounting filesystem read-only > > Jun 17 12:01:00 hostname kernel: EXT3-fs error (device dm-2) in > > start_transaction: Journal has aborted > > And what did fsck /dev/dm-2 report? > > -- > Ralf Hildebrandt > Gesch?ftsbereich IT | Abteilung Netzwerk > Charit? - Universit?tsmedizin Berlin > Campus Benjamin Franklin > Hindenburgdamm 30 | D-12203 Berlin > Tel. +49 30 450 570 155 | Fax: +49 30 450 570 962 > ralf.hildebrandt at charite.de | http://www.charite.de > > > _______________________________________________ > Ext3-users mailing list > Ext3-users at redhat.com > https://www.redhat.com/mailman/listinfo/ext3-users -- Mr ERTZSCHEID Daniel-Henry Mobile : 0664503731 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ralf.Hildebrandt at charite.de Thu Jun 17 12:56:21 2010 From: Ralf.Hildebrandt at charite.de (Ralf Hildebrandt) Date: Thu, 17 Jun 2010 14:56:21 +0200 Subject: Problem EXT3-fs error In-Reply-To: References: <20100617114314.GP18029@charite.de> Message-ID: <20100617125621.GT18029@charite.de> * daniel-henry Ertzscheid : > The / dev/dm-2 corresponds to a fitting on a SAN Yes, so what? Errors happen. > Why the system puts the file system in read only? Because ext3 detected a EXT3-fs error -- Ralf Hildebrandt Gesch?ftsbereich IT | Abteilung Netzwerk Charit? - Universit?tsmedizin Berlin Campus Benjamin Franklin Hindenburgdamm 30 | D-12203 Berlin Tel. +49 30 450 570 155 | Fax: +49 30 450 570 962 ralf.hildebrandt at charite.de | http://www.charite.de From mike.miller at hp.com Thu Jun 17 16:08:14 2010 From: mike.miller at hp.com (Mike Miller) Date: Thu, 17 Jun 2010 11:08:14 -0500 Subject: kjournald blocked in D state Message-ID: <20100617160814.GA28084@beardog.cce.hp.com> I have a system on which kjournald becomes blocked in D state quite often. Looking at a core file we have 5 mounted ext3 filesystems: crash> mount VFSMOUNT SUPERBLK TYPE DEVNAME DIRNAME 10037e07b00 10037e4ec00 rootfs rootfs / 10037e07ec0 10037e4e400 proc /proc /proc 10037e07d40 102188abc00 tmpfs none /dev 10037e07e00 102188b2400 ext3 /dev/root / 10037e07200 102188abc00 tmpfs none /dev 10037e07140 10037e4e400 proc /proc /proc 1021652bc00 102188b1c00 usbfs /proc/bus/usb /proc/bus/usb 1021652bf00 10037e4c400 sysfs /sys /sys 1021652bb40 10006967400 devpts devpts /dev/pts 1021652b180 100dfeda400 ext3 /dev/cciss/c0d0p1 /boot 1021652b240 100dfecb800 ext3 /dev/sys/home /home 1021652b300 100dfecbc00 ext3 /dev/sys/tmp /tmp 1021652b3c0 100dfeda800 ext3 /dev/sys/var /var 1021652b480 100dfedac00 tmpfs tmpfs /dev/shm 1021652bcc0 100dfecb400 binfmt_misc none /proc/sys/fs/binfmt_misc So we have 5 corresponding journal threads: crash> ps | grep kjournald 626 1 2 10218109030 IN 0.0 0 0 [kjournald] 3015 1 0 102168f2030 IN 0.0 0 0 [kjournald] 3016 1 1 102168f27f0 UN 0.0 0 0 [kjournald] 3017 1 1 1021837b030 IN 0.0 0 0 [kjournald] 3018 1 7 10216fd0030 UN 0.0 0 0 [kjournald] 2 are in the UNITERRUPTIBLE state. But only PID 3018 shows __wait_on_buffer in its stack: crash> bt -f 3018 PID: 3018 TASK: 10216fd0030 CPU: 7 COMMAND: "kjournald" -----snip----- #2 [10215a83b30] __wait_on_buffer at ffffffff8017d504 10215a83b38: 000001005fa12ce8 0000000000000000 10215a83b48: 0000010216fd0030 ffffffff8017d38a 10215a83b58: 0000010215a83b88 0000010215a83b88 10215a83b68: 000001005fa12ce8 0000000000000000 10215a83b78: 0000010216fd0030 ffffffff8017d38a 10215a83b88: ffffffff804ac808 ffffffff804ac808 10215a83b98: 000001005fa12ce8 0000000000000001 10215a83ba8: 000001004f4e90e0 ffffffffa0080ffe -----snip----- I'm not a crash expert so I then looked the last address pushed onto its stack and traced down to the inode semaphore: crash> struct file.f_dentry 000001005fa12ce8 f_dentry = 0x1021f4e5510, crash> struct dentry.d_inode 0x1021f4e5510 d_inode = 0x100c95c17c0, crash> struct inode.i_sem 0x100c95c17c0 i_sem = { count = { counter = -916711312 <-------------------- This looks wrong }, sleepers = 256, wait = { lock = { lock = 497690456, magic = 258 }, task_list = { next = 0x100000000000, <--------------- This also looks wrong prev = 0x30f75c3 } } }, At this point I'm not sure how to continue or even if I went down the right path. From this info can anyone tell what's wrong? Or did I not go down the patch to reach this conclusion. -- mikem In this case /home is a heavily accessed filesystem. From lists at nerdbynature.de Sun Jun 20 07:44:37 2010 From: lists at nerdbynature.de (Christian Kujau) Date: Sun, 20 Jun 2010 00:44:37 -0700 (PDT) Subject: kjournald blocked in D state In-Reply-To: <20100617160814.GA28084@beardog.cce.hp.com> References: <20100617160814.GA28084@beardog.cce.hp.com> Message-ID: On Thu, 17 Jun 2010 at 11:08, Mike Miller wrote: > I have a system on which kjournald becomes blocked in D state quite often. Did this happen "just now", or after a kernel upgrade? Which kernel are you using? Do other systems (with the same kernel?) show similar behaviour? Christian. -- BOFH excuse #414: tachyon emissions overloading the system From mike.miller at hp.com Mon Jun 21 16:46:16 2010 From: mike.miller at hp.com (Mike Miller) Date: Mon, 21 Jun 2010 11:46:16 -0500 Subject: kjournald blocked in D state In-Reply-To: References: <20100617160814.GA28084@beardog.cce.hp.com> Message-ID: <20100621164616.GB28084@beardog.cce.hp.com> On Sun, Jun 20, 2010 at 12:44:37AM -0700, Christian Kujau wrote: > On Thu, 17 Jun 2010 at 11:08, Mike Miller wrote: > > I have a system on which kjournald becomes blocked in D state quite often. > > Did this happen "just now", or after a kernel upgrade? Which kernel are > you using? Do other systems (with the same kernel?) show similar > behaviour? The kernel is a 2.6.9 variant. According to the user 2.6.9-89 exhibits the problem. Kernel 2.6.9-78 does not appear to exhibit the problem. Aside from that I've seen the the symptoms written against 2.6.18 and 2.6.32 kernels. It's not easy to reproduce. The customer is using clusters of 50+ nodes all using internal storage. AFAIK, they are not sharing filesystems between nodes. The driver differences between the 2 kernels are minimal with nothing in the main code path. -- mikem > > Christian. > -- > BOFH excuse #414: > > tachyon emissions overloading the system