block.c (b202381800d81fbff9978abbdea95760dd363bb6) block.c (f11f57e405a99732ed0f3294904c2dd258d77629)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 1860 unchanged lines hidden (view full) ---

1869 cur_item->next = info;
1870 cur_item = info;
1871 }
1872 }
1873
1874 return head;
1875}
1876
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 1860 unchanged lines hidden (view full) ---

1869 cur_item->next = info;
1870 cur_item = info;
1871 }
1872 }
1873
1874 return head;
1875}
1876
1877static void bdrv_stats_iter(QObject *data, void *opaque)
1877/* Consider exposing this as a full fledged QMP command */
1878static BlockStats *qmp_query_blockstat(const BlockDriverState *bs, Error **errp)
1878{
1879{
1879 QDict *qdict;
1880 Monitor *mon = opaque;
1880 BlockStats *s;
1881
1881
1882 qdict = qobject_to_qdict(data);
1883 monitor_printf(mon, "%s:", qdict_get_str(qdict, "device"));
1882 s = g_malloc0(sizeof(*s));
1884
1883
1885 qdict = qobject_to_qdict(qdict_get(qdict, "stats"));
1886 monitor_printf(mon, " rd_bytes=%" PRId64
1887 " wr_bytes=%" PRId64
1888 " rd_operations=%" PRId64
1889 " wr_operations=%" PRId64
1890 " flush_operations=%" PRId64
1891 " wr_total_time_ns=%" PRId64
1892 " rd_total_time_ns=%" PRId64
1893 " flush_total_time_ns=%" PRId64
1894 "\n",
1895 qdict_get_int(qdict, "rd_bytes"),
1896 qdict_get_int(qdict, "wr_bytes"),
1897 qdict_get_int(qdict, "rd_operations"),
1898 qdict_get_int(qdict, "wr_operations"),
1899 qdict_get_int(qdict, "flush_operations"),
1900 qdict_get_int(qdict, "wr_total_time_ns"),
1901 qdict_get_int(qdict, "rd_total_time_ns"),
1902 qdict_get_int(qdict, "flush_total_time_ns"));
1903}
1904
1905void bdrv_stats_print(Monitor *mon, const QObject *data)
1906{
1907 qlist_iter(qobject_to_qlist(data), bdrv_stats_iter, mon);
1908}
1909
1910static QObject* bdrv_info_stats_bs(BlockDriverState *bs)
1911{
1912 QObject *res;
1913 QDict *dict;
1914
1915 res = qobject_from_jsonf("{ 'stats': {"
1916 "'rd_bytes': %" PRId64 ","
1917 "'wr_bytes': %" PRId64 ","
1918 "'rd_operations': %" PRId64 ","
1919 "'wr_operations': %" PRId64 ","
1920 "'wr_highest_offset': %" PRId64 ","
1921 "'flush_operations': %" PRId64 ","
1922 "'wr_total_time_ns': %" PRId64 ","
1923 "'rd_total_time_ns': %" PRId64 ","
1924 "'flush_total_time_ns': %" PRId64
1925 "} }",
1926 bs->nr_bytes[BDRV_ACCT_READ],
1927 bs->nr_bytes[BDRV_ACCT_WRITE],
1928 bs->nr_ops[BDRV_ACCT_READ],
1929 bs->nr_ops[BDRV_ACCT_WRITE],
1930 bs->wr_highest_sector *
1931 (uint64_t)BDRV_SECTOR_SIZE,
1932 bs->nr_ops[BDRV_ACCT_FLUSH],
1933 bs->total_time_ns[BDRV_ACCT_WRITE],
1934 bs->total_time_ns[BDRV_ACCT_READ],
1935 bs->total_time_ns[BDRV_ACCT_FLUSH]);
1936 dict = qobject_to_qdict(res);
1937
1938 if (*bs->device_name) {
1939 qdict_put(dict, "device", qstring_from_str(bs->device_name));
1884 if (bs->device_name[0]) {
1885 s->has_device = true;
1886 s->device = g_strdup(bs->device_name);
1940 }
1941
1887 }
1888
1889 s->stats = g_malloc0(sizeof(*s->stats));
1890 s->stats->rd_bytes = bs->nr_bytes[BDRV_ACCT_READ];
1891 s->stats->wr_bytes = bs->nr_bytes[BDRV_ACCT_WRITE];
1892 s->stats->rd_operations = bs->nr_ops[BDRV_ACCT_READ];
1893 s->stats->wr_operations = bs->nr_ops[BDRV_ACCT_WRITE];
1894 s->stats->wr_highest_offset = bs->wr_highest_sector * BDRV_SECTOR_SIZE;
1895 s->stats->flush_operations = bs->nr_ops[BDRV_ACCT_FLUSH];
1896 s->stats->wr_total_time_ns = bs->total_time_ns[BDRV_ACCT_WRITE];
1897 s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ];
1898 s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH];
1899
1942 if (bs->file) {
1900 if (bs->file) {
1943 QObject *parent = bdrv_info_stats_bs(bs->file);
1944 qdict_put_obj(dict, "parent", parent);
1901 s->has_parent = true;
1902 s->parent = qmp_query_blockstat(bs->file, NULL);
1945 }
1946
1903 }
1904
1947 return res;
1905 return s;
1948}
1949
1906}
1907
1950void bdrv_info_stats(Monitor *mon, QObject **ret_data)
1908BlockStatsList *qmp_query_blockstats(Error **errp)
1951{
1909{
1952 QObject *obj;
1953 QList *devices;
1910 BlockStatsList *head = NULL, *cur_item = NULL;
1954 BlockDriverState *bs;
1955
1911 BlockDriverState *bs;
1912
1956 devices = qlist_new();
1957
1958 QTAILQ_FOREACH(bs, &bdrv_states, list) {
1913 QTAILQ_FOREACH(bs, &bdrv_states, list) {
1959 obj = bdrv_info_stats_bs(bs);
1960 qlist_append_obj(devices, obj);
1914 BlockStatsList *info = g_malloc0(sizeof(*info));
1915 info->value = qmp_query_blockstat(bs, NULL);
1916
1917 /* XXX: waiting for the qapi to support GSList */
1918 if (!cur_item) {
1919 head = cur_item = info;
1920 } else {
1921 cur_item->next = info;
1922 cur_item = info;
1923 }
1961 }
1962
1924 }
1925
1963 *ret_data = QOBJECT(devices);
1926 return head;
1964}
1965
1966const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
1967{
1968 if (bs->backing_hd && bs->backing_hd->encrypted)
1969 return bs->backing_file;
1970 else if (bs->encrypted)
1971 return bs->filename;

--- 1320 unchanged lines hidden ---
1927}
1928
1929const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
1930{
1931 if (bs->backing_hd && bs->backing_hd->encrypted)
1932 return bs->backing_file;
1933 else if (bs->encrypted)
1934 return bs->filename;

--- 1320 unchanged lines hidden ---