Print this page
PSARC 2007/569 lofi(7D) compression support
6618343 lofi compression support


  74  *      strcpy(li.li_filename, "somefilename");
  75  *      ioctl(ld, LOFI_UNMAP_FILE, &li);
  76  *
  77  *      strcpy(li.li_filename, "somefilename");
  78  *      li.li_minor = minor_number;
  79  *      ioctl(ld, LOFI_MAP_FILE_MINOR, &li);
  80  *
  81  *      li.li_minor = minor_number;
  82  *      ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li);
  83  *
  84  *      li.li_minor = minor_number;
  85  *      ioctl(ld, LOFI_GET_FILENAME, &li);
  86  *
  87  *      strcpy(li.li_filename, "somefilename");
  88  *      ioctl(ld, LOFI_GET_MINOR, &li);
  89  *
  90  *      li.li_minor = 0;
  91  *      ioctl(ld, LOFI_GET_MAXMINOR, &li);
  92  *      maxminor = li.li_minor;
  93  *




  94  * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if
  95  * the device is busy, the underlying vnode will be closed, and any subsequent
  96  * operations will fail.  It will behave as if the device had been forcibly
  97  * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE.  When the device
  98  * is last closed, it will be torn down.
  99  *
 100  * Oh, and last but not least: these ioctls are totally private and only
 101  * for use by lofiadm(1M).
 102  *
 103  */
 104 
 105 struct lofi_ioctl {
 106         uint32_t        li_minor;
 107         boolean_t       li_force;
 108         char    li_filename[MAXPATHLEN + 1];

 109 };
 110 
 111 #define LOFI_IOC_BASE           (('L' << 16) | ('F' << 8))
 112 
 113 #define LOFI_MAP_FILE           (LOFI_IOC_BASE | 0x01)
 114 #define LOFI_MAP_FILE_MINOR     (LOFI_IOC_BASE | 0x02)
 115 #define LOFI_UNMAP_FILE         (LOFI_IOC_BASE | 0x03)
 116 #define LOFI_UNMAP_FILE_MINOR   (LOFI_IOC_BASE | 0x04)
 117 #define LOFI_GET_FILENAME       (LOFI_IOC_BASE | 0x05)
 118 #define LOFI_GET_MINOR          (LOFI_IOC_BASE | 0x06)
 119 #define LOFI_GET_MAXMINOR       (LOFI_IOC_BASE | 0x07)

 120 
 121 /*
 122  * file types that might be usable with lofi, maybe. Only regular
 123  * files are documented though.
 124  */
 125 #define S_ISLOFIABLE(mode) \
 126         (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
 127 




 128 #if defined(_KERNEL)
 129 
 130 /*
 131  * We limit the maximum number of active lofi devices to 128, which seems very
 132  * large. You can tune this by changing lofi_max_files in /etc/system.
 133  * If you change it dynamically, which you probably shouldn't do, make sure
 134  * to only _increase_ it.
 135  */
 136 #define LOFI_MAX_FILES  128
 137 extern uint32_t lofi_max_files;
 138 
 139 #define V_ISLOFIABLE(vtype) \
 140         ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
 141 
 142 struct lofi_state {
 143         char            *ls_filename;   /* filename to open */
 144         size_t          ls_filename_sz;
 145         struct vnode    *ls_vp;         /* open vnode */
 146         kmutex_t        ls_vp_lock;     /* protects ls_vp */
 147         kcondvar_t      ls_vp_cv;       /* signal changes to ls_vp */
 148         uint32_t        ls_vp_iocount;  /* # pending I/O requests */
 149         boolean_t       ls_vp_closereq; /* force close requested */
 150         u_offset_t      ls_vp_size;
 151         uint32_t        ls_blk_open;
 152         uint32_t        ls_chr_open;
 153         uint32_t        ls_lyr_open_count;
 154         int             ls_openflag;
 155         taskq_t         *ls_taskq;
 156         kstat_t         *ls_kstat;
 157         kmutex_t        ls_kstat_lock;
 158         struct dk_geom  ls_dkg;
 159         struct vtoc     ls_vtoc;
 160         struct dk_cinfo ls_ci;

















































 161 };
 162 
 163 #endif
 164 























 165 #ifdef  __cplusplus
 166 }
 167 #endif
 168 
 169 #endif  /* _SYS_LOFI_H */


  74  *      strcpy(li.li_filename, "somefilename");
  75  *      ioctl(ld, LOFI_UNMAP_FILE, &li);
  76  *
  77  *      strcpy(li.li_filename, "somefilename");
  78  *      li.li_minor = minor_number;
  79  *      ioctl(ld, LOFI_MAP_FILE_MINOR, &li);
  80  *
  81  *      li.li_minor = minor_number;
  82  *      ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li);
  83  *
  84  *      li.li_minor = minor_number;
  85  *      ioctl(ld, LOFI_GET_FILENAME, &li);
  86  *
  87  *      strcpy(li.li_filename, "somefilename");
  88  *      ioctl(ld, LOFI_GET_MINOR, &li);
  89  *
  90  *      li.li_minor = 0;
  91  *      ioctl(ld, LOFI_GET_MAXMINOR, &li);
  92  *      maxminor = li.li_minor;
  93  *
  94  *      strcpy(li.li_filename, "somefilename");
  95  *      li.li_minor = 0;
  96  *      ioctl(ld, LOFI_CHECK_COMPRESSED, &li);
  97  *
  98  * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if
  99  * the device is busy, the underlying vnode will be closed, and any subsequent
 100  * operations will fail.  It will behave as if the device had been forcibly
 101  * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE.  When the device
 102  * is last closed, it will be torn down.
 103  *
 104  * Oh, and last but not least: these ioctls are totally private and only
 105  * for use by lofiadm(1M).
 106  *
 107  */
 108 
 109 struct lofi_ioctl {
 110         uint32_t        li_minor;
 111         boolean_t       li_force;
 112         char    li_filename[MAXPATHLEN];
 113         char    li_algorithm[MAXPATHLEN];
 114 };
 115 
 116 #define LOFI_IOC_BASE           (('L' << 16) | ('F' << 8))
 117 
 118 #define LOFI_MAP_FILE           (LOFI_IOC_BASE | 0x01)
 119 #define LOFI_MAP_FILE_MINOR     (LOFI_IOC_BASE | 0x02)
 120 #define LOFI_UNMAP_FILE         (LOFI_IOC_BASE | 0x03)
 121 #define LOFI_UNMAP_FILE_MINOR   (LOFI_IOC_BASE | 0x04)
 122 #define LOFI_GET_FILENAME       (LOFI_IOC_BASE | 0x05)
 123 #define LOFI_GET_MINOR          (LOFI_IOC_BASE | 0x06)
 124 #define LOFI_GET_MAXMINOR       (LOFI_IOC_BASE | 0x07)
 125 #define LOFI_CHECK_COMPRESSED   (LOFI_IOC_BASE | 0x08)
 126 
 127 /*
 128  * file types that might be usable with lofi, maybe. Only regular
 129  * files are documented though.
 130  */
 131 #define S_ISLOFIABLE(mode) \
 132         (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
 133 
 134 #define SEGHDR          1
 135 #define COMPRESSED      1
 136 #define UNCOMPRESSED    0
 137 
 138 #if defined(_KERNEL)
 139 
 140 /*
 141  * We limit the maximum number of active lofi devices to 128, which seems very
 142  * large. You can tune this by changing lofi_max_files in /etc/system.
 143  * If you change it dynamically, which you probably shouldn't do, make sure
 144  * to only _increase_ it.
 145  */
 146 #define LOFI_MAX_FILES  128
 147 extern uint32_t lofi_max_files;
 148 
 149 #define V_ISLOFIABLE(vtype) \
 150         ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
 151 
 152 struct lofi_state {
 153         char            *ls_filename;   /* filename to open */
 154         size_t          ls_filename_sz;
 155         struct vnode    *ls_vp;         /* open vnode */
 156         kmutex_t        ls_vp_lock;     /* protects ls_vp */
 157         kcondvar_t      ls_vp_cv;       /* signal changes to ls_vp */
 158         uint32_t        ls_vp_iocount;  /* # pending I/O requests */
 159         boolean_t       ls_vp_closereq; /* force close requested */
 160         u_offset_t      ls_vp_size;
 161         uint32_t        ls_blk_open;
 162         uint32_t        ls_chr_open;
 163         uint32_t        ls_lyr_open_count;
 164         int             ls_openflag;
 165         taskq_t         *ls_taskq;
 166         kstat_t         *ls_kstat;
 167         kmutex_t        ls_kstat_lock;
 168         struct dk_geom  ls_dkg;
 169         struct vtoc     ls_vtoc;
 170         struct dk_cinfo ls_ci;
 171 
 172         /* the following fields are required for compression support */
 173 
 174         /*
 175          * index into lofi_compress_table for the compression algorithm
 176          * used
 177          */
 178         int             ls_comp_algorithm_index;
 179         uint32_t        ls_comp_algorithm_len;
 180         /* size of an uncompressed segment */
 181         uint32_t        ls_uncomp_seg_sz;
 182         /* number of index entries */
 183         uint32_t        ls_comp_index_sz;
 184         /* exponent for byte shift, power of 2 */
 185         uint32_t        ls_comp_seg_shift;
 186         /*
 187          * size of the last uncompressed segment (the file may
 188          * not be an exact multiple of the segment size ls_uncomp_seg_sz)
 189          */
 190         uint32_t        ls_uncomp_last_seg_sz;
 191         /*
 192          * the offset in the file where the header ends and the
 193          * actual compressed data begins. The segment offsets in
 194          * the index do not account for the header so this value must
 195          * be added
 196          */
 197         uint64_t        ls_comp_offbase;
 198         /*
 199          * the array holding the segment index. This is a pointer
 200          * into ls_comp_index_data
 201          */
 202         uint64_t        *ls_comp_seg_index;
 203         /*
 204          * holds the index pages loaded from the file. This is aligned
 205          * on a disk block boundary so lsecomp_seg_index above is used
 206          * to point to the actual array
 207          */
 208         caddr_t         ls_comp_index_data;
 209         /* size of ls_comp_index_data */
 210         uint32_t        ls_comp_index_data_sz;
 211         /*
 212          * incase of compressed files, ls_vp_size above is
 213          * tweaked to represent the actual uncompressed file
 214          * size so that fake_disk_geometry gives the correct
 215          * values. However we need the actual compressed file
 216          * size while faulting in pages from the compressed
 217          * file in lofi_mapped_rdwr
 218          */
 219         u_offset_t      ls_vp_comp_size;
 220 };
 221 
 222 #endif  /* _KERNEL */
 223 
 224 /*
 225  * Common signature for all lofi compress functions
 226  */
 227 typedef int lofi_compress_func_t(void *src, size_t srclen, void *dst,
 228         size_t *destlen, int level);
 229 
 230 /*
 231  * Information about each compression function
 232  */
 233 typedef struct lofi_compress_info {
 234         lofi_compress_func_t    *l_decompress;
 235         lofi_compress_func_t    *l_compress;
 236         int                     l_level;
 237         char                    *l_name;        /* algorithm name */
 238 } lofi_compress_info_t;
 239 
 240 enum lofi_compress {
 241         LOFI_COMPRESS_GZIP = 0,
 242         LOFI_COMPRESS_GZIP_6 = 1,
 243         LOFI_COMPRESS_GZIP_9 = 2,
 244         LOFI_COMPRESS_FUNCTIONS
 245 };
 246 
 247 #ifdef  __cplusplus
 248 }
 249 #endif
 250 
 251 #endif  /* _SYS_LOFI_H */