/* * Either iAlloc() or txBegin() may block. Deadlock can occur if we * block there while holding dtree page, so we allocate the inode & * begin the transaction before we search the directory.
*/
ip = ialloc(dip, mode); if (IS_ERR(ip)) {
rc = PTR_ERR(ip); goto out2;
}
/* * Either iAlloc() or txBegin() may block. Deadlock can occur if we * block there while holding dtree page, so we allocate the inode & * begin the transaction before we search the directory.
*/
ip = ialloc(dip, S_IFDIR | mode); if (IS_ERR(ip)) {
rc = PTR_ERR(ip); goto out2;
}
/* * NAME: jfs_rmdir(dip, dentry) * * FUNCTION: remove a link to child directory * * PARAMETER: dip - parent inode * dentry - child directory dentry * * RETURN: -EINVAL - if name is . or .. * -EINVAL - if . or .. exist but are invalid. * errors from subroutines * * note: * if other threads have the directory open when the last link * is removed, the "." and ".." entries, if present, are removed before * rmdir() returns and no new entries may be created in the directory, * but the directory is not removed until the last reference to * the directory is released (cf.unlink() of regular file).
*/ staticint jfs_rmdir(struct inode *dip, struct dentry *dentry)
{ int rc;
tid_t tid; /* transaction id */ struct inode *ip = d_inode(dentry);
ino_t ino; struct component_name dname; struct inode *iplist[2]; struct tblock *tblk;
/* * delete the entry of target directory from parent directory
*/
ino = ip->i_ino; if ((rc = dtDelete(tid, dip, &dname, &ino, JFS_REMOVE))) {
jfs_err("jfs_rmdir: dtDelete returned %d", rc); if (rc == -EIO)
txAbort(tid, 1);
txEnd(tid);
mutex_unlock(&JFS_IP(ip)->commit_mutex);
mutex_unlock(&JFS_IP(dip)->commit_mutex);
goto out2;
}
/* update parent directory's link count corresponding * to ".." entry of the target directory deleted
*/
inode_set_mtime_to_ts(dip, inode_set_ctime_current(dip));
inode_dec_link_count(dip);
/* * OS/2 could have created EA and/or ACL
*/ /* free EA from both persistent and working map */ if (JFS_IP(ip)->ea.flag & DXD_EXTENT) { /* free EA pages */
txEA(tid, ip, &JFS_IP(ip)->ea, NULL);
}
JFS_IP(ip)->ea.flag = 0;
/* free ACL from both persistent and working map */ if (JFS_IP(ip)->acl.flag & DXD_EXTENT) { /* free ACL pages */
txEA(tid, ip, &JFS_IP(ip)->acl, NULL);
}
JFS_IP(ip)->acl.flag = 0;
/* mark the target directory as deleted */
clear_nlink(ip);
mark_inode_dirty(ip);
/* * Truncating the directory index table is not guaranteed. It * may need to be done iteratively
*/ if (test_cflag(COMMIT_Stale, dip)) { if (dip->i_size > 1)
jfs_truncate_nolock(dip, 0);
/* * NAME: jfs_unlink(dip, dentry) * * FUNCTION: remove a link to object <vp> named by <name> * from parent directory <dvp> * * PARAMETER: dip - inode of parent directory * dentry - dentry of object to be removed * * RETURN: errors from subroutines * * note: * temporary file: if one or more processes have the file open * when the last link is removed, the link will be removed before * unlink() returns, but the removal of the file contents will be * postponed until all references to the files are closed. * * JFS does NOT support unlink() on directories. *
*/ staticint jfs_unlink(struct inode *dip, struct dentry *dentry)
{ int rc;
tid_t tid; /* transaction id */ struct inode *ip = d_inode(dentry);
ino_t ino; struct component_name dname; /* object name */ struct inode *iplist[2]; struct tblock *tblk;
s64 new_size = 0; int commit_flag;
/* * Incomplete truncate of file data can * result in timing problems unless we synchronously commit the * transaction.
*/ if (new_size)
commit_flag = COMMIT_SYNC; else
commit_flag = 0;
/* * If xtTruncate was incomplete, commit synchronously to avoid * timing complications
*/
rc = txCommit(tid, 2, &iplist[0], commit_flag);
if (ip->i_nlink == 0)
set_cflag(COMMIT_Nolink, ip);
IWRITE_UNLOCK(ip);
/* * Truncating the directory index table is not guaranteed. It * may need to be done iteratively
*/ if (test_cflag(COMMIT_Stale, dip)) { if (dip->i_size > 1)
jfs_truncate_nolock(dip, 0);
/* * NAME: commitZeroLink() * * FUNCTION: for non-directory, called by jfs_remove(), * truncate a regular file, directory or symbolic * link to zero length. return 0 if type is not * one of these. * * if the file is currently associated with a VM segment * only permanent disk and inode map resources are freed, * and neither the inode nor indirect blocks are modified * so that the resources can be later freed in the work * map by ctrunc1. * if there is no VM segment on entry, the resources are * freed in both work and permanent map. * (? for temporary file - memory object is cached even * after no reference: * reference count > 0 - ) * * PARAMETERS: cd - pointer to commit data structure. * current inode is the one to truncate. * * RETURN: Errors from subroutines
*/ static s64 commitZeroLink(tid_t tid, struct inode *ip)
{ int filetype; struct tblock *tblk;
jfs_info("commitZeroLink: tid = %d, ip = 0x%p", tid, ip);
filetype = ip->i_mode & S_IFMT; switch (filetype) { case S_IFREG: break; case S_IFLNK: /* fast symbolic link */ if (ip->i_size < IDATASIZE) {
ip->i_size = 0; return 0;
} break; default:
assert(filetype != S_IFDIR); return 0;
}
set_cflag(COMMIT_Freewmap, ip);
/* mark transaction of block map update type */
tblk = tid_to_tblock(tid);
tblk->xflag |= COMMIT_PMAP;
/* * free EA
*/ if (JFS_IP(ip)->ea.flag & DXD_EXTENT) /* acquire maplock on EA to be freed from block map */
txEA(tid, ip, &JFS_IP(ip)->ea, NULL);
/* * free ACL
*/ if (JFS_IP(ip)->acl.flag & DXD_EXTENT) /* acquire maplock on EA to be freed from block map */
txEA(tid, ip, &JFS_IP(ip)->acl, NULL);
/* * free xtree/data (truncate to zero length): * free xtree/data pages from cache if COMMIT_PWMAP, * free xtree/data blocks from persistent block map, and * free xtree/data blocks from working block map if COMMIT_PWMAP;
*/ if (ip->i_size) return xtTruncate_pmap(tid, ip, 0);
return 0;
}
/* * NAME: jfs_free_zero_link() * * FUNCTION: for non-directory, called by iClose(), * free resources of a file from cache and WORKING map * for a file previously committed with zero link count * while associated with a pager object, * * PARAMETER: ip - pointer to inode of file.
*/ void jfs_free_zero_link(struct inode *ip)
{ int type;
jfs_info("jfs_free_zero_link: ip = 0x%p", ip);
/* return if not reg or symbolic link or if size is * already ok.
*/
type = ip->i_mode & S_IFMT;
switch (type) { case S_IFREG: break; case S_IFLNK: /* if its contained in inode nothing to do */ if (ip->i_size < IDATASIZE) return; break; default: return;
}
/* * free EA
*/ if (JFS_IP(ip)->ea.flag & DXD_EXTENT) {
s64 xaddr = addressDXD(&JFS_IP(ip)->ea); int xlen = lengthDXD(&JFS_IP(ip)->ea); struct maplock maplock; /* maplock for COMMIT_WMAP */ struct pxd_lock *pxdlock; /* maplock for COMMIT_WMAP */
/* free EA pages from cache */
invalidate_dxd_metapages(ip, JFS_IP(ip)->ea);
/* * free xtree/data (truncate to zero length): * free xtree/data pages from cache, and * free xtree/data blocks from working block map;
*/ if (ip->i_size)
xtTruncate(0, ip, 0, COMMIT_WMAP);
}
/* * NAME: jfs_link(vp, dvp, name, crp) * * FUNCTION: create a link to <vp> by the name = <name> * in the parent directory <dvp> * * PARAMETER: vp - target object * dvp - parent directory of new link * name - name of new link to target object * crp - credential * * RETURN: Errors from subroutines * * note: * JFS does NOT support link() on directories (to prevent circular * path in the directory hierarchy); * EPERM: the target object is a directory, and either the caller * does not have appropriate privileges or the implementation prohibits * using link() on directories [XPG4.2]. * * JFS does NOT support links between file systems: * EXDEV: target object and new link are on different file systems and * implementation does not support links between file systems [XPG4.2].
*/ staticint jfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
{ int rc;
tid_t tid; struct inode *ip = d_inode(old_dentry);
ino_t ino; struct component_name dname; struct btstack btstack; struct inode *iplist[2];
/* * NAME: jfs_symlink(dip, dentry, name) * * FUNCTION: creates a symbolic link to <symlink> by name <name> * in directory <dip> * * PARAMETER: dip - parent directory vnode * dentry - dentry of symbolic link * name - the path name of the existing object * that will be the source of the link * * RETURN: errors from subroutines * * note: * ENAMETOOLONG: pathname resolution of a symbolic link produced * an intermediate result whose length exceeds PATH_MAX [XPG4.2]
*/
/* * if symlink is > 128 bytes, we don't have the space to * store inline extended attributes
*/ if (ssize > sizeof (JFS_IP(ip)->i_inline))
JFS_IP(ip)->mode2 &= ~INLINEEA;
jfs_info("jfs_symlink: fast symlink added ssize:%u name:%s ",
ssize, name);
} /* * write source path name in a single extent
*/ else {
jfs_info("jfs_symlink: allocate extent ip:0x%p", ip);
if ((rc = get_UCSname(&old_dname, old_dentry))) goto out1;
if ((rc = get_UCSname(&new_dname, new_dentry))) goto out2;
/* * Make sure source inode number is what we think it is
*/
rc = dtSearch(old_dir, &old_dname, &ino, &btstack, JFS_LOOKUP); if (rc || (ino != old_ip->i_ino)) {
rc = -ENOENT; goto out3;
}
/* * Make sure dest inode number (if any) is what we think it is
*/
rc = dtSearch(new_dir, &new_dname, &ino, &btstack, JFS_LOOKUP); if (!rc) { if ((!new_ip) || (ino != new_ip->i_ino)) {
rc = -ESTALE; goto out3;
}
} elseif (rc != -ENOENT) goto out3; elseif (new_ip) { /* no entry exists, but one was expected */
rc = -ESTALE; goto out3;
}
if (S_ISDIR(old_ip->i_mode)) { if (new_ip) { if (!dtEmpty(new_ip)) {
rc = -ENOTEMPTY; goto out3;
}
}
} elseif (new_ip) {
IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL); /* Init inode for quota operations. */
rc = dquot_initialize(new_ip); if (rc) goto out_unlock;
}
/* * The real work starts here
*/
tid = txBegin(new_dir->i_sb, 0);
/* * How do we know the locking is safe from deadlocks? * The vfs does the hard part for us. Any time we are taking nested * commit_mutexes, the vfs already has i_mutex held on the parent. * Here, the vfs has already taken i_mutex on both old_dir and new_dir.
*/
mutex_lock_nested(&JFS_IP(new_dir)->commit_mutex, COMMIT_MUTEX_PARENT);
mutex_lock_nested(&JFS_IP(old_ip)->commit_mutex, COMMIT_MUTEX_CHILD); if (old_dir != new_dir)
mutex_lock_nested(&JFS_IP(old_dir)->commit_mutex,
COMMIT_MUTEX_SECOND_PARENT);
ino = old_ip->i_ino;
rc = dtInsert(tid, new_dir, &new_dname, &ino, &btstack); if (rc) { if (rc == -EIO)
jfs_err("jfs_rename: dtInsert returned -EIO"); goto out_tx;
} if (S_ISDIR(old_ip->i_mode))
inc_nlink(new_dir);
} /* * Remove old directory entry
*/
ino = old_ip->i_ino;
rc = dtDelete(tid, old_dir, &old_dname, &ino, JFS_REMOVE); if (rc) {
jfs_err("jfs_rename did not expect dtDelete to return rc = %d",
rc);
txAbort(tid, 1); /* Marks Filesystem dirty */ goto out_tx;
} if (S_ISDIR(old_ip->i_mode)) {
drop_nlink(old_dir); if (old_dir != new_dir) { /* * Change inode number of parent for moved directory
*/
/* Build list of inodes modified by this transaction */
ipcount = 0;
iplist[ipcount++] = old_ip; if (new_ip)
iplist[ipcount++] = new_ip;
iplist[ipcount++] = old_dir;
/* * Incomplete truncate of file data can * result in timing problems unless we synchronously commit the * transaction.
*/ if (new_size)
commit_flag = COMMIT_SYNC; else
commit_flag = 0;
rc = txCommit(tid, ipcount, iplist, commit_flag);
out_tx:
txEnd(tid); if (new_ip)
mutex_unlock(&JFS_IP(new_ip)->commit_mutex); if (old_dir != new_dir)
mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
while (new_size && (rc == 0)) {
tid = txBegin(new_ip->i_sb, 0);
mutex_lock(&JFS_IP(new_ip)->commit_mutex);
new_size = xtTruncate_pmap(tid, new_ip, new_size); if (new_size < 0) {
txAbort(tid, 1);
rc = new_size;
} else
rc = txCommit(tid, 1, &new_ip, COMMIT_SYNC);
txEnd(tid);
mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
} if (new_ip && (new_ip->i_nlink == 0))
set_cflag(COMMIT_Nolink, new_ip); /* * Truncating the directory index table is not guaranteed. It * may need to be done iteratively
*/ if (test_cflag(COMMIT_Stale, old_dir)) { if (old_dir->i_size > 1)
jfs_truncate_nolock(old_dir, 0);
hash = init_name_hash(dir); for (i=0; i < this->len; i++)
hash = partial_name_hash(tolower(this->name[i]), hash);
this->hash = end_name_hash(hash);
return 0;
}
staticint jfs_ci_compare(conststruct dentry *dentry, unsignedint len, constchar *str, conststruct qstr *name)
{ int i, result = 1;
if (len != name->len) goto out; for (i=0; i < len; i++) { if (tolower(str[i]) != tolower(name->name[i])) goto out;
}
result = 0;
out: return result;
}
staticint jfs_ci_revalidate(struct inode *dir, conststruct qstr *name, struct dentry *dentry, unsignedint flags)
{ /* * This is not negative dentry. Always valid. * * Note, rename() to existing directory entry will have ->d_inode, * and will use existing name which isn't specified name by user. * * We may be able to drop this positive dentry here. But dropping * positive dentry isn't good idea. So it's unsupported like * rename("filename", "FILENAME") for now.
*/ if (d_really_is_positive(dentry)) return 1;
/* * This may be nfsd (or something), anyway, we can't see the * intent of this. So, since this can be for creation, drop it.
*/ if (!flags) return 0;
/* * Drop the negative dentry, in order to make sure to use the * case sensitive name which is specified by user if this is * for creation.
*/ if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) return 0; return 1;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.42Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.