pass3.c revision b9a41fd39fb451c441a90e8959cb2dc2db84b497
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Use is subject to license terms.
03831d35f7499c87d51205817c93e9a8d42c4baestevel/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
03831d35f7499c87d51205817c93e9a8d42c4baestevel/* All Rights Reserved */
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * All rights reserved.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Redistribution and use in source and binary forms are permitted
03831d35f7499c87d51205817c93e9a8d42c4baestevel * provided that: (1) source distributions retain this entire copyright
03831d35f7499c87d51205817c93e9a8d42c4baestevel * notice and comment, and (2) distributions including binaries display
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the following acknowledgement: ``This product includes software
03831d35f7499c87d51205817c93e9a8d42c4baestevel * developed by the University of California, Berkeley and its contributors''
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in the documentation or other materials provided with the distribution
03831d35f7499c87d51205817c93e9a8d42c4baestevel * and in all advertising materials mentioning features or use of this
03831d35f7499c87d51205817c93e9a8d42c4baestevel * software. Neither the name of the University nor the names of its
03831d35f7499c87d51205817c93e9a8d42c4baestevel * contributors may be used to endorse or promote products derived
03831d35f7499c87d51205817c93e9a8d42c4baestevel * from this software without specific prior written permission.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
03831d35f7499c87d51205817c93e9a8d42c4baestevel * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
03831d35f7499c87d51205817c93e9a8d42c4baestevel * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
03831d35f7499c87d51205817c93e9a8d42c4baestevel#pragma ident "%Z%%M% %I% %E% SMI"
03831d35f7499c87d51205817c93e9a8d42c4baestevelstatic void setcurino(struct inodesc *, struct dinode *, struct inoinfo *);
03831d35f7499c87d51205817c93e9a8d42c4baestevel struct shadowclientinfo *sci, *sci_victim, *sci_prev, **sci_rootp;
03831d35f7499c87d51205817c93e9a8d42c4baestevel for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (state == DCLEAR || state == USTATE || (state & INORPHAN))
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If we are running with logging and we come
03831d35f7499c87d51205817c93e9a8d42c4baestevel * across unreferenced directories, we just leave
03831d35f7499c87d51205817c93e9a8d42c4baestevel * them in DSTATE which will cause them to be pitched
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in pass 4.
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (preen && !iscorrupt && islog && S_IS_DUNFOUND(state)) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Skip out if we aren't connected to the name
03831d35f7499c87d51205817c93e9a8d42c4baestevel * space, or our parent is connected, or we've
03831d35f7499c87d51205817c93e9a8d42c4baestevel * looked at too many directories. Our parent
03831d35f7499c87d51205817c93e9a8d42c4baestevel * being connected means that orphan is the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * first ancestor of *inpp with questionable
03831d35f7499c87d51205817c93e9a8d42c4baestevel * antecedents.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Can't happen, because a non-zero parent's already
03831d35f7499c87d51205817c93e9a8d42c4baestevel * been seen and therefore cached.
03831d35f7499c87d51205817c93e9a8d42c4baestevel "inode I=%d\n",
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Already did this one. Don't bother the user
03831d35f7499c87d51205817c93e9a8d42c4baestevel * with redundant questions.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * A link count of 0 with parent and .. inodes of 0
03831d35f7499c87d51205817c93e9a8d42c4baestevel * indicates a partly deleted directory.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Clear it.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * clri() just uses curino.id_number; in other
03831d35f7499c87d51205817c93e9a8d42c4baestevel * words, it won't use the callback that setcurino()
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If we didn't clear it, at least mark it so
03831d35f7499c87d51205817c93e9a8d42c4baestevel * we don't waste time on it again.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * We can call linkup() multiple times on the same directory
03831d35f7499c87d51205817c93e9a8d42c4baestevel * inode, if we were told not to reconnect it the first time.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * This is because we find it as a disconnected parent of
03831d35f7499c87d51205817c93e9a8d42c4baestevel * of its children (and mark it found), and then finally get
03831d35f7499c87d51205817c93e9a8d42c4baestevel * to it in the inpsort array. This is better than in the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * past, where we'd call it every time we found it as a
03831d35f7499c87d51205817c93e9a8d42c4baestevel * child's parent. Ideally, we'd suppress even the second
03831d35f7499c87d51205817c93e9a8d42c4baestevel * query, but that confuses pass 4's interpretation of
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the state flags.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Bookkeeping for any sort of relinked
03831d35f7499c87d51205817c93e9a8d42c4baestevel * directory.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * We visited more directories than exist in the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * filesystem. The only way to do that is if there's
03831d35f7499c87d51205817c93e9a8d42c4baestevel pfatal("ORPHANED DIRECTORY LOOP DETECTED I=%d\n", orphan);
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Can never get here with inp->i_parent zero, because
03831d35f7499c87d51205817c93e9a8d42c4baestevel * of the interactions between the for() and the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * if (loopcnt <= countdirs) above.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Theoretically, this lookup via ckinode can't fail
03831d35f7499c87d51205817c93e9a8d42c4baestevel * (if orphan doesn't exist in i_parent, then i_parent
03831d35f7499c87d51205817c93e9a8d42c4baestevel * would not have been filled in by pass2check()).
03831d35f7499c87d51205817c93e9a8d42c4baestevel * However, if we're interactive, we want to at least
03831d35f7499c87d51205817c93e9a8d42c4baestevel * attempt to continue. The worst case is that it
03831d35f7499c87d51205817c93e9a8d42c4baestevel * gets reconnected as #nnn into lost+found instead of
03831d35f7499c87d51205817c93e9a8d42c4baestevel * to its old parent with its old name.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Represents a on-disk leak, not an inconsistency,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * so don't set iscorrupt. Such leaks are harmless
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in the context of discrepancies that the kernel
03831d35f7499c87d51205817c93e9a8d42c4baestevel * will panic over.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * We don't care if tsearch() returns non-NULL
03831d35f7499c87d51205817c93e9a8d42c4baestevel * != orphan, since there's no dynamic memory
03831d35f7499c87d51205817c93e9a8d42c4baestevel * to free here.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The essence of the inner loop is to update the inode of
03831d35f7499c87d51205817c93e9a8d42c4baestevel * every shadow or attribute inode's lncntp[] by the number of
03831d35f7499c87d51205817c93e9a8d42c4baestevel * links we've found to them in pass 2 and above. Logically,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * all that is needed is just the one line:
03831d35f7499c87d51205817c93e9a8d42c4baestevel * lncntp[sci->shadow] -= sci->totalclients;
03831d35f7499c87d51205817c93e9a8d42c4baestevel * However, there's the possibility of wrapping the link count
03831d35f7499c87d51205817c93e9a8d42c4baestevel * (this is especially true for shadows, which are expected to
03831d35f7499c87d51205817c93e9a8d42c4baestevel * be shared amongst many files). This means that we have to
03831d35f7499c87d51205817c93e9a8d42c4baestevel * range-check before changing anything, and if the check
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fails, offer to clear the shadow or attribute. If we do
03831d35f7499c87d51205817c93e9a8d42c4baestevel * clear it, then we have to remove it from the linked list of
03831d35f7499c87d51205817c93e9a8d42c4baestevel * all of the type of inodes that we're going through.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Just to make things a little more complicated, these are
03831d35f7499c87d51205817c93e9a8d42c4baestevel * singly-linked lists, so we have to do all the extra
03831d35f7499c87d51205817c93e9a8d42c4baestevel * bookkeeping that goes along with that as well.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The only connection between the shadowclientinfo and
03831d35f7499c87d51205817c93e9a8d42c4baestevel * attrclientinfo lists is that they use the same underlying
03831d35f7499c87d51205817c93e9a8d42c4baestevel * struct. Both need this scan, so the outer loop is just to
03831d35f7499c87d51205817c93e9a8d42c4baestevel * pick which one we're working on at the moment. There is no
03831d35f7499c87d51205817c93e9a8d42c4baestevel * requirement as to which of these lists is scanned first.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Overflowed the link count.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * It's been cleared, fix the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If we did not clear the shadow, then we
03831d35f7499c87d51205817c93e9a8d42c4baestevel * need to update the count and advance the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * previous pointer. Otherwise, finish the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * clean up once we're done with the struct.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * This is used to verify the cflags of files
03831d35f7499c87d51205817c93e9a8d42c4baestevel * under a directory that used to be an attrdir.
03831d35f7499c87d51205817c93e9a8d42c4baestevel int n = 0, ret = 0;
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Accept DSTATE and DFOUND so we can handle normal
03831d35f7499c87d51205817c93e9a8d42c4baestevel * directories as well as xattr directories.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * For extended attribute directories .. may point
03831d35f7499c87d51205817c93e9a8d42c4baestevel * to a file. In this situation we don't want
03831d35f7499c87d51205817c93e9a8d42c4baestevel * to decrement link count as it was already
03831d35f7499c87d51205817c93e9a8d42c4baestevel * decremented when the entry was seen and decremented
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in the directory it actually lives in.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * IXATTR indicates that an object is itself an extended
03831d35f7499c87d51205817c93e9a8d42c4baestevel * attribute. An IFMT of IFATTRDIR means we are looking
03831d35f7499c87d51205817c93e9a8d42c4baestevel * at a directory which contains files which should all
03831d35f7499c87d51205817c93e9a8d42c4baestevel * have IXATTR set. The IFATTRDIR case was handled in
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Note that the following code actually handles
03831d35f7499c87d51205817c93e9a8d42c4baestevel * anything that's marked as an extended attribute but
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in a regular directory, not just files.
03831d35f7499c87d51205817c93e9a8d42c4baestevel "%s I=%d should NOT be marked as extended attribute\n",
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (n != 0)
03831d35f7499c87d51205817c93e9a8d42c4baestevel /* NOTREACHED */
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (n == 0)
03831d35f7499c87d51205817c93e9a8d42c4baestevelsetcurino(struct inodesc *idesc, struct dinode *dp, struct inoinfo *inp)