7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 *
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2016 Andrey Sokolov
26 * Copyright 2016 Toomas Soome <tsoome@me.com>
27 */
28
29 /*
30 * lofi (loopback file) driver - allows you to attach a file to a device,
31 * which can then be accessed through that device. The simple model is that
32 * you tell lofi to open a file, and then use the block device you get as
33 * you would any block device. lofi translates access to the block device
34 * into I/O on the underlying file. This is mostly useful for
35 * mounting images of filesystems.
36 *
37 * lofi is controlled through /dev/lofictl - this is the only device exported
38 * during attach, and is instance number 0. lofiadm communicates with lofi
39 * through ioctls on this device. When a file is attached to lofi, block and
40 * character devices are exported in /dev/lofi and /dev/rlofi. These devices
41 * are identified by lofi instance number, and the instance number is also used
42 * as the name in /dev/lofi.
43 *
44 * Virtual disks, or, labeled lofi, implements virtual disk support to
45 * support partition table and related tools. Such mappings will cause
46 * block and character devices to be exported in /dev/dsk and /dev/rdsk
536 }
537
538 list_remove(&lofi_list, lsp);
539
540 lofi_free_crypto(lsp);
541
542 /*
543 * Free pre-allocated compressed buffers
544 */
545 if (lsp->ls_comp_bufs != NULL) {
546 for (i = 0; i < lofi_taskq_nthreads; i++) {
547 if (lsp->ls_comp_bufs[i].bufsize > 0)
548 kmem_free(lsp->ls_comp_bufs[i].buf,
549 lsp->ls_comp_bufs[i].bufsize);
550 }
551 kmem_free(lsp->ls_comp_bufs,
552 sizeof (struct compbuf) * lofi_taskq_nthreads);
553 }
554
555 if (lsp->ls_vp != NULL) {
556 (void) VOP_PUTPAGE(lsp->ls_vp, 0, 0, B_INVAL, credp, NULL);
557 (void) VOP_CLOSE(lsp->ls_vp, lsp->ls_openflag,
558 1, 0, credp, NULL);
559 VN_RELE(lsp->ls_vp);
560 }
561 if (lsp->ls_stacked_vp != lsp->ls_vp)
562 VN_RELE(lsp->ls_stacked_vp);
563 lsp->ls_vp = lsp->ls_stacked_vp = NULL;
564
565 if (lsp->ls_kstat != NULL) {
566 kstat_delete(lsp->ls_kstat);
567 lsp->ls_kstat = NULL;
568 }
569
570 /*
571 * Free cached decompressed segment data
572 */
573 lofi_free_comp_cache(lsp);
574 list_destroy(&lsp->ls_comp_cache);
575
576 if (lsp->ls_uncomp_seg_sz > 0) {
2917 */
2918 mutex_enter(&lsp->ls_vp_lock);
2919 lsp->ls_vp_ready = B_TRUE;
2920 cv_broadcast(&lsp->ls_vp_cv);
2921 mutex_exit(&lsp->ls_vp_lock);
2922 mutex_exit(&lofi_lock);
2923
2924 lofi_copy_devpath(klip);
2925
2926 if (rvalp)
2927 *rvalp = id;
2928 (void) copy_out_lofi_ioctl(klip, ulip, ioctl_flag);
2929 free_lofi_ioctl(klip);
2930 return (0);
2931
2932 err:
2933 if (lsp != NULL) {
2934 lofi_destroy(lsp, credp);
2935 } else {
2936 if (vp != NULL) {
2937 (void) VOP_PUTPAGE(vp, 0, 0, B_INVAL, credp, NULL);
2938 (void) VOP_CLOSE(vp, flag, 1, 0, credp, NULL);
2939 VN_RELE(vp);
2940 }
2941 }
2942
2943 mutex_exit(&lofi_lock);
2944 free_lofi_ioctl(klip);
2945 return (error);
2946 }
2947
2948 /*
2949 * unmap a file.
2950 */
2951 static int
2952 lofi_unmap_file(struct lofi_ioctl *ulip, int byfilename,
2953 struct cred *credp, int ioctl_flag)
2954 {
2955 struct lofi_state *lsp;
2956 struct lofi_ioctl *klip;
2957 char namebuf[MAXNAMELEN];
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 *
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2016 Andrey Sokolov
26 * Copyright 2016 Toomas Soome <tsoome@me.com>
27 * Copyright 2019 Joyent, Inc.
28 */
29
30 /*
31 * lofi (loopback file) driver - allows you to attach a file to a device,
32 * which can then be accessed through that device. The simple model is that
33 * you tell lofi to open a file, and then use the block device you get as
34 * you would any block device. lofi translates access to the block device
35 * into I/O on the underlying file. This is mostly useful for
36 * mounting images of filesystems.
37 *
38 * lofi is controlled through /dev/lofictl - this is the only device exported
39 * during attach, and is instance number 0. lofiadm communicates with lofi
40 * through ioctls on this device. When a file is attached to lofi, block and
41 * character devices are exported in /dev/lofi and /dev/rlofi. These devices
42 * are identified by lofi instance number, and the instance number is also used
43 * as the name in /dev/lofi.
44 *
45 * Virtual disks, or, labeled lofi, implements virtual disk support to
46 * support partition table and related tools. Such mappings will cause
47 * block and character devices to be exported in /dev/dsk and /dev/rdsk
537 }
538
539 list_remove(&lofi_list, lsp);
540
541 lofi_free_crypto(lsp);
542
543 /*
544 * Free pre-allocated compressed buffers
545 */
546 if (lsp->ls_comp_bufs != NULL) {
547 for (i = 0; i < lofi_taskq_nthreads; i++) {
548 if (lsp->ls_comp_bufs[i].bufsize > 0)
549 kmem_free(lsp->ls_comp_bufs[i].buf,
550 lsp->ls_comp_bufs[i].bufsize);
551 }
552 kmem_free(lsp->ls_comp_bufs,
553 sizeof (struct compbuf) * lofi_taskq_nthreads);
554 }
555
556 if (lsp->ls_vp != NULL) {
557 (void) VOP_PUTPAGE(lsp->ls_vp, 0, 0, B_FREE, credp, NULL);
558 (void) VOP_CLOSE(lsp->ls_vp, lsp->ls_openflag,
559 1, 0, credp, NULL);
560 VN_RELE(lsp->ls_vp);
561 }
562 if (lsp->ls_stacked_vp != lsp->ls_vp)
563 VN_RELE(lsp->ls_stacked_vp);
564 lsp->ls_vp = lsp->ls_stacked_vp = NULL;
565
566 if (lsp->ls_kstat != NULL) {
567 kstat_delete(lsp->ls_kstat);
568 lsp->ls_kstat = NULL;
569 }
570
571 /*
572 * Free cached decompressed segment data
573 */
574 lofi_free_comp_cache(lsp);
575 list_destroy(&lsp->ls_comp_cache);
576
577 if (lsp->ls_uncomp_seg_sz > 0) {
2918 */
2919 mutex_enter(&lsp->ls_vp_lock);
2920 lsp->ls_vp_ready = B_TRUE;
2921 cv_broadcast(&lsp->ls_vp_cv);
2922 mutex_exit(&lsp->ls_vp_lock);
2923 mutex_exit(&lofi_lock);
2924
2925 lofi_copy_devpath(klip);
2926
2927 if (rvalp)
2928 *rvalp = id;
2929 (void) copy_out_lofi_ioctl(klip, ulip, ioctl_flag);
2930 free_lofi_ioctl(klip);
2931 return (0);
2932
2933 err:
2934 if (lsp != NULL) {
2935 lofi_destroy(lsp, credp);
2936 } else {
2937 if (vp != NULL) {
2938 (void) VOP_PUTPAGE(vp, 0, 0, B_FREE, credp, NULL);
2939 (void) VOP_CLOSE(vp, flag, 1, 0, credp, NULL);
2940 VN_RELE(vp);
2941 }
2942 }
2943
2944 mutex_exit(&lofi_lock);
2945 free_lofi_ioctl(klip);
2946 return (error);
2947 }
2948
2949 /*
2950 * unmap a file.
2951 */
2952 static int
2953 lofi_unmap_file(struct lofi_ioctl *ulip, int byfilename,
2954 struct cred *credp, int ioctl_flag)
2955 {
2956 struct lofi_state *lsp;
2957 struct lofi_ioctl *klip;
2958 char namebuf[MAXNAMELEN];
|