erofs-utils: lib: introduce erofs_io_close()
PATCH 1/1 erofs-utils: lib: introduce erofs_io_close()
Since virtual files may have their own .close().
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/io.h | 3 +++ lib/io.c | 11 +++++++++-- lib/metabox.c | 2 +- lib/tar.c | 2 +- mount/main.c | 24 ++++++++++++------------ 5 files changed, 26 insertions(+), 16 deletions(-)
include/erofs/io.h +3 -0
@@ -41,6 +41,7 @@ struct erofs_vfops { off_t *pos, size_t count);int (*xcopy)(struct erofs_vfile *vout,off_t pos,struct erofs_vfile *vin,unsigned int len,bool noseek); +void (*close)(struct erofs_vfile *vf); };/* don't extend this; instead, use payload for any extra information */
@@ -87,6 +88,8 @@ static inline int erofs_pread(struct erofs_vfile *vf, void *buf,return read != len ? -EIO :0 ; } +void erofs_io_close (struct erofs_vfile *vf); + #ifdef __cplusplus }#endif
lib/io.c +9 -2
@@ -380,8 +380,7 @@ out:void erofs_dev_close (struct erofs_sb_info *sbi) { -if (!sbi->bdev.ops) -close (sbi->bdev.fd); +erofs_io_close (&sbi->bdev);free (sbi->devname); sbi->devname =NULL ; sbi->bdev.fd =-1 ;
@@ -657,3 +656,11 @@ int erofs_io_xcopy(struct erofs_vfile *vout, off_t pos, }while (len);return 0 ; } + +void erofs_io_close (struct erofs_vfile *vf) +{ +if (vf->ops) +return vf->ops->close (vf); +close (vf->fd); + vf->fd =-1 ; +}
lib/metabox.c +1 -1
@@ -21,7 +21,7 @@ void erofs_metabox_exit(struct erofs_sb_info *sbi)return ;DBG_BUGON (!m2gr->bmgr);erofs_buffer_exit (m2gr->bmgr); -close (m2gr->vf.fd); +erofs_io_close (&m2gr->vf);free (m2gr); }
lib/tar.c +1 -1
@@ -65,7 +65,7 @@ void erofs_iostream_close(struct erofs_iostream *ios)#endif return ; } -close (ios->vf.fd); +erofs_io_close (&ios->vf); }int erofs_iostream_open (struct erofs_iostream *ios,int fd,int decoder)
mount/main.c +12 -12
@@ -267,8 +267,8 @@ static void *erofsmount_nbd_loopfn(void *arg)break ; } } -close (ctx->vd.fd); -close (ctx->sk.fd); +erofs_io_close (&ctx->vd); +erofs_io_close (&ctx->sk);return (void *)(uintptr_t )err; }
@@ -288,15 +288,15 @@ static int erofsmount_startnbd(int nbdfd, const char *source) err =erofs_nbd_connect (nbdfd,9 ,INT64_MAX >>9 );if (err <0 ) { -close (ctx.vd.fd); +erofs_io_close (&ctx.vd); goto out_closefd; } ctx.sk.fd = err; err = -pthread_create (&th,NULL , erofsmount_nbd_loopfn, &ctx);if (err) { -close (ctx.vd.fd); -close (ctx.sk.fd); +erofs_io_close (&ctx.vd); +erofs_io_close (&ctx.sk); goto out_closefd; }
@@ -392,7 +392,7 @@ static int erofsmount_startnbd_nl(pid_t *pid, const char *source) err =pipe (pipefd);if (err <0 ) { err = -errno; -close (ctx.vd.fd); +erofs_io_close (&ctx.vd);return err; }if ((*pid =fork ()) ==0 ) {
@@ -400,12 +400,12 @@ static int erofsmount_startnbd_nl(pid_t *pid, const char *source)/* Otherwise, NBD disconnect sends SIGPIPE, skipping cleanup */ if (signal (SIGPIPE ,SIG_IGN ) ==SIG_ERR ) { -close (ctx.vd.fd); +erofs_io_close (&ctx.vd);exit (EXIT_FAILURE ); } recp =erofsmount_write_recovery_info (source);if (IS_ERR (recp)) { -close (ctx.vd.fd); +erofs_io_close (&ctx.vd);exit (EXIT_FAILURE ); } num =-1 ;
@@ -414,7 +414,7 @@ static int erofsmount_startnbd_nl(pid_t *pid, const char *source) ctx.sk.fd = err; err =erofsmount_nbd_fix_backend_linkage (num, &recp);if (err) { -close (ctx.sk.fd); +erofs_io_close (&ctx.sk); }else { err =write (pipefd[1 ], &num,sizeof (int ));if (err <0 )
@@ -427,7 +427,7 @@ static int erofsmount_startnbd_nl(pid_t *pid, const char *source) } } } -close (ctx.vd.fd); +erofs_io_close (&ctx.vd); out_fork: (void )unlink (recp);free (recp);
@@ -529,10 +529,10 @@ static int erofsmount_reattach(const char *target)return EXIT_FAILURE ;return EXIT_SUCCESS ; } -close (ctx.sk.fd); +erofs_io_close (&ctx.sk); err =0 ; } -close (ctx.vd.fd); +erofs_io_close (&ctx.vd); err_line:free (line); err_identifier:
Signature · 1 line
2.43.5