return 0; /* success */
} /*CopyOnWrite */
-static int
-CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
- afs_sfsize_t size)
-{
- char *buff = malloc(COPYBUFFSIZE);
- size_t length;
- ssize_t rdlen;
- ssize_t wrlen;
- int rc = 0;
- afs_foff_t done = off;
-
- if (size > FDH_SIZE(targFdP) - off)
- size = FDH_SIZE(targFdP) - off;
-
- while (size > 0) {
- if (size > COPYBUFFSIZE) { /* more than a buffer */
- length = COPYBUFFSIZE;
- size -= COPYBUFFSIZE;
- } else {
- length = size;
- size = 0;
- }
- rdlen = FDH_PREAD(targFdP, buff, length, done);
- if (rdlen == length) {
- wrlen = FDH_PWRITE(newFdP, buff, length, done);
- done += rdlen;
- }
- else
- wrlen = 0;
-
- if ((rdlen != length) || (wrlen != length)) {
- /* no error recovery, at the worst we'll have a "hole"
- * in the file */
- rc = 1;
- break;
- }
- }
- free(buff);
- return rc;
-}
-
-
/*
* Common code to handle with removing the Name (file when it's called from
* SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
parentwhentargetnotdir = NULL;
}
- fsstats_StartXfer(&fsstats);
+ fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
/* actually do the data transfer */
errorCode =
parentwhentargetnotdir = NULL;
}
- fsstats_StartXfer(&fsstats);
+ fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
errorCode =
StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
goto Bad_Rename;
+ /* since copyonwrite would mean fileptr has a new handle, do it here */
+ FidZap(&filedir);
+ SetDirHandle(&filedir, fileptr);
}
/* If the new name exists already, delete it and the file it points to */
afs_fsize_t NewLength; /* size after this store completes */
afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
int linkCount = 0; /* link count on inode */
- afs_fsize_t CoW_off, CoW_len;
ssize_t nBytes;
- FdHandle_t *fdP, *origfdP = NULL;
+ FdHandle_t *fdP;
struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
afs_ino_str_t stmp;
* mechanisms (i.e. copy on write overhead.) Also the right size
* of the disk will be recorded...
*/
- origfdP = fdP;
+ FDH_CLOSE(fdP);
VN_GET_LEN(size, targetptr);
volptr->partition->flags &= ~PART_DONTUPDATE;
VSetPartitionDiskUsage(volptr->partition);
volptr->partition->flags |= PART_DONTUPDATE;
if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
volptr->partition->flags &= ~PART_DONTUPDATE;
- FDH_CLOSE(origfdP);
return (errorCode);
}
- CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
- CopyOnWrite_calls++;
- if (CoW_len == 0) CopyOnWrite_size0++;
- if (Pos == 0) CopyOnWrite_off0++;
- if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
-
- ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
- "off 0x0 size 0x%llx\n",
- afs_printable_VolumeId_u(V_id(volptr)),
- afs_printable_VnodeId_u(targetptr->vnodeNumber),
- V_name(volptr), Pos));
- if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
+ ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
+ if ((errorCode = CopyOnWrite(targetptr, volptr, 0, MAXFSIZE))) {
ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
volptr->partition->flags &= ~PART_DONTUPDATE;
- FDH_CLOSE(origfdP);
return (errorCode);
}
volptr->partition->flags &= ~PART_DONTUPDATE;
if (fdP == NULL) {
ViceLog(25,
("StoreData : Reopen after CopyOnWrite failed\n"));
- FDH_REALLYCLOSE(origfdP);
return ENOENT;
}
}
AdjustDiskUsage(volptr, adjustSize,
adjustSize - SpareComp(volptr)))) {
FDH_CLOSE(fdP);
- if (origfdP) FDH_REALLYCLOSE(origfdP);
return (errorCode);
}
FDH_SYNC(fdP);
}
if (errorCode) {
+ Error tmp_errorCode = 0;
afs_sfsize_t nfSize = FDH_SIZE(fdP);
osi_Assert(nfSize >= 0);
/* something went wrong: adjust size and return */
* need to update the target vnode.
*/
targetptr->changed_newTime = 1;
- if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
- CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
- if (origfdP) FDH_REALLYCLOSE(origfdP);
FDH_CLOSE(fdP);
/* set disk usage to be correct */
- VAdjustDiskUsage(&errorCode, volptr,
+ VAdjustDiskUsage(&tmp_errorCode, volptr,
(afs_sfsize_t) (nBlocks(nfSize) -
nBlocks(NewLength)), 0);
- return errorCode;
- }
- if (origfdP) { /* finish CopyOnWrite */
- if ( (CoW_off = Pos + Length) < NewLength) {
- errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
- ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
- "off 0x%llx size 0x%llx returns %d\n",
- afs_printable_VolumeId_u(V_id(volptr)),
- afs_printable_VnodeId_u(targetptr->vnodeNumber),
- V_name(volptr), CoW_off, CoW_len, errorCode));
+ if (tmp_errorCode) {
+ errorCode = tmp_errorCode;
}
- FDH_REALLYCLOSE(origfdP);
+ return errorCode;
}
FDH_CLOSE(fdP);