From: Andrew Himmer Subject: Multiple Renames in the Kernel (on Stackable FileSystems) Date: Mon, 31 Mar 2003 18:07:14 -0800 (PST) Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20030401020714.263.qmail@web11306.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: aphimmer@yahoo.com Return-path: To: linux-fsdevel@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Hello, I am writing code in the kernel, to change the names of multiple files at once. For instance, there is a set of files foo;1, foo;2, foo;3, foo;4, foo;5. I first delete foo;1. Then i want to rename foo;2, foo;3, foo;4, foo;5 to foo;1, foo;2, foo;3, foo;4. All this should be done in one operation called with an ioctl to my f/s. The state of the cache does not seem to be consistent right after these multiple cals to vfs_rename though.. My question is, if this is possible, or all operations as such meant to be atomic in the kernel (i.e. only possible with one 'mv' command from the shell at a time)?? My f/s is a stackable f/s. Here is my code to do renames. It is called multiple times one after the other, since each rename depends on the previous one's success (foo;2 to foo;1, then foo;3 to foo;2, then foo;4 to foo;3...). The file you are renaming to should not exist: int swap(char *name_from, char *name_to, dentry_t *upper_dir) { dentry_t *lower_to=NULL, *lower_from=NULL; dentry_t *upper_to=NULL, *upper_from=NULL; dentry_t *hidden_dir; ... ... upper_from = d_lookup(upper_dir, q_from); ... lower_from = d_lookup(hidden_dir, q_from); ... upper_to = lookup_one_len(name_to, upper_dir,..); ... vfs_create(upper_dir->d_inode, upper_to, ...); ... lower_to = d_lookup(hidden_dir, q_to); ... lock_kernel(); vfs_rename(upper_dir->d_inode, upper_from, upper_dir->d_inode, upper_to); unlock_kernel(); if (upper_to) dput(upper_to); if (lower_to) dput(lower_to); if (upper_from) dput(upper_from); if (lower_from) dput(lower_from); } i left out error checking to make the code shorter. The code works but is buggy. I can't figure out why. __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://platinum.yahoo.com