Skip to content

Commit

Permalink
DELETE_ON_CLOSE needs to parse stream_name
Browse files Browse the repository at this point in the history
We attempted to delete "FileName.txt:Zone.Identifier" when
the xattr name would just be "Zone.Identifier".

Also correct setting the Stream name by passing it along
and assigning it. Garbage characters is undesired in log files.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jan 30, 2024
1 parent f85bf35 commit 674ab11
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
61 changes: 38 additions & 23 deletions module/os/windows/zfs/zfs_vnops_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ zfs_AcquireForLazyWrite(void *Context, BOOLEAN Wait)
FILE_OBJECT *fo = Context;
BOOLEAN result = FALSE;

dprintf("%s:fo %p\n", __func__, fo);

if (fo == NULL)
return (FALSE);

mount_t *zmo = fo->DeviceObject->DeviceExtension;
zfsvfs_t *zfsvfs = vfs_fsprivate(zmo);
struct vnode *vp = fo->FsContext;
dprintf("%s:fo %p\n", __func__, fo);

if (unlikely(zfsvfs == NULL)) {
dprintf("%s: fo %p already freed zfsvfs\n", __func__, fo);
Expand Down Expand Up @@ -178,15 +179,14 @@ zfs_ReleaseFromLazyWrite(void *Context)
{
FILE_OBJECT *fo = Context;

dprintf("%s:\n", __func__);
if (fo == NULL)
return;

mount_t *zmo = fo->DeviceObject->DeviceExtension;
zfsvfs_t *zfsvfs = vfs_fsprivate(zmo);
struct vnode *vp = fo->FsContext;

dprintf("%s:\n", __func__);

if (vp != NULL && VN_HOLD(vp) == 0) {
ExReleaseResourceLite(vp->FileHeader.Resource);
vnode_rele(vp);
Expand All @@ -206,15 +206,15 @@ zfs_AcquireForReadAhead(void *Context, BOOLEAN Wait)
FILE_OBJECT *fo = Context;
BOOLEAN result = FALSE;

dprintf("%s:\n", __func__);

if (fo == NULL)
return (FALSE);

mount_t *zmo = fo->DeviceObject->DeviceExtension;
zfsvfs_t *zfsvfs = vfs_fsprivate(zmo);
struct vnode *vp = fo->FsContext;

dprintf("%s:\n", __func__);

if (unlikely(zfsvfs == NULL)) {
dprintf("%s: fo %p already freed zfsvfs\n", __func__, fo);
return (FALSE);
Expand Down Expand Up @@ -260,14 +260,15 @@ zfs_ReleaseFromReadAhead(void *Context)
{
FILE_OBJECT *fo = Context;

dprintf("%s:\n", __func__);
if (fo == NULL)
return;

mount_t *zmo = fo->DeviceObject->DeviceExtension;
zfsvfs_t *zfsvfs = vfs_fsprivate(zmo);

struct vnode *vp = fo->FsContext;
dprintf("%s:\n", __func__);

if (vp != NULL && VN_HOLD(vp) == 0) {
ExReleaseResourceLite(vp->FileHeader.Resource);
vnode_rele(vp);
Expand Down Expand Up @@ -333,7 +334,8 @@ zfs_init_cache(FILE_OBJECT *fo, struct vnode *vp, CC_FILE_SIZES *ccfs)
*/
static void
zfs_couplefileobject(vnode_t *vp, vnode_t *dvp, FILE_OBJECT *fileobject,
uint64_t size, zfs_ccb_t **ccb, uint64_t alloc, ACCESS_MASK access)
uint64_t size, zfs_ccb_t **ccb, uint64_t alloc, ACCESS_MASK access,
char *stream)
{
zfs_ccb_t *zccb;

Expand Down Expand Up @@ -371,10 +373,11 @@ zfs_couplefileobject(vnode_t *vp, vnode_t *dvp, FILE_OBJECT *fileobject,
vp->FileHeader.IsFastIoPossible = fast_io_possible(vp);
#endif

zfs_build_path(VTOZ(vp), dvp ? VTOZ(dvp) : NULL,
zfs_build_path_stream(VTOZ(vp), dvp ? VTOZ(dvp) : NULL,
&zccb->z_name_cache,
&zccb->z_name_len,
&zccb->z_name_offset);
&zccb->z_name_offset,
stream);

}

Expand Down Expand Up @@ -885,7 +888,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
dvp = ZTOV(zp);

zfs_couplefileobject(dvp, NULL, FileObject, 0ULL, &zccb,
Irp->Overlay.AllocationSize.QuadPart, DesiredAccess);
Irp->Overlay.AllocationSize.QuadPart, DesiredAccess,
stream_name);

VN_RELE(dvp);

Expand Down Expand Up @@ -952,7 +956,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
FileObject, zp->z_size, &zccb,
Irp->
Overlay.AllocationSize.QuadPart,
DesiredAccess);
DesiredAccess,
stream_name);
VN_RELE(vp);

Irp->IoStatus.Information = FILE_OPENED;
Expand Down Expand Up @@ -990,7 +995,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zfs_couplefileobject(dvp, NULL, FileObject,
0ULL, &zccb,
Irp->Overlay.AllocationSize.QuadPart,
DesiredAccess);
DesiredAccess,
stream_name);
VN_RELE(dvp);
} else {
Irp->IoStatus.Information = 0;
Expand Down Expand Up @@ -1149,7 +1155,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zp ? zp->z_size : 0ULL,
&zccb,
Irp->Overlay.AllocationSize.QuadPart,
DesiredAccess);
DesiredAccess,
stream_name);
}
#endif
VN_RELE(vp);
Expand Down Expand Up @@ -1261,7 +1268,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zfs_couplefileobject(dvp, NULL, FileObject, 0ULL,
&zccb,
Irp->Overlay.AllocationSize.QuadPart,
DesiredAccess);
DesiredAccess,
stream_name);
if (DeleteOnClose)
Status = zfs_setunlink_masked(FileObject, NULL);
if (Status == STATUS_SUCCESS)
Expand Down Expand Up @@ -1332,7 +1340,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zfs_couplefileobject(vp, NULL, FileObject, 0ULL,
&zccb,
Irp->Overlay.AllocationSize.QuadPart,
DesiredAccess);
DesiredAccess,
stream_name);

if (DeleteOnClose)
Status = zfs_setunlink_masked(FileObject, dvp);
Expand Down Expand Up @@ -1603,12 +1612,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zp ? zp->z_size : 0ULL, &zccb,
Irp->Overlay.AllocationSize.QuadPart,
granted_access ?
granted_access : DesiredAccess);

zfs_build_path(VTOZ(vp), VTOZ(dvp),
&zccb->z_name_cache,
&zccb->z_name_len,
&zccb->z_name_offset);
granted_access : DesiredAccess,
stream_name);

if (DeleteOnClose)
Status =
Expand Down Expand Up @@ -1685,7 +1690,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zfs_couplefileobject(dvp, NULL, FileObject, 0ULL,
&zccb,
Irp->Overlay.AllocationSize.QuadPart,
granted_access ? granted_access : DesiredAccess);
granted_access ? granted_access : DesiredAccess,
stream_name);

if (DeleteOnClose)
Status = zfs_setunlink_masked(FileObject, NULL);
Expand All @@ -1711,7 +1717,8 @@ zfs_vnop_lookup_impl(PIRP Irp, PIO_STACK_LOCATION IrpSp, mount_t *zmo,
zfs_couplefileobject(vp, dvp, FileObject, zp->z_size,
&zccb,
Irp->Overlay.AllocationSize.QuadPart,
granted_access ? granted_access : DesiredAccess);
granted_access ? granted_access : DesiredAccess,
stream_name);

// Now that vp is set, check delete
if (DeleteOnClose)
Expand Down Expand Up @@ -5679,6 +5686,14 @@ delete_entry(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
else
finalname = filename;

// Check if it has :stream
char *stream_name = NULL;
error = stream_parse(filename, &stream_name);
if (error == 0 && stream_name != NULL)
finalname = stream_name;

dprintf("final delete name as '%s'\n", finalname);

// Release final HOLD on item, ready for deletion
int isdir = vnode_isdir(vp);

Expand Down
11 changes: 6 additions & 5 deletions module/os/windows/zfs/zfs_vnops_windows_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2263,18 +2263,15 @@ zfs_build_path_stream(znode_t *start_zp, znode_t *start_parent, char **fullpath,
if (start_zp == NULL)
return (EINVAL);

if (stream == NULL)
return (EINVAL);

error = zfs_build_path(start_zp, start_parent, fullpath,
returnsize, start_zp_offset);

if (error) {
if (error && stream) {
// name + ":" + streamname + null
// TODO: clean this up to not realloc
char *newname;
newname = kmem_asprintf("%s:%s",
*fullpath, stream);
*fullpath ? *fullpath : "", stream);

// Fetch new offset, before ":stream"
*start_zp_offset = *returnsize;
Expand All @@ -2284,6 +2281,10 @@ zfs_build_path_stream(znode_t *start_zp, znode_t *start_parent, char **fullpath,
*returnsize = strlen(newname) + 1;
// assign new string
*fullpath = newname;
} else if (error) {
*fullpath = kmem_asprintf("(nameunknown)");
*returnsize = strlen(*fullpath) + 1;
*start_zp_offset = 0;
}

return (0);
Expand Down

0 comments on commit 674ab11

Please sign in to comment.