OpenSolaris

Printable Version Enter a New Search
Bug ID 6587767
Synopsis 'zpool create' get different behavior while mountpoint not empty but has file or dir
State 10-Fix Delivered (Fix available in build)
Category:Subcategory kernel:zfs
Keywords
Responsible Engineer Timothy Haley
Reported Against
Duplicate Of
Introduced In solaris_nevada
Commit to Fix snv_83
Fixed In snv_83
Release Fixed solaris_nevada(snv_83) , solaris_10u6(s10u6_01) (Bug ID:2160994)
Related Bugs
Submit Date 1-August-2007
Last Update Date 29-April-2008
Description
Bfu to onnv-gate:2007-07-31, while create pool, if the default mountpoint or 
specified by '-m' exist but not empty, it get different behavior while it has file or sub-dir.

I also tried 'zpool import' and found it will import that pool anyway although
it cannot be mounted. 

So looks like the behavior a bit inconsistent and need to verify.

# rm -rf /tank/*

(1) has file, the pool just be created but unable to mount

# touch /tank/file0
# zpool create tank c0t0d0s0
cannot mount '/tank': directory is not empty
# echo $?
1
# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
tank                     68G     94K   68.0G     0%  ONLINE     -
# zfs mount



(2) has directory, the pool cannot be created. 
# zpool destroy tank
# rm -rf /tank/*
# mkdir /tank/dir0
# zpool create tank c0t0d0s0
default mountpoint '/tank' exists and is not empty
use '-m' option to provide a different default
# echo $?
1
# zpool list
no pools available


src/cmd/zpool/zpool_main.c
    716 		if (stat64(buf, &statbuf) == 0 &&
    717 		    statbuf.st_nlink != 2) {
    718 			if (mountpoint == NULL)
    719 				(void) fprintf(stderr, gettext("default "
    720 				    "mountpoint '%s' exists and is not "
    721 				    "empty\n"), buf);
    722 			else
    723 				(void) fprintf(stderr, gettext("mountpoint "
    724 				    "'%s' exists and is not empty\n"), buf);
    725 			(void) fprintf(stderr, gettext("use '-m' "
    726 			    "option to provide a different default\n"));
I believe the only fs-agnostic way to determine if a 
directory is empty would be to readdir() it and see if 
there are any entries besides "." and ".." -- that's 
what we should be doing here.  (either that or rmdir()
it and then just rely on the mountpoint creation code
to re-mkdir() it)
Work Around
N/A
Comments
N/A