virt-alignment-scan: Add checks for when API calls return NULL.
[libguestfs.git] / TODO
1 TODO list for libguestfs
2 ======================================================================
3
4 This list contains random ideas and musings on features we could add
5 to libguestfs in future.
6
7    - RWMJ
8
9 FUSE API
10 --------
11
12 The API needs more test coverage, particularly lesser-used system
13 calls.
14
15 The big unresolved issue is UID/GID mapping between guest filesystem
16 IDs and the host.  It's not easy to automate this because you need
17 extra details about the guest itself in order to get to its
18 UID->username map (eg. /etc/passwd from the guest).
19
20 Haskell bindings
21 ----------------
22
23 Complete the Haskell bindings (see discussion on haskell-cafe).
24
25 PHP bindings
26 ------------
27
28 Add bindtests to PHP bindings.
29
30 Complete bind tests
31 -------------------
32
33 Complete the bind tests - must test the return values and error cases.
34
35 virt-inspector - make libvirt XML
36 ---------------------------------
37
38 It should be possible to generate libvirt XML from virt-inspector
39 data, at least partially.  This would be just another output type so:
40
41  virt-inspector --libvirt guest.img
42
43 Note that recent versions of libvirt/virt-install allow guests to be
44 imported, so this is not so useful any more.
45
46 "Standalone/local mode"
47 -----------------------
48
49 Instead of running guestfsd (the daemon) inside qemu, there should be
50 an option to just run guestfsd directly.
51
52 The architecture in this mode would look like:
53
54      +------------------+
55      | main program     |
56      |------------------|
57      | libguestfs       |
58      +--------^---------+
59           |   | reply
60       cmd |   |
61      +----v-------------+
62      | guestfsd         |
63      +------------------+
64
65 Notes:
66
67 (1) This only makes sense if we are running as root.
68
69 (2) There is no console / kernel messages in this configuration, but
70 we might consider capturing stderr from the daemon.
71
72 (3) guestfs_config and guestfs_add_drive become no-ops.
73
74 Obviously in this configuration, commands are run directly on the
75 local machine's disks.  You could just run the commands themselves
76 directly, but libguestfs provides a convenient API and language
77 bindings.  Also deals with tricky stuff like parsing the output of the
78 LVM commands.  Also we get to leverage other code such as
79 virt-inspector.
80
81 This is mainly useful from live CDs, ie. virt-p2v.
82
83 Should we bother having the daemon at all and just link the guestfsd
84 code directly into libguestfs?
85
86 Ideas for extra commands
87 ------------------------
88
89   General glibc / core programs:
90     chgrp
91     more mk*temp calls
92
93   ext2 properties:
94     chattr
95     lsattr
96     badblocks
97     blkid
98     debugfs
99     dumpe2fs
100     e2image
101     e2undo
102     filefrag
103     findfs
104     logsave
105     mklost+found
106
107   SELinux:
108     chcat
109     restorecon
110     ch???
111
112   Oddball:
113     pivot_root
114     fts(3) / ftw(3)
115
116 Other initrd-* commands
117 -----------------------
118
119 Such as:
120
121 initrd-extract
122 initrd-replace
123
124 Simple editing of configuration files
125 -------------------------------------
126
127 Some easy non-Augeas methods to edit configuration files.
128 I'm thinking:
129
130   replace /etc/file key value
131
132 which would look in /etc/file for any instances of
133
134   key=...
135   key ...
136   key:...
137
138 and replace them with
139
140   key=value
141   key value
142   key:value
143
144 That would solve about 50% of reconfiguration needs, and for the
145 rest you'd use Augeas, 'download'+'upload' or 'edit'.
146
147 RWMJ: I had a go at implementing this, but it's quite error-prone to
148 do this sort of editing inside the C-based daemon code.  It's far
149 better to do it with Augeas, or else to use an external language like
150 Perl.
151
152 Quick Perl scripts
153 ------------------
154
155 Currently we can't do Perl "one-liners".  ie. The current syntax for
156 any short Perl one-liner would be:
157
158   perl -MSys::Guestfs -e '$g = Sys::Guestfs->new(); $g->add_drive ("foo"); $g->launch; $g->mount ("/dev/sda1", "/"); ....'
159
160 You can see we're well beyond a single line just getting to the point
161 of adding drives and mounting.
162
163 First suggestion:
164
165  $h = create ($filename, \"/dev/sda1\" => \"/\");
166
167  $h = create ([$file1, $file2], \"/dev/sda1\" => \"/\");
168
169 To mount read-only, add C<ro =E<gt> 1> like this:
170
171  $h = create ($filename, \"/dev/sda1\" => \"/\", ro => 1);
172
173 which is equivalent to the following sequence of calls:
174
175  $h = Sys::Guestfs->new ();
176  $h->add_drive_ro ($filename);
177  $h->launch ();
178  $h->mount_ro (\"/dev/sda1\", \"/\");
179
180 Command-line form would be:
181
182  perl -MSys::Guestfs=:all -e '$_=create("guest.img", "/dev/sda1" => "/"); $_->cat ("/etc/fstab");'
183
184 That's not brief enough for one-liners, so we could have an extra
185 autogenerated module which creates a Sys::Guestfs handle singleton
186 (the handle is an implicit global variable as in guestfish), eg:
187
188  perl -MSys::Guestfs::One -e 'inspect("guest.img"); cat ("/etc/fstab");'
189
190 How would editing files work?
191
192 virt-rescue pty
193 ---------------
194
195 See:
196 http://search.cpan.org/~rgiersig/IO-Tty-1.08/Pty.pm
197 http://www.perlmonks.org/index.pl?node_id=582185
198
199 Note that pty requires cooperation inside the C code too (there are
200 two sides to a pty, and one has to be handled after the fork).
201
202 [I tried to implement this in the new C virt-rescue, but it doesn't
203 work.  qemu is implementing its own ptys, and they are broken.  Need
204 to fix qemu.]
205
206 Windows-based daemon/appliance
207 ------------------------------
208
209 See discussion on list:
210 https://www.redhat.com/archives/libguestfs/2009-November/msg00165.html
211
212 qemu locking
213 ------------
214
215 Add -drive file=...,lock=exclusive and -drive file=...,lock=shared
216
217 Change libguestfs and libvirt to do the right thing, so that multiple
218 instances of qemu cannot stomp on each other.
219
220 virt-disk-explore
221 -----------------
222
223 For multi-level disk images such as live CDs:
224 http://rwmj.wordpress.com/2009/07/15/unpack-the-russian-doll-of-a-f11-live-cd/
225
226 It's possible with libguestfs to recursively look for anything that
227 might be a filesystem, mount-{,loop} it and look in those, revealing
228 anything in a disk image.
229
230 However this won't work easily for VM disk images in the disk image.
231 One would have to download those to the host and launch another
232 libguestfs instance.
233
234 [Not sure this is such a good idea.  See also live CD inspection idea below.]
235
236 Map filesystems to disk blocks
237 ------------------------------
238
239 Map files/filesystems/(any other object) to the actual disk
240 blocks they occupy.
241
242 And vice versa.
243
244 Is it even possible?
245
246 See also contribs/visualize-alignment/
247
248 Integration with host intrusion systems
249 ---------------------------------------
250
251 Perfect way to monitor VMs from outside the VM.  Look for file
252 hashes, log events, login/logout etc.
253
254 http://www.ossec.net/
255 http://la-samhna.de/samhain/
256 http://sourceforge.net/projects/aide/
257 http://osiris.shmoo.com/
258 http://sourceforge.net/projects/tripwire/
259
260 Fix 'file'
261 ----------
262
263 https://www.redhat.com/archives/libguestfs/2010-June/msg00053.html
264 https://www.redhat.com/archives/libguestfs/2010-June/msg00079.html
265
266 Freeze/thaw filesystems
267 -----------------------
268
269 Access to these ioctls:
270 http://git.kernel.org/linus/fcccf502540e3d7
271
272 Tips for new users in guestfish
273 -------------------------------
274
275 $ guestfish
276 Tip: You need to 'add disk.img' or 'alloc disk.img nn' to make a new image.
277 Type 'notips' to disable tips permanently.
278 ><fs> add mydisk
279 Tip: You need to type 'run' before you can see into the disk image.
280 ><fs> run
281 Tip: Use 'list-filesystems' to see what filesystems are available.
282 ><fs> list-filesystems
283 /dev/vda1
284 Tip: Use 'mount fs /' to mount a filesystem.
285 ><fs> mount /dev/vda1 /
286 Tip: Use 'll /' to view the filesystem or ...
287 ><fs> ll /
288
289 Could we make guestfish interactive if commands are used without params?
290 ------------------------------------------------------------------------
291
292 ><fs> sparse
293 [[Prints man page]]
294 Image name? disk.img
295 Size of image? 10M
296
297 Common problems
298 ---------------
299
300 How can we solve these common user problems?
301
302 [space for common problems here]
303
304 Better support for encrypted devices
305 ------------------------------------
306
307 Currently LUKS support only works if the device contains volume
308 groups.  If it contains, eg., partitions, you cannot access them.
309 We would like to add:
310
311   - Direct access to the /dev/mapper device (eg. if it contains
312     anything apart from VGs).
313
314 Display image as PS
315 -------------------
316
317 Display the structure of an image file as a PS.
318
319 Greater use of blkid / libblkid
320 -------------------------------
321
322 guestfs_zero should use wipefs.  See wipefs(8).
323
324 There are various useful functions in libblkid for listing partitions,
325 devices etc which we are essentially duplicating in the daemon.  It
326 would make more sense to just use libblkid for this.
327
328 There are some places where we call out to the 'blkid' program.  This
329 might be replaced by direct use of the library (if this is easier).
330
331 Visualization
332 -------------
333
334 Eric Sandeen pointed out the blktrace tool which is a better way of
335 capturing traces than using patched qemu (see
336 contrib/visualize-alignment).  We would still use the same
337 visualization tools in conjunction with blktrace traces.
338
339 guestfish parsing
340 -----------------
341
342 At the moment guestfish uses an ad hoc parser which has many
343 shortcomings.  We should change to using a lex/yacc-based scanner and
344 parser (there are better parsers out there, but yacc is sufficient and
345 very widely available).
346
347 The scanner must deal with the case of parsing a whole command string,
348 eg. for a command that the user types in:
349
350  ><fs> add-drive-opts "/tmp/foo" readonly:true
351
352 and also with parsing single words from the command line:
353
354  guestfish add-drive-opts /tmp/foo readonly:true
355
356 Note the quotes are for scanning and don't indicate types.
357
358 We should also allow variables and expressions as part of this new
359 parsing code, eg:
360
361  set roots inspect-os
362  set product inspect-get-product-name %{roots[0]}
363
364 % is better than $ because of shell escaping and confusion with shell
365 variables.
366
367 Can we combine this with ability to set and read environment
368 variables?  Currently guestfish uses many environment variables like
369 $EDITOR without any corresponding ability to set them.
370
371  set EDITOR /usr/bin/emacs
372  echo $EDITOR  # or %{EDITOR}
373  edit /etc/resolv.conf
374
375 live CD inspection for Windows 7
376 --------------------------------
377
378 Windows 7 install CDs are quite different and pretty impenetrable.
379 There are no obvious files to parse.
380
381 More ntfs tools
382 ---------------
383
384 ntfsprogs actually has a lot more useful tools than we currently
385 use.  Interesting ones are:
386
387 ntfslabel: display or change filesystem label (we should unify all
388   set*label APIs into a single set_vfs_label which can deal with any
389   filesystem)
390
391 ntfsclone: clone, image, restore, rescue NTFS
392
393 ntfsinfo: print various information about NTFS volume and files
394
395 ntfs streams: extract alternate streams from NTFS files
396
397 ntfsck: checker for NTFS filesystems
398
399 Undelete files
400 --------------
401
402 Two useful tools:
403
404   - ext2undelete
405   - ntfsundelete
406
407 More mkfs_opts options
408 ----------------------
409
410 Useful options to offer:
411  - Set label.
412  - Set UUID.
413
414 Use /proc/self/mountinfo
415 ------------------------
416
417 This file contains lots of interesting information about
418 what is mounted and where. eg:
419
420   16 21 0:3 / /proc rw,relatime - proc /proc rw
421   17 21 0:16 / /sys rw,relatime - sysfs /sys rw,seclabel
422   18 23 0:5 / /dev rw,relatime - devtmpfs udev rw,seclabel,size=1906740k,nr_inodes=476685,mode=755
423   26 21 253:3 / /home rw,relatime - ext4 /dev/mapper/vg-lv_home rw,seclabel,barrier=1,data=ordered
424
425 This could be used instead of current hairy code to parse the output
426 of the 'mount' command.  We could add new APIs to return kernel mount
427 options, type of filesystem at a mountpoint etc.
428
429 guestfish drive letters
430 -----------------------
431
432 There should be an option to mount all Windows drives as separate
433 paths, like C: => /c/, D: => /d/ etc.
434
435 More inspection features
436 ------------------------
437
438 - last shutdown time
439 - DHCP address
440 - last time the software was updated
441 - last user who logged in
442 - lastlog, last, who
443
444 Integrate virt-inspector with CMDBs
445 -----------------------------------
446
447 Either integrate virt-inspector with Configuration Management
448 Databases (CMDBs) or at least check that virt-inspector produces the
449 right range of data so that integration would be possible.  The
450 standards for CMDBs come from the DMTF, see eg:
451
452 http://dmtf.org/news/pr/2009/7/dmtf-releases-cmdbf-standard-federating-configuration-management-data
453
454 Efficient way to visit all files
455 --------------------------------
456
457 https://rwmj.wordpress.com/2010/12/15/tip-audit-virtual-machine-for-setuid-files/#content
458
459 A naive method would look like:
460
461   g#visit ~return_stats:true "/" (
462     fun pathname stat ->
463       ...
464   )
465
466 However this has two disadvantages:
467
468  - requires hand-written custom bindings in each language
469  - unclear about locking, thread-safety and re-entrancy of handle g
470
471 A better way would be to have some sort of explicit "download all
472 filenames and stat structures", which could then be iterated over:
473
474   let files = g#find_opts ~return_stats:true "/" in
475   List.iter (
476     fun pathname stat ->
477       ...
478   )
479
480 The problem with this is that 'files' is going to be larger than a
481 protocol buffer.
482
483 This leads to thinking about changes to the protocol / generator to
484 make this simpler.  The proposal would be to add RBigStringList,
485 RBigStructList [or RBig (Ranytype ...)].  These would work like
486 FileOut, in that they would use file streaming to stream XDR
487 structures (probably written to a file on the library side).
488 Generated code would hide most of the implementation.
489
490 We also need to think about security issues: is it possible for the
491 daemon to keep sending back data forever, and if so what happens on
492 the library side.
493
494 [Users can now use virt-ls to solve some of these problems, but it is
495 not a general solution at the API level]
496
497 Interactive disk creator
498 ------------------------
499
500 An interactive disk creator program.
501
502 Attach method for disconnected operation
503 ----------------------------------------
504
505 http://libguestfs.org/guestfs.3.html#guestfs_set_attach_method
506
507 "Librarian" has an idea that he should be able to attach to a regular
508 appliance, but disconnect from it and reconnect to it later.  This
509 would be some sort of modified attach method (see link above).
510
511 The complexity here is that we would no longer have access to
512 stdin/stdout (or we'd have to direct that somewhere else).
513
514 GObject Introspection
515 ---------------------
516
517 We periodically get asked to implement gobject-introspection (it's a
518 GNOME thing):
519
520 http://live.gnome.org/GObjectIntrospection
521
522 This would require a separate Gtk C API since the main guestfs handle
523 would have to be encapsulated in a GObject.  However the main
524 difficulty is that the annotations supported to define types are not
525 very rich.  Notably missing are support for optional arguments
526 (defined but not implemented), support for structs (unless mapped to
527 other objects).
528
529 Also note that the libguestfs API is not "object oriented".
530
531 libosinfo mappings for virt-inspector
532 -------------------------------------
533
534 Return libosinfo mappings from inspection API.
535
536 virt-sysprep ideas
537 ------------------
538
539  - touch /.unconfigured ?
540  - other Spacewalk / RHN IDs (?)
541  - Kerberos keys
542  - Puppet registration
543  - user accounts
544  - Windows sysprep
545    (see: https://github.com/clalancette/oz/blob/e74ce83283d468fd987583d6837b441608e5f8f0/oz/Windows.py )
546  - blue skies: change the background image
547  - (librarian suggests ...)
548    . install a firstboot script      virt-sysprep --script=/tmp/foo.sh
549    . run an external shell script
550    . run external guestfish script   virt-sysprep --fish=/tmp/foo.fish
551    . rm /var/cache/apt/archives/*
552  - /var/run/* and pam_faillock's data files
553  - homedirs/.ssh directory, especially /root/.ssh (Steve Grubb)
554  - if drives are encrypted, then dm-crypt key should be changed
555    and drives all re-encrypted
556  - /etc/pki
557    (Steve says ...)
558    Rpm uses nss. Nss sets up its crypto database in
559    /etc/pki. Depending on how long the machine ran before cloning, you
560    may have picked up some certificates or things. This is an area
561    that you would want to look into.
562  - secure erase of inodes etc using scrub (Steve Grubb)
563  - other directories that could require cleaning include:
564     /var/cache/gdm/*
565     /var/lib/fprint/*
566     /var/run/*
567     /var/lib/AccountService/users/*
568     /var/lib/sss/db/*
569     /var/lib/samba/*
570     /var/lib/samba/*/*
571   (thanks Marko Myllynen, James Antill)
572
573 Launch remote sessions over ssh
574 -------------------------------
575
576 We had an idea you could add a launch method that uses ssh, ie.  all
577 febootstrap and qemu commands happen the same as now, but prefixed by
578 ssh so it happens on a remote machine.
579
580 Note that proper remote support and integration with libvirt is
581 different from this, and people are working on that.  ssh would just
582 be "remote-lite".
583
584 virt-make-fs and virt-win-reg need to not be in Perl
585 ----------------------------------------------------
586
587 Probably they should be in C or OCaml.
588
589 Integrate snap-type functionality in inspection tools
590 -----------------------------------------------------
591
592 Mo Morsi's "snap" program lets you describe a guest as the list of
593 packages (eg. RPMs) installed + changes made to those RPMs + files
594 added.
595
596 http://projects.morsi.org/wiki/Snap
597
598 This results in a compact description of the guest.  He even managed
599 to do a kind of migration of guests by simply recreating the guest
600 from the description on the target machine.
601
602 It would be ideal to integrate this and/or use inspection to do this.