From d26145606529756389f07c2e518ca841ecbf8d6c Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 28 Jun 2004 17:29:42 +0000 Subject: [PATCH] freelance-rw-mounts-20040626 Extend Freelance code to support r/w mount points in the fake root.afs volume --- src/WINNT/afsd/cm_freelance.c | 139 +++++++++++++++++++--------------- src/WINNT/afsd/cm_freelance.h | 2 +- src/WINNT/afsd/cm_ioctl.c | 3 +- src/WINNT/afsd/cm_vnodeops.c | 3 +- 4 files changed, 82 insertions(+), 65 deletions(-) diff --git a/src/WINNT/afsd/cm_freelance.c b/src/WINNT/afsd/cm_freelance.c index b3ed545f7..0280852f1 100644 --- a/src/WINNT/afsd/cm_freelance.c +++ b/src/WINNT/afsd/cm_freelance.c @@ -45,7 +45,7 @@ void cm_InitFreelance() { // yj: first we make a call to cm_initLocalMountPoints // to read all the local mount points from an ini file cm_InitLocalMountPoints(); - + // then we make a call to InitFakeRootDir to create // a fake root directory based on the local mount points cm_InitFakeRootDir(); @@ -346,7 +346,7 @@ int cm_reInitLocalMountPoints() { long cm_InitLocalMountPoints() { FILE *fp; - char line[200]; + char line[512]; int i; char* t; cm_localMountPoint_t* aLocalMountPoint; @@ -359,10 +359,21 @@ long cm_InitLocalMountPoints() { // if we fail to open the file, create an empty one if (!fp) { - fp = fopen(hdir, "w"); - fputs("0\n", fp); - fclose(fp); - return 0; /* success */ + long code; + char rootCellName[256]; + fp = fopen(hdir, "w"); + code = cm_GetRootCellName(rootCellName); + if (code == 0) { + fputs("1\n", fp); + fprintf(fp,"%s#%s:root.cell.\n",rootCellName,rootCellName); + fprintf(fp,".%s%%%s:root.cell.\n",rootCellName,rootCellName); + fclose(fp); + fopen(hdir, "r"); + } else { + fputs("0\n", fp); + fclose(fp); + return 0; /* success */ + } } // we successfully opened the file @@ -370,7 +381,7 @@ long cm_InitLocalMountPoints() { // now we read the first line to see how many entries // there are - fgets(line, 200, fp); + fgets(line, sizeof(line), fp); // if the line is empty at any point when we're reading // we're screwed. report error and return. @@ -396,7 +407,7 @@ long cm_InitLocalMountPoints() { // entry name, yyy is the cell name and zzz is the volume name. // #yyy:zzz together make up the mount point. for (i=0; inamep=malloc(t-line+1); memcpy(aLocalMountPoint->namep, line, t-line); *(aLocalMountPoint->namep + (t-line)) = 0; - aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1); + + aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1); memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2); *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0; osi_Log2(afsd_logp,"found mount point: name %s, string %s", - aLocalMountPoint->namep, - aLocalMountPoint->mountPointStringp); + aLocalMountPoint->namep, + aLocalMountPoint->mountPointStringp); aLocalMountPoint++; } @@ -428,7 +442,6 @@ long cm_InitLocalMountPoints() { return 0; } - int cm_getNoLocalMountPoints() { return cm_noLocalMountPoints; } @@ -437,11 +450,11 @@ cm_localMountPoint_t* cm_getLocalMountPoint(int vnode) { return 0; } -long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t *fidp) +long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp) { FILE *fp; char hfile[120]; - char line[200]; + char line[512]; char fullname[200]; int n; int alias = 0; @@ -450,8 +463,8 @@ long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t don't add the mount point. allow partial matches as a means of poor man's alias. */ /* major performance issue? */ - osi_Log3(afsd_logp,"Freelance Add Mount request: filename=%s cellname=%s volume=%s", - filename, cellname, volume); + osi_Log3(afsd_logp,"Freelance Add Mount request: filename=%s cellname=%s volume=%s %s", + filename, cellname, volume, rw ? "rw" : "ro"); if (cellname[0] == '.') { if (!cm_GetCell_Gen(&cellname[1], &fullname[1], CM_FLAG_CREATE)) return -1; @@ -465,36 +478,38 @@ long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t lock_ObtainMutex(&cm_Freelance_Lock); - cm_GetConfigDir(hfile); - strcat(hfile, AFS_FREELANCE_INI); - fp = fopen(hfile, "r+"); - if (!fp) - return CM_ERROR_INVAL; - fgets(line, 200, fp); - n = atoi(line); - n++; - fseek(fp, 0, SEEK_SET); - fprintf(fp, "%d", n); - fseek(fp, 0, SEEK_END); - fprintf(fp, "%s#%s:%s\n", filename, fullname, volume); - fclose(fp); - lock_ReleaseMutex(&cm_Freelance_Lock); - - /* cm_reInitLocalMountPoints(); */ - if (fidp) { - fidp->unique = 1; - fidp->vnode = cm_noLocalMountPoints + 1; /* vnode value of last mt pt */ - } - cm_noteLocalMountPointChange(); - - return 0; + cm_GetConfigDir(hfile); + strcat(hfile, AFS_FREELANCE_INI); + fp = fopen(hfile, "r+"); + if (!fp) + return CM_ERROR_INVAL; + fgets(line, sizeof(line), fp); + n = atoi(line); + n++; + fseek(fp, 0, SEEK_SET); + fprintf(fp, "%d", n); + fseek(fp, 0, SEEK_END); + if (rw) + fprintf(fp, "%s%%%s:%s\n", filename, fullname, volume); + else + fprintf(fp, "%s#%s:%s\n", filename, fullname, volume); + fclose(fp); + lock_ReleaseMutex(&cm_Freelance_Lock); + + /* cm_reInitLocalMountPoints(); */ + if (fidp) { + fidp->unique = 1; + fidp->vnode = cm_noLocalMountPoints + 1; /* vnode value of last mt pt */ + } + cm_noteLocalMountPointChange(); + return 0; } long cm_FreelanceRemoveMount(char *toremove) { int i, n; char* cp; - char line[200]; + char line[512]; char shortname[200]; char hfile[120], hfile2[120]; FILE *fp1, *fp2; @@ -515,36 +530,38 @@ long cm_FreelanceRemoveMount(char *toremove) return CM_ERROR_INVAL; } - fgets(line, 200, fp1); + fgets(line, sizeof(line), fp1); n=atoi(line); fprintf(fp2, "%d\n", n-1); for (i=0; iinDatap == '%', NULL); return code; } #endif diff --git a/src/WINNT/afsd/cm_vnodeops.c b/src/WINNT/afsd/cm_vnodeops.c index 3fc9bbf5d..d03bf1aac 100644 --- a/src/WINNT/afsd/cm_vnodeops.c +++ b/src/WINNT/afsd/cm_vnodeops.c @@ -1011,8 +1011,7 @@ long cm_Lookup(cm_scache_t *dscp, char *namep, long flags, cm_user_t *userp, } else { /* nonexistent dir on freelance root, so add it */ osi_Log1(afsd_logp,"cm_Lookup adding mount for non-existent directory: %s", namep); - code = cm_FreelanceAddMount(namep, namep, "root.cell.", - &rock.fid); + code = cm_FreelanceAddMount(namep, namep, "root.cell.", 0, &rock.fid); if (code < 0) { /* add mount point failed, so give up */ if (flags & CM_FLAG_CHECKPATH) return CM_ERROR_NOSUCHPATH; -- 2.39.5