nfs-ganesha 1.4

test_ns.c

Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include "config.h"
00003 #endif
00004 
00005 #include "namespace.h"
00006 
00007 typedef struct ns_testset__
00008 {
00009   ino_t parent_inode;
00010   ino_t entry_inode;
00011   char *name;
00012 } ns_testset_t;
00013 
00014 #define ROOT_INODE  ((ino_t)1)
00015 #define DEV ((dev_t)1)
00016 
00017 /* Test set */
00018 ns_testset_t testset[] = {
00019   {ROOT_INODE, ROOT_INODE + 1, "dir1"},
00020   {ROOT_INODE, ROOT_INODE + 2, "dir2"},
00021   {ROOT_INODE, ROOT_INODE + 3, "dir3"},
00022   {ROOT_INODE, ROOT_INODE + 4, "dir4"},
00023   {ROOT_INODE + 4, ROOT_INODE + 5, "file1"},
00024   {ROOT_INODE + 4, ROOT_INODE + 6, "file2"},
00025   {ROOT_INODE + 4, ROOT_INODE + 7, "subdir1"},
00026   {ROOT_INODE + 4, ROOT_INODE + 8, "subdir2"},
00027   {ROOT_INODE + 8, ROOT_INODE + 9, "file1"},
00028   {ROOT_INODE + 8, ROOT_INODE + 10, "file2"},
00029   {ROOT_INODE + 8, ROOT_INODE + 10, "file2.harlink"},   /* same inode = hardlink */
00030   {ROOT_INODE, ROOT_INODE + 11, "dir5"},
00031   {ROOT_INODE + 11, ROOT_INODE + 10, "file2.hardlink"}, /* same inode = another hardlink */
00032 
00033   {0, 0, NULL}                  /* end of list */
00034 
00035 };
00036 
00037 int main(int argc, char **argv)
00038 {
00039   int rc, i;
00040   ns_testset_t *p_test;
00041   char path[FSAL_MAX_PATH_LEN];
00042   unsigned int gen = 0;
00043   unsigned int dev = DEV;
00044 
00045   /* Init logging */
00046 
00047   SetNamePgm("test_ns");
00048   SetDefaultLogging("TEST");
00049   SetNameFunction("main");
00050   InitLogging();
00051 
00052   /* namespace init */
00053   rc = NamespaceInit(ROOT_INODE, DEV, &gen);
00054   if(rc)
00055     {
00056       LogTest("NamespaceInit rc=%d\n", rc);
00057       exit(1);
00058     }
00059 
00060   for(i = 0; i < 2; i++)
00061     {
00062 
00063       /* creation des entrees */
00064       for(p_test = testset; p_test->name != NULL; p_test++)
00065         {
00066           rc = NamespaceAdd(p_test->parent_inode, DEV, gen, p_test->name,
00067                             p_test->entry_inode, DEV, &gen);
00068           LogTest("NamespaceAdd(%lu,%s->%lu) = %d\n", p_test->parent_inode, p_test->name,
00069                  p_test->entry_inode, rc);
00070           if(rc)
00071             exit(1);            /* This is an error */
00072         }
00073 
00074       /* tentative de recreation */
00075       for(p_test = testset; p_test->name != NULL; p_test++)
00076         {
00077           rc = NamespaceAdd(p_test->parent_inode, DEV, gen, p_test->name,
00078                             p_test->entry_inode, DEV, &gen);
00079           LogTest("Redundant NamespaceAdd(%lu,%s->%lu) = %d\n", p_test->parent_inode,
00080                  p_test->name, p_test->entry_inode, rc);
00081           if(rc)
00082             exit(1);            /* This is an error */
00083         }
00084 
00085       /* recolte du chemin complet de root */
00086 
00087       rc = NamespacePath(ROOT_INODE, DEV, gen, path);
00088       if(rc)
00089         {
00090           LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE, rc);
00091           exit(1);
00092         }
00093       else
00094         LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE, path);
00095 
00096       /* recolte du chemin complet des entrees */
00097 
00098       for(p_test = testset; p_test->name != NULL; p_test++)
00099         {
00100           rc = NamespacePath(p_test->entry_inode, DEV, gen, path);
00101           if(rc)
00102             {
00103               LogTest("NamespacePath(%lu) rc=%d\n", p_test->entry_inode, rc);
00104               exit(1);
00105             }
00106           else
00107             LogTest("NamespacePath(%lu) => \"%s\"\n", p_test->entry_inode, path);
00108         }
00109 
00110       /* on efface les entrees en ordre inverse */
00111       for(p_test--; p_test >= testset; p_test--)
00112         {
00113           rc = NamespaceRemove(p_test->parent_inode, DEV, gen, p_test->name);
00114           LogTest("NamespaceRemove(%lu,%s) = %d\n", p_test->parent_inode,
00115                  p_test->name, rc);
00116         }
00117 
00118       /* on essaye d'obtenir leur nom */
00119       for(p_test = testset; p_test->name != NULL; p_test++)
00120         {
00121           rc = NamespacePath(p_test->entry_inode, DEV, gen, path);
00122           if(rc == 0)
00123             {
00124               LogTest("NamespacePath(%lu) => \"%s\"\n", p_test->entry_inode, path);
00125               exit(1);
00126             }
00127           else if(rc != ENOENT)
00128             {
00129               LogTest("NamespacePath(%lu) rc=%d\n", p_test->entry_inode, rc);
00130               exit(1);
00131             }
00132           else
00133             LogTest("NamespacePath(%lu) rc=%d (ENOENT)\n", p_test->entry_inode, rc);
00134         }
00135     }
00136 
00137   /* now create/remove a hardlink to a file N times */
00138 
00139   rc = NamespaceAdd(ROOT_INODE, DEV, gen, "dir", ROOT_INODE + 1, DEV, &gen);
00140   if(rc)
00141     {
00142       LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1);
00143       exit(1);
00144     }
00145 
00146   rc = NamespaceAdd(ROOT_INODE + 1, DEV, gen, "subdir", ROOT_INODE + 2, DEV, &gen);
00147   if(rc)
00148     {
00149       LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1);
00150       exit(1);
00151     }
00152 
00153   rc = NamespaceAdd(ROOT_INODE + 2, DEV, gen, "entry", ROOT_INODE + 3, DEV, &gen);
00154   if(rc)
00155     {
00156       LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1);
00157       exit(1);
00158     }
00159 
00160   /* create hardlinks and lookup */
00161   for(i = 0; i < 3; i++)
00162     {
00163       char name[FSAL_MAX_NAME_LEN];
00164 
00165       sprintf(name, "entry.hl%d", i);
00166 
00167       rc = NamespaceAdd(ROOT_INODE + 2, DEV, gen, name, ROOT_INODE + 3, DEV, &gen);
00168       LogTest("NamespaceAdd(%lu,%s->%lu) = %d\n", ROOT_INODE + 2, name, ROOT_INODE + 3,
00169              rc);
00170       if(rc)
00171         exit(1);
00172 
00173       rc = NamespacePath(ROOT_INODE + 3, DEV, gen, path);
00174       if(rc)
00175         {
00176           LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE + 3, rc);
00177           exit(1);
00178         }
00179       else
00180         LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE + 3, path);
00181 
00182     }
00183 
00184   /* delete hardlinks and lookup */
00185   for(i = 0; i < 3; i++)
00186     {
00187       char name[FSAL_MAX_NAME_LEN];
00188 
00189       sprintf(name, "entry.hl%d", i);
00190 
00191       rc = NamespaceRemove(ROOT_INODE + 2, DEV, gen, name);
00192       LogTest("NamespaceRemove(%lu,%s) = %d\n", ROOT_INODE + 2, name, rc);
00193       if(rc)
00194         exit(1);
00195 
00196       rc = NamespacePath(ROOT_INODE + 3, DEV, gen, path);
00197       if(rc)
00198         {
00199           LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE + 3, rc);
00200           exit(1);
00201         }
00202       else
00203         LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE + 3, path);
00204 
00205     }
00206 
00207   return 0;
00208 
00209 }